[R] lm predictions for rows with missing y values
Bert Gunter
gunter.berton at gene.com
Tue Apr 15 23:12:33 CEST 2014
Yes. I believe what you're looking for is:
See ?predict.lm and what it has to say about the na.action=na.exclude
argument to lm.
Cheers,
Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch
On Tue, Apr 15, 2014 at 1:22 PM, Mast, Brent D <Brent.D.Mast at hud.gov> wrote:
> Hi.
>
> I'm trying to produce lm fitted values and standard errors for cases with missing y values. I know how to compute these myself with matrix algebra, but I'm wondering if there is an appropriate na.action in the lm function to do this.
> Here is some simple code where I use na.action=NULL with a dataset with 2 missing y values, but the model won't estimate. It also won't run with na.action=TRUE or FALSE. Any suggestions would be appreciated.
>
> Thanks much,
> Brent Mast
>
> x <- rnorm(15)
> y <- x + rnorm(15)
> lm <- lm(y ~ x)
> fit <- fitted(lm)
> fit
> # 2 new x cases
> newx <- c(x,-3, 3)
> # set y to NA for new cases
> newy <- matrix(,17,1)
> newy[1:15,1] <- y
> newdata <- data.frame(newy,newx)
> newdata
> lmnew <- lm(newy ~ newx,newdata,na.action=NULL)
> fitnew <- fitted(lmnew)
> fitnew
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list