Re: [R] lm without error

From: ivo welch <>
Date: Fri, 11 Jun 2010 11:28:04 -0400

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.

eric--let me disagree with you, too. I did know about "?try" and it is useful when the dependent variable is just one vector---except if you have thousands of dependent variables (to run thousands of regressions with one lm() statement). if an error is thrown, then you then have to determine which of the columns actually was responsible for the error, and then you have to restart it. if you want a minimal example to explain this dilemma better:

  y= matrix(rnorm(1000), nrow=10, ncol=100)   y[,28]= rep(NA, 10)
  lm( y ~ x )

       ## now what do you do? hunt for which column was responsible?

gabor---this seems to be exactly what I wanted to get---coefficients without triggering an error. thanks (yet again). in my example,

   coefs= qr.coef( qr(x), y )

works great.



On Fri, Jun 11, 2010 at 10:46 AM, Erik Iverson <> wrote:
> 1) please use reproducible, minimal examples when discussing behavior of R.
> 2) perhaps ?try could help.
> ivo welch wrote:
>> this is not an important question, but I wonder why lm returns an
>> error, and whether this can be shut off.  it would seem to me that
>> returning NA's would make more sense in some cases---after all, the
>> problem is clearly that coefficients cannot be computed.
>> I know that I can trap the error---although I have always
>> found this to be quite inconvenient---and this is easy if I have only
>> one regression in my lm() statement.
>> but, let's presume I have a matrix with a few thousand dependent y
>> variables (and the same independent X variables).  Let's presume one
>> of the y variables contains only NA's.  I believe I now cannot use
>> lm(y ~ X), because one of the regressions will throw the
>> exception.  (all the other y vectors should have worked.)
>> or is there a way to get lm() to work in such situations?
>> /iaw
>> ----
>> Ivo Welch (,
>> ______________________________________________
>> mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 11 Jun 2010 - 15:31:00 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:30:30 GMT.

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

list of date sections of archive