Re: [R] update.default evaluating in wrong environment?

From: Martin C. Martin <martin_at_martincmartin.com>
Date: Tue 10 Oct 2006 - 19:00:11 GMT

Great; thanks for the detailed explanation!

Thomas Lumley wrote:
> On Tue, 10 Oct 2006, Martin C. Martin wrote:

>> Thanks, or even just:
>>
>> e <- environment(formula(f.lm))
>>
>> But this was more of a bug report.  Is update.default wrong?  Should it
>> be changed?  I don't see how evaluating in update's parent environment
>> would ever be better default behavior than the formula's environment.
>>

>
> This is deliberate (although that doesn't necessarily imply that it is
> optimal). There already is a bug report (PR#1861) on this issue, so
> another one certainly isn't appropriate.
>
> The comments for this bug report give an example taken from the scripts
> for MASS chapter 6, doing a bootstrap of a linear model
> ph.fun <- function(data, i) {
> d <- data
> d$calls <- d$fitted + d$res[i]
> coef(update(fit, data=d))
> }
>
> This is not uncommon for resampling and other perturbations of a model
> and requires looking in the calling frame of update().
>
> For other uses such as yours the right place would be the frame where
> the model was created. Neither the environment of the formula nor the
> calling frame of update() is guaranteed to be the right place and it is
> easy to come up with examples where each works and the other doesn't.
>
> There really isn't a trivial solution to this.
>
> -thomas


R-help@stat.math.ethz.ch 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. Received on Wed Oct 11 05:14:00 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 10 Oct 2006 - 20:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.