Skip to content
Prev 206833 / 398503 Next

Remove term from formula for predict.lm

Werner,

You could set 0 to that regressors you don't want to consider for
prediction.

da <- expand.grid(A=1:20, B=rnorm(20, 4, 0.2), C=10^seq(1,2,l=20))
da$y <- rnorm(da$A, 0, 0.3)

m0 <- lm(y~A+B+C, data=da)

new <- da
new$C <- 0

predict(m0)[1:5]
predict(m0, newdata=new)[1:5]

At your disposal.
Walmes.

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