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

d.firth@warwick.ac.uk d.firth at warwick.ac.uk
Thu Aug 4 17:50:28 CEST 2005


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



More information about the R-devel mailing list