Skip to content
Prev 200314 / 398503 Next

update.lm question

On Nov 15, 2009, at 11:15 AM, Karsten Weinert wrote:

            
But did you look at the as.formula page?
And here is what seemed like the obvious extension of your example but  
using as.formula:

myData <- data.frame(x1=rnorm(10), x2=rnorm(10), x3=rnorm(10),  
y=rnorm(10))
fit <- lm(y~x1+x2+x3, data=myData)
remvterm <- function(ft, termname) update(ft, as.formula(paste(".~.-",  
termname, sep="")))
remvterm(fit, "x3")

Call:
lm(formula = y ~ x1 + x2, data = myData)

Coefficients:
(Intercept)           x1           x2
     -0.2598      -0.0290      -0.2645