R-alpha: offset in glm not working

Thomas Lumley Thomas Lumley <thomas@biostat.washington.edu>
Fri, 17 Oct 1997 09:19:17 -0700 (PDT)


On Fri, 17 Oct 1997, Comblain muriel wrote:

> >
> >	With the new version of R (septembre), the function glm seems to ignore
> the offset. The ouput is exactly the same with or without the offset
> specification. I tried the same program in the version of april and it
> worked corectly. 
> >

Yes, this is a bug.  The modelling code was changing quite rapidly at
about the time rsept was built, and it ended up without support for
offsets.

There are two problems. The version of model.frame/model.matrix in
rsept doesn't allow 
	glm(y~x+offset(z))
and the model.offset() function is broken so that
	glm(y~x,offset=z) 
doesn't work. The second problem is easy to fix 

If you define
model.offset  <- function (x) 
{
        offsets <- attr(attr(x, "terms"), "offset")
        if (length(offsets) > 0) {
                ans <- 0
                for (i in offsets) ans <- ans + x[[i]]
        }
        else NULL
}

by adding it to your profile, or by editing the base library
then  glm(y~x,offset=z) will work. 


Thomas Lumley
------------------------------------------------------+------
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :
------------------------------------------------------------


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-