The R Project SVN R

Rev

Rev 69217 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 69217 Rev 81650
Line 11... Line 11...
11
## via argument
11
## via argument
12
fit2 <- lm(Postwt ~ Prewt + Treat, data = anorexia, offset=Prewt)
12
fit2 <- lm(Postwt ~ Prewt + Treat, data = anorexia, offset=Prewt)
13
summary(fit2)
13
summary(fit2)
14
stopifnot(all.equal(predict(fit2, anorexia), pred))
14
stopifnot(all.equal(predict(fit2, anorexia), pred))
15
 
15
 
16
## now spili into two parts
16
## now split into two parts
17
anorexia$o1 <- 0.9*anorexia$Prewt
17
anorexia$o1 <- 0.9*anorexia$Prewt
18
anorexia$o2 <- 0.1*anorexia$Prewt
18
anorexia$o2 <- 0.1*anorexia$Prewt
19
fit3 <- lm(Postwt ~ Prewt + Treat + offset(o1) + offset(o2), data = anorexia)
19
fit3 <- lm(Postwt ~ Prewt + Treat + offset(o1) + offset(o2), data = anorexia)
20
summary(fit3)
20
summary(fit3)
21
stopifnot(all.equal(predict(fit3, anorexia), pred))
21
stopifnot(all.equal(predict(fit3, anorexia), pred))
Line 23... Line 23...
23
fit4 <- lm(Postwt ~ Prewt + Treat + offset(o1), data = anorexia, offset = o2)
23
fit4 <- lm(Postwt ~ Prewt + Treat + offset(o1), data = anorexia, offset = o2)
24
summary(fit4)
24
summary(fit4)
25
stopifnot(all.equal(predict(fit4, anorexia), pred))
25
stopifnot(all.equal(predict(fit4, anorexia), pred))
26
 
26
 
27
## using more than one offset failed in R 2.8.1
27
## using more than one offset failed in R 2.8.1
-
 
28
 
-
 
29
 
-
 
30
## Using variable a name starting with "(weights)" :
-
 
31
anoD <- within(anorexia, `(weights)_2` <- Prewt)
-
 
32
fit5 <- lm(Postwt ~ `(weights)_2` + Treat + offset(o1) + offset(o2), data = anoD)
-
 
33
summary(fit5)
-
 
34
stopifnot(exprs = {
-
 
35
    all.equal(predict(fit5, anoD), pred)
-
 
36
    all.equal(sigma(fit5), sigma(fit1))
-
 
37
    is.null(model.weights(model.frame(fit5)))
-
 
38
})
-
 
39
## these were all (even the model fit!) wrong in R <= 4.2.1