Skip to content
Prev 206830 / 398503 Next

Remove term from formula for predict.lm

Thanks Gabor and Henrique!

Sorry for the imprecise question. I want predict() to use the coefficients
estimated by the original regression but to exclude terms from the
prediction formula. If I originally estimated y ~ x1 + x2 and got
coefficients b0, b1, b2, I would like to remove x2 and predict y = b0 +
b1*x1 using the the originally estimated coefficients b0 and b1.

@Gabor: I tried your suggestion but it seems although predict now accepts a
list with fewer variables, the new function is not used so that the
coefficient does not change.
1 
4.684909 
Warning message:
In predict.lm(eval(mod$call), list(x1 = 1, x2 = 1, x3 = 1, x4 = 1)) :
  prediction from a rank-deficient fit may be misleading
1 
4.684909
Many thanks,
  Werner