Gregor Gorjanc
2006-Jul-19 09:24 UTC
[Rd] Bug?: summary() fails after use of na.action="na.exclude" in lm()
Hello!
I have encountered a weird problem and I am wondering if this is a bug.
Here is the example:
n <- 50
x <- runif(n=n)
y1 <- 2 * x + rnorm(n=n)
y2 <- 5 * x + rnorm(n=n)
y2[sample(1:n, size=5)] <- NA
y <- cbind(y1, y2)
fit <- lm(y1 ~ 1, na.action="na.exclude")
summary(fit)
## Goes ok here
fit <- lm(y2 ~ 1, na.action="na.exclude")
summary(fit)
## But fails if we use matrix of response variables
fit <- lm(y ~ 1, na.action="na.exclude")
summary(fit)
## Response y1 :
##
## Call:
## lm(formula = y1 ~ 1, na.action = "na.exclude")
##
## Residuals:
## Error in quantile.default(resid) : missing values and NaN's not
allowed if 'na.rm' is FALSE
Am I doing something wrong here?
----------------------------------------------------------------------
Btw. man page of lm says (in the begining of the details):
"A typical model has the form 'response ~ terms' where
'response' is the
(numeric) response vector ..."
^^^^^^
Should not this part say that repsponse can also be a matrix?
Thanks
--
Lep pozdrav / With regards,
Gregor Gorjanc
----------------------------------------------------------------------
University of Ljubljana PhD student
Biotechnical Faculty
Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3 mail: gregor.gorjanc <at> bfro.uni-lj.si
SI-1230 Domzale tel: +386 (0)1 72 17 861
Slovenia, Europe fax: +386 (0)1 72 17 888
----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
you have no certainty until you try." Sophocles ~ 450 B.C.
Thomas Lumley
2006-Jul-19 15:30 UTC
[Rd] Bug?: summary() fails after use of na.action="na.exclude" in lm()
On Wed, 19 Jul 2006, Gregor Gorjanc wrote:> I have encountered a weird problem and I am wondering if this is a bug. > Here is the example: > > n <- 50 > x <- runif(n=n) > y1 <- 2 * x + rnorm(n=n) > y2 <- 5 * x + rnorm(n=n) > y2[sample(1:n, size=5)] <- NA > > y <- cbind(y1, y2) > > fit <- lm(y1 ~ 1, na.action="na.exclude") > summary(fit) > > ## Goes ok here > fit <- lm(y2 ~ 1, na.action="na.exclude") > summary(fit) > > ## But fails if we use matrix of response variables > fit <- lm(y ~ 1, na.action="na.exclude") > summary(fit) > > ## Response y1 : > ## > ## Call: > ## lm(formula = y1 ~ 1, na.action = "na.exclude") > ## > ## Residuals: > ## Error in quantile.default(resid) : missing values and NaN's not > allowed if 'na.rm' is FALSE >Yes, I think it's a bug. summary.mlm() produces an object that is a list of objects of class "summary.lm", but these objects get their $resid component from the residuals() function and so NAs in their $resid component where a "summary.lm" produced by summary.lm() would not. -thomas
Possibly Parallel Threads
- Summary() fails after use of na.action="na.exclude" in lm() (PR#9191)
- Re: [Rd] corrupt data frame: columns will be truncated or padded with NAs in: format.data.frame(x, digits = digits)
- corrupt data frame: columns will be truncated or padded with NAs in: format.data.frame(x, digits = digits)
- corrupt data frame: columns will be truncated or padded with NAs in: format.data.frame(x, digits = digits)
- corrupt data frame: columns will be truncated or padded with NAs in: format.data.frame(x, digits = digits)