Skip to content

difference in using with() and the "data" argument in glm (PR#9338)

2 messages · Duncan Murdoch, Gabor Grothendieck

#
I've redirected this reply from r-help to the bugs list.
On 11/3/2006 8:25 AM, vito muggeo wrote:
I think this is a bug in terms.formula.  Near the end it has

     environment(terms) <- environment(x)

where x is the formula.  Since "y" isn't defined in that environment, it
fails.  It would work for you with

     environment(terms) <- data

but see below.

A workaround that should work for you is to put

environment(Formula) <- KK

before the call to glm.

I'm not going to make the patch I suggest above, because I don't think 
it's consistent with the expected behaviour of glm() in the case where 
some of the terms in the formula are supposed to come from 
environment(x), and some from "data".

I don't know how to handle that case properly:  I think it requires a 
different search strategy than R employs (but I might be wrong).  This 
isn't a problem with the workaround I suggested to you, because there 
the parent of KK is environment(x), but that wouldn't be true in general.

Duncan Murdoch
#
One thing I noticed is that ?glm does not really specify what happens
if you do not give a value for data.  Is data then just skipped so that search
takes place in enivonrment(formula) only or is it supposed to default to
something?   Some clarification in ?glm would be helpful.
On 11/3/06, murdoch at stats.uwo.ca <murdoch at stats.uwo.ca> wrote: