[R] lm predictions for rows with missing y values
Rui Barradas
ruipbarradas at sapo.pt
Tue Apr 15 23:22:25 CEST 2014
Hello,
I believe you want na.action = na.exclude.
lmnew <- lm(newy ~ newx,newdata,na.action=na.exclude)
na.action can not be set to TRUE or FALSE. From the help page ?lm
na.action
a function which indicates what should happen when the data contain NAs.
The default is set by the na.action setting of options, and is na.fail
if that is unset. The ‘factory-fresh’ default is na.omit. Another
possible value is NULL, no action. Value na.exclude can be useful.
Hope this helps,
Rui Barradas
Em 15-04-2014 21:22, Mast, Brent D escreveu:
> 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