From d.firth at warwick.ac.uk  Thu Aug  4 17:50:28 2005
From: d.firth at warwick.ac.uk (d.firth@warwick.ac.uk)
Date: Thu,  4 Aug 2005 17:50:28 +0200 (CEST)
Subject: [Rd] add1.lm and add1.glm not handling weights and offsets properly
	(PR#8049)
Message-ID: <20050804155028.4D291A75C@slim.kubism.ku.dk>

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



[Rd] add1.lm and add1.glm not handling weights and offsets properly (PR#8049)
d.firth@warwick.ac.uk