[Rd] lm() takes weights from formula environment

John Mount jmount @end|ng |rom w|n-vector@com
Mon Aug 10 19:42:43 CEST 2020


I wish I had started with "I am disappointed that lm() doesn't continue its search for weights into the calling environment" or "the fact that lm() looks only in the formula environment and data frame for weights doesn't seem consistent with how other values are treated."

But I did not. So I do apologize for both that and for negative tone on my part.


Simplified example:

d <- data.frame(x = 1:3, y = c(1, 2, 1))
w <- c(1, 10, 1)
f <- as.formula(y ~ x)
lm(f, data = d, weights = w)  # works

# fails
environment(f) <- baseenv()
lm(f, data = d, weights = w)
# Error in eval(extras, data, env) : object 'w' not found


> On Aug 9, 2020, at 11:56 AM, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
> 
> This is fairly clearly documented in ?lm:
> 



More information about the R-devel mailing list