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

Bert Gunter bgunter.4567 at gmail.com
Wed May 17 16:48:12 CEST 2017

You should consult a linear models text, but, assuming I have
correctly understood your post, the procedure is this (the translation
to R code is trivial, and I leave it to you):

Let y be the response variable, P1 be the first set of predictors and
z be your new predictor to be added.

1. regress y on P1; let r1 be the residuals from this model, call it M1.

2. regress z on P1 and let r2 be the residuals from this model

3. regress r1 on r2, Call this model M2

Than the predictions obtained from the model y ~ P1 + z are the same
(within numerical error) as those obtained by adding the predictions
from M1 to the predictions of M2. As Gerrit mentioned, the
coefficients from the full fit model will be different than those
obtained from the seprate model fitting procedure.



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Wed, May 17, 2017 at 12:12 AM, Urs Kleinholdermann
<urs at kleinholdermann.de> wrote:
> 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
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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