[R] update.lm question

David Winsemius dwinsemius at comcast.net
Sun Nov 15 16:07:46 CET 2009


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
On Nov 15, 2009, at 9:23 AM, Karsten Weinert wrote:

> Hello,
> at the Rgui command line I can easily remove a term from a fitted lm
> object, like
>
> fit <- lm(y~x1+x2+x3, data=myData)
> update(fit, .~.-x1)
>
> However, I would like to do this in a function with term given as  
> string, like
>
> removeTerm <- function(linModel, termName) { ??? }
> removeTerm(fit, "x1")
>
> but I can not fill the ???. I already tried
>
> removeTerm <- function(linModel, termName) { update(linModel, .~. -  
> termName },
> removeTerm <- function(linModel, termName) { update(linModel, .~. -
> as.name(termName) },
> removeTerm <- function(linModel, termName) { update(linModel, .~. -
> eval(termName) },
> removeTerm <- function(linModel, termName) { update(linModel, .~. -
> eval.parent(termName) },
> removeTerm <- function(linModel, termName) { update(linModel, .~. -
> get(termName) },
>
> but these attempts produce error messages.
>
> Can you advise me here?
>
> Kind regards,
> Karsten
-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list