Re: R-alpha: problem adding a variable to an object

Thomas Lumley (
Thu, 12 Dec 1996 09:05:57 -0800 (PST)

Date: Thu, 12 Dec 1996 09:05:57 -0800 (PST)
From: Thomas Lumley <>
To: Murray Keir <>
Subject: Re: R-alpha: problem adding a variable to an object
In-Reply-To: <>

On Thu, 12 Dec 1996, Murray Keir wrote:
> I have tracked down the source of the error to the statement
>         mf <- eval(mf, sys.frame(sys.parent()))
> in the glm function.  However, I do not know what this is doing.
> Any advice on what this command does or, even better, why the error 
> itself is occuring would be greatly appreciated.

This command is a trick I copied from the survival4 library when I
modified model.frame().  The point of it is to allow arguments like the
weight and offset to be evaluated in the same data frame as the formula
when the data= argument is used. This is convenient and also compatible 
with S-PLUS.

When you call glm() a copy of the call is obtained and stored in the 
variable mf. It looks like, eg

glm(y~x,data=mydata, family=poisson, subset=1:42, offset=logt, x=T, 

and is stored as a list.
The program then removes all the components of the list that model.frame 
would not understand with eg
and the same for all the other options that glm() takes.  The first 
component of the list is then replaced with"model.frame") so mf 
now contains

The important point about all this manoeuvring is that nothing has been 
evaluated yet.  In particular, logt need not be defined in the global or 
local environment: it can be a column of the data.frame mydata. 

Now this call is evaluated in the parent environment, since we know the 
data= argument has the correct value there (if we evaluated it in the 
current environment it might get overridden by a local variable).

To cure your problem, add mf$dispersion<-NULL to all the other 
mf$thing<-NULL statements in glm.

thomas lumley
UW biostatistics

r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: