[R] update.lm question
Karsten Weinert
k.weinert at gmx.net
Sun Nov 15 17:15:28 CET 2009
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>:
>
> You need to review:
>
> ?update
> ?update.formula
> ?as.formula
>
> The way should be clear at that point. If not, then include a reproducible
> data example to work with.
>
> --
> David
More information about the R-help
mailing list