The R Project SVN R

Rev

Rev 69217 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 69217 Rev 74683
Line 1... Line 1...
1
## tests of the simulate.lm method, added Feb 2009
1
## tests of the simulate.lm method, added Feb 2009
2
 
2
 
3
options(digits = 5)
3
options(digits = 5)
4
 
4
 
5
## cases should be named
5
## cases should be named
6
load("hills.rda") # copied from package MASS
6
hills <- readRDS("hills.rds") # copied from package MASS
7
fit1 <- lm(time ~ dist, data = hills)
7
fit1 <- lm(time ~ dist, data = hills)
8
set.seed(1)
8
set.seed(1)
9
simulate(fit1, nsim = 3)
9
simulate(fit1, nsim = 3)
10
 
10
 
11
## and weights should be taken into account
11
## and weights should be taken into account
12
fit2 <- lm(time ~ -1 + dist + climb, hills[-18, ], weight = 1/dist^2)
12
fit2 <- lm(time ~ -1 + dist + climb, hills[-18, ], weight = 1/dist^2)
13
coef(summary(fit2))
13
coef(summary(fit2))
14
set.seed(1)
-
 
15
( ys <- simulate(fit2, nsim = 3) )
14
set.seed(1); ( ys <- simulate(fit2, nsim = 3) )
16
for(i in seq_len(3))
15
for(i in seq_len(3))
17
    print(coef(summary(update(fit2, ys[, i] ~ .))))
16
    print(coef(summary(update(fit2, ys[, i] ~ .))))
-
 
17
## should be identical to glm(*, gaussian):
-
 
18
fit2. <- glm(time ~ -1 + dist + climb, family=gaussian, data=hills[-18, ],
-
 
19
             weight = 1/dist^2)
-
 
20
set.seed(1); ys. <- simulate(fit2., nsim = 3)
-
 
21
stopifnot(all.equal(ys, ys.))
18
 
22
 
19
## Poisson fit
23
## Poisson fit
20
load("anorexia.rda") # copied from package MASS
24
load("anorexia.rda") # copied from package MASS
21
fit3 <- glm(Postwt ~ Prewt + Treat + offset(Prewt),
25
fit3 <- glm(Postwt ~ Prewt + Treat + offset(Prewt),
22
            family = gaussian, data = anorexia)
26
            family = gaussian, data = anorexia)