Re: [R] lm without error

From: Joris Meys <>
Date: Sat, 12 Jun 2010 02:22:57 +0200

On Fri, Jun 11, 2010 at 5:28 PM, ivo welch <> wrote:
> thanks, everybody.
> joris---let me disagree with you, please.  there are so many
> possibilities of how could fail that by the time I am done with
> pre-checking, I may as well write my own lm() routine.
If we all would agree, life would be boring, no? ;-) I see your point, but the thing is that if the function returns only NA coefficients (and it can't do anything else than that, as a fit is mathematically not possible), you have literally no information about what went wrong. If I fit can't be done, I'd like to know why it happened, and not just get the answer "Not Available". That's an error message too.

Checking your data before doing an analysis is what we call "Good Statistical Practice". Using a model on data you didn't check before is like starting to drive to another country without checking which direction you have to go. Pretty unlikely you're going to arrive at the right spot...

This said, you gave us what we need.
>  y= matrix(rnorm(1000), nrow=10, ncol=100)
>  y[,28]= rep(NA, 10)
>  x=rnorm(10)
>  lm( y ~ x )
>       ## now what do you do?  hunt for which column was responsible?
I'd do :
y= matrix(rnorm(1000), nrow=10, ncol=100)  y[,28]= rep(NA, 10)

getOut <- which(colSums([1])

  lm( y[-getOut] ~ x )


Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Disclaimer :

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 12 Jun 2010 - 00:26:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Jun 2010 - 00:40:29 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive