Skip to content
Prev 200307 / 398503 Next

update.lm question

Hello David,

of course I read those help pages and searched the r-help archive.

I agree that the way should be clear, but I am stuck and looking for
help. Here is reproducible code

removeTerm1 <- function(linModel, termName) { update(linModel, .~. - termName) }
removeTerm2 <- function(linModel, termName) { update(linModel, .~. -
as.name(termName)) }
removeTerm3 <- function(linModel, termName) { update(linModel, .~. -
eval(termName)) }
removeTerm4 <- function(linModel, termName) { update(linModel, .~. -
eval.parent(termName)) }
removeTerm5 <- function(linModel, termName) { update(linModel, .~. -
get(termName)) }

myData <- data.frame(x1=rnorm(10), x2=rnorm(10), x3=rnorm(10), y=rnorm(10))
fit <- lm(y~x1+x2+x3, data=myData)

# all this does not work, as I am expecting the function to return a
lm object with formula y~x2+x3
removeTerm1(fit, "x1")
removeTerm2(fit, "x1")
removeTerm3(fit, "x1")
removeTerm4(fit, "x1")
removeTerm5(fit, "x1")


Any help appreciated,
kind regards,
Karsten Weinert



2009/11/15 David Winsemius <dwinsemius at comcast.net>: