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 lm.fit() 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 lm.fit 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 (ivo.welch at brown.edu, ivo.welch at gmail.com)
Obvious solution : check your data before you throw it in the lm. lm() shouldn't work in that situation, and if it would, I'd no longer use R. Cheers Joris On Fri, Jun 11, 2010 at 2:49 PM, ivo welch <ivowel at gmail.com> 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 lm.fit() 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 lm.fit > 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 (ivo.welch at brown.edu, ivo.welch at gmail.com) > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 Joris.Meys at Ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
This will give the coefficients of each regression for which there are no missing values in the dependent variable and NAs for the rest:> # test data > set.seed(123) > y <- cbind(y1 = 1:4, y2 = c(NA, 2:4)) > x <- 1:4 + rnorm(4) > > qr.coef(qr(cbind(1, x)), y)y1 y2 0.8607244 NA x 0.6049789 NA On Fri, Jun 11, 2010 at 8:49 AM, ivo welch <ivowel at gmail.com> 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 lm.fit() 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 lm.fit > 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 (ivo.welch at brown.edu, ivo.welch at gmail.com) > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
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 lm.fit() 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 lm.fit > 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 (ivo.welch at brown.edu, ivo.welch at gmail.com) > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.