Skip to content
Prev 217183 / 398498 Next

predict.lm with NAs

You can use predict() by specifying a complete data.frame() for prediction to
the argument newdata=. Look:

da <- expand.grid(x1=LETTERS[1:4], x2=1:9)
da$y <- rnorm(da$x1)
da$y[sample(length(da$y), 5)] <- NA

m0 <- lm(y~x1+x2, data=da)
predict(m0) # NA not predicted
predict(m0, newdata=da) # NA predicted

Sincerely.
Walmes.

-----
..ooo0
...................................................................................................
..(....)... 0ooo...                              Walmes Zeviani
...\..(.....(.....)...     Master in Statistics and Agricultural
Experimentation
....\_)..... )../....       walmeszeviani at hotmail.com, Lavras - MG, Brasil
............
(_/............................................................................................