Rev 69217 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
## tests of offsets, and prediction from them.load("anorexia.rda") # copied from package MASS## via formulafit1 <- lm(Postwt ~ Prewt + Treat + offset(Prewt), data = anorexia)summary(fit1)pred <- fitted(fit1)stopifnot(all.equal(predict(fit1, anorexia), pred))## via argumentfit2 <- lm(Postwt ~ Prewt + Treat, data = anorexia, offset=Prewt)summary(fit2)stopifnot(all.equal(predict(fit2, anorexia), pred))## now spili into two partsanorexia$o1 <- 0.9*anorexia$Prewtanorexia$o2 <- 0.1*anorexia$Prewtfit3 <- lm(Postwt ~ Prewt + Treat + offset(o1) + offset(o2), data = anorexia)summary(fit3)stopifnot(all.equal(predict(fit3, anorexia), pred))fit4 <- lm(Postwt ~ Prewt + Treat + offset(o1), data = anorexia, offset = o2)summary(fit4)stopifnot(all.equal(predict(fit4, anorexia), pred))## using more than one offset failed in R 2.8.1