[Rd] (PR#8049) add1.lm and add1.glm not handling weights and

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri Aug 5 09:06:18 CEST 2005


David,

Thanks.

The reason add1.lm (and drop1.lm) do not support offsets is that lm did 
not when they were written, and the person who added offsets to lm did not 
change them. (I do wish they had not added an offset arg and just used the 
formula as in S's glm.)  That is easy to add.

For the other point, some care is needed if 'x' is supplied and the upper 
scope reduces the number of points.  We can try harder, but your usage 
does give a warning and perhaps that needs to be an error in this case.

Brian


On Thu, 4 Aug 2005 d.firth at warwick.ac.uk wrote:

> I am using R 2.1.1 under Mac OS 10.3.9.
>
> Two related problems (see notes 1. and 2. below) are illustrated by
> results of the following:
>
> y <- rnorm(10)
> x <- z <- 1:10
> is.na(x[9]) <- TRUE
>
> lm0 <- lm(y ~ 1)
> lm1 <- lm(y ~ 1, weights = rep(1, 10))
>
> add1(lm0, scope = ~ x)  ## works ok
> add1(lm1, scope = ~ x)  ## error
>
> lm2 <- lm(y ~ 1, offset = 1:10)
>
> add1(lm0, scope = ~ z)  ## works ok
> add1(lm2, scope = ~ z)  ## gives incorrect results (ignores the offset)
>
> glm0 <- glm(y ~ 1)
> glm1 <- glm(y ~ 1, weights = rep(1, 10))
> glm2 <- glm(y ~ 1, offset = rep(0, 10))
>
> add1(glm0, scope = ~ x)  ## error
> add1(glm1, scope = ~ x)  ## error
> add1(glm2, scope = ~ x)  ## error
>
>
>
> As I see it, the two problems are:
>
> 1.  add1.lm ignores any offset present in its "object" argument.
>
> 2.  add1.lm and add1.glm both take weights directly from their "object"
> argument, and add1.glm also does the same for any offset that is
> present.  But this does not work when the upper scope includes missing
> values and na.omit is used: the weights (and offset) then have the
> wrong length.  They should presumably be extracted instead from the
> reduced model frame.
>
>
> If I can be of help in fixing these things, please let me know.  But I
> don't want to make things worse, or to duplicate anyone else's work.  I
> don't see this fixed in the bug-fix list at
>   https://svn.r-project.org/R/trunk/NEWS
> but I haven't checked whether the same problems are in the current
> r-devel.
>
> David
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list