-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sec 2.1: tree-girl-height
60 lines (54 loc) · 2.26 KB
/
Sec 2.1: tree-girl-height
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# relationship among age, tree height & girl height
# simulated data of age (year), tree and girl height (in centimeter)
dd <- "
age tree girl
0 29.6 50.4
1 98.3 57.9
2 178.2 65.7
3 261.7 74.3
4 332.6 82.0
5 427.0 90.7
6 504.2 99.0
7 581.0 104.8
8 666.5 113.8
9 737.3 121.4
10 814.0 129.7
11 897.0 138.1
12 986.4 145.4
13 1063.5 154.3
14 1134.0 163.3
15 1218.6 169.7
16 1306.3 177.8
17 1377.7 186.5
"
dd <- read.table(textConnection(dd), header=T)
# 3 models
m1 <- lm(girl~tree, data=dd)
m2 <- lm(girl~age+tree, data=dd)
m3 <- lm(girl~age, data=dd)
# point estimate & 95% interval: tree-girl association based on model m1
c(summary(m1)$coefficients['tree', 'Estimate'], summary(m1)$coefficients['tree', 'Estimate']-qt(0.975,
summary(m1)$df[2])*summary(m1)$coefficients['tree', 'Std. Error'],
summary(m1)$coefficients['tree', 'Estimate']+qt(0.975,
summary(m1)$df[2])*summary(m1)$coefficients['tree', 'Std. Error'])
#[1] 0.10019338 0.09922737 0.10115938
# point estimate & 95% interval: tree-girl association based on model m2
c(summary(m2)$coefficients['tree', 'Estimate'],
summary(m2)$coefficients['tree', 'Estimate']-qt(0.975,
summary(m2)$df[2])*summary(m2)$coefficients['tree', 'Std. Error'],
summary(m2)$coefficients['tree', 'Estimate']+qt(0.975,
summary(m2)$df[2])*summary(m2)$coefficients['tree', 'Std. Error'])
#[1] 0.004057802 -0.061985409 0.070101014
# point estimate & 95% interval: girl growth rate based on model m2
c(summary(m2)$coefficients['age', 'Estimate'],
summary(m2)$coefficients['age', 'Estimate']-qt(0.975,
summary(m2)$df[2])*summary(m2)$coefficients['age', 'Std. Error'],
summary(m2)$coefficients['age', 'Estimate']+qt(0.975,
summary(m2)$df[2])*summary(m2)$coefficients['age', 'Std. Error'])
#[1] 7.678621 2.403933 12.953308
# point estimate & 95% interval: girl growth rate based on model m3
c(summary(m3)$coefficients['age', 'Estimate'],
summary(m3)$coefficients['age', 'Estimate']-qt(0.975, summary(m3)$df[2])*summary(m3)$coefficients['age', 'Std. Error'],
summary(m3)$coefficients['age', 'Estimate']+qt(0.975,
summary(m3)$df[2])*summary(m3)$coefficients['age', 'Std. Error'])
#[1] 8.002683 7.942437 8.062929