Re: [Rd] lm() takes weights from formula environment

2020-08-10 Thread John Mount
Forgot the url: https://win-vector.com/2014/05/30/trimming-the-fat-from-glm-models-in-r/ On Aug 10, 2020, at 11:50 AM, John Mount mailto:jmo...@win-vector.com>> wrote: Thank you for your suggestion. I do know how to work around the issue. I usually build a fresh environment as a child of base

Re: [Rd] lm() takes weights from formula environment

2020-08-10 Thread John Mount
Thank you for your suggestion. I do know how to work around the issue. I usually build a fresh environment as a child of base-environment and then insurt the weights there. I was just trying to provide an example of the issue. emptyenv() can not be used, as it is needed for the eval (errors out

Re: [Rd] lm() takes weights from formula environment

2020-08-10 Thread Duncan Murdoch
On 10/08/2020 1:42 p.m., John Mount wrote: 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

Re: [Rd] lm() takes weights from formula environment

2020-08-10 Thread William Dunlap via R-devel
I assume you are concerned about this because the formula is defined in one environment and the model fitting with weights occurs in a separate function. If that is the case then the model fitting function can create a new environment, a child of the formula's environment, add the weights variable

Re: [Rd] lm() takes weights from formula environment

2020-08-10 Thread John Mount
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

Re: [Rd] lm() takes weights from formula environment

2020-08-09 Thread Duncan Murdoch
On 09/08/2020 3:07 p.m., Duncan Murdoch wrote: On 09/08/2020 3:01 p.m., John Mount wrote: Doesn't this preclude "y ~ ." style notations? Yes, but you can use "y ~ . - w". And as was pointed out to me offline, often one doesn't have a simple vector w giving the weights, instead one computes

Re: [Rd] lm() takes weights from formula environment

2020-08-09 Thread Duncan Murdoch
On 09/08/2020 3:01 p.m., John Mount wrote: Doesn't this preclude "y ~ ." style notations? Yes, but you can use "y ~ . - w". Duncan Murdoch On Aug 9, 2020, at 11:56 AM, Duncan Murdoch wrote: This is fairly clearly documented in ?lm: "All of weights, subset and offset are evaluated in th

Re: [Rd] lm() takes weights from formula environment

2020-08-09 Thread John Mount
Doesn't this preclude "y ~ ." style notations? > On Aug 9, 2020, at 11:56 AM, Duncan Murdoch wrote: > > This is fairly clearly documented in ?lm: > > "All of weights, subset and offset are evaluated in the same way as variables > in formula, that is first in data and then in the environment of

Re: [Rd] lm() takes weights from formula environment

2020-08-09 Thread Duncan Murdoch
This is fairly clearly documented in ?lm: "All of weights, subset and offset are evaluated in the same way as variables in formula, that is first in data and then in the environment of formula." There are lots of possible places to look for weights, but this seems to me like a pretty sensibl

[Rd] lm() takes weights from formula environment

2020-08-09 Thread John Mount
I know this programmers can reason this out from R's late parameter evaluation rules PLUS the explicit match.call()/eval() lm() does to work with the passed in formula and data frame. But, from a statistical user point of view this seems to be counter-productive. At best it works as if the user