Message-ID: <971536df1001190824u37ecd4e3x73acbcbd2f3d5f29@mail.gmail.com>
Date: 2010-01-19T16:24:55Z
From: Gabor Grothendieck
Subject: Remove term from formula for predict.lm
In-Reply-To: <128816.22092.qm@web23006.mail.ird.yahoo.com>
This recomputes the lm but if that is ok then:
mod <- lm(y1 ~ x1 + x2 + x3 + x4, anscombe)
mod$call$formula <- update(as.formula(mod$call$formula), ~ . - x1 - x2)
predict(eval(mod$call), list(x3 = 1, x4 = 1))
On Tue, Jan 19, 2010 at 11:10 AM, Werner W. <pensterfuzzer at yahoo.de> wrote:
> Hi,
>
> probably just a quick question: can I somehow change the formula used with predict? E.g., the regression was run on "y ~ u + v + w" but for the prediction the term v should be removed from the formula contained in the regression object and only "y ~ u + w" be used.
>
> I could use model.matrix etc. to do the predictions but it would be very helpful to know a simpler way.
>
> Thanks so much,
> ?Werner
>
>
> __________________________
> ?verf?gt ?ber einen herausragenden Schutz gegen Massenmails.
> http://mail.yahoo.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>