Sverre:

As your reproducible example shows, the problem is that the string
"y1:y2" is not an acceptable term of the formula. One way round this
is simply convert the non-string part of the formula to a string, pase
it with your term, and then reconvert it to a formula:

update(my.lm,formula(paste(".~.-", my.object)))

There may be a more elegant way via substitute(), but I think this works.

Cheers,
Bert

On Mon, Aug 15, 2011 at 1:44 PM, Sverre Stausland
<john...@fas.harvard.edu> wrote:
> Hi all,
>
> I'm extracting the name of the term in a regression model that
> dropterm specifies as the least significant one, and I'm assigning
> this name to an object. However, when I use update(), it ignores this
> object. Is there a way I can make it not ignore it? A reproducible
> example is below:
>
>> lm(x1~1+y1*y2+y3+y4,data=anscombe)->my.lm
>> rownames(dropterm(my.lm,test="F",sort=TRUE))[1]->my.object
>> my.object
> [1] "y1:y2"
>> update(my.lm,.~.-my.object)
>
> Call:
> lm(formula = x1 ~ y1 + y2 + y3 + y4 + y1:y2, data = anscombe)
>
> Coefficients:
> (Intercept)           y1           y2           y3           y4
>   -8.95635      1.11420      0.61921      0.76762      0.21237
>      y1:y2
>   -0.04056
>
>> update(my.lm,.~.-y1:y2)
>
> Call:
> lm(formula = x1 ~ y1 + y2 + y3 + y4, data = anscombe)
>
> Coefficients:
> (Intercept)           y1           y2           y3           y4
>    -6.6409       0.7618       0.3836       0.7759       0.1640
>
> ______________________________________________
> R-help@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.
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

______________________________________________
R-help@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.

Reply via email to