[R] adding predictor to linear model without changing existing coefficients

Urs Kleinholdermann urs at kleinholdermann.de
Wed May 17 09:12:17 CEST 2017


Dear list members,

I want to add a predictor to a linear model without changing the
coefficients of the existing model. How is that done with R?

So if I have a response y and predictors x1, x2, x3 I want to make a model lm1 like

lm1 = lm(y~x1+x2)

After this model is computed I want to add x3 like

lm2 = lm(y~x1+x2+x3)

However, unlike it is done by the notation above or by update or add1
(as far as I understand) I don't want a new model with all predictors
estimated anew but I want a model lm2 where the coefficients for x1 and
x2 stay exactly as in lm1 and the coefficent for x3 is estimated
additionally. The reasons for this are theoretical. I guess what I want
is similar to calculating a new regression on the residuals of lm1.

lm2 = lm(residuals(lm1)~x3)

however, I would prefer to to that in the common framework of the lm
command in order to calculate statistics, perform anova on the models
and so on.

thanks for your help!
Urs



More information about the R-help mailing list