-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchp6-code.Rmd
113 lines (84 loc) · 2.02 KB
/
chp6-code.Rmd
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: "Laurits"
output: html_document
---
```{r}
library(rethinking)
data(Howell1)
d <- Howell1
d$age <- (d$age - mean(d$age))/sd(d$age)
set.seed( 1000 )
i <- sample(1:nrow(d),size=nrow(d)/2)
d1 <- d[ i , ]
d2 <- d[ -i , ]
```
```{r}
m1 <- rethinking::map(
alist(
height ~ dnorm( mu , sigma ) ,
mu <- a + b*age,
a ~ dnorm(130, 50),
b ~ dnorm(0, 10),
sigma ~ dnorm(0, 10)
), data = d1)
m2 <- rethinking::map(
alist(
height ~ dnorm( mu , sigma ) ,
mu <- a + b1*age + b2*age*age,
a ~ dnorm(130, 50),
b1 ~ dnorm(0, 10),
b2 ~ dnorm(0, 10),
sigma ~ dnorm(0, 10)
), data = d1)
m3 <- rethinking::map(
alist(
height ~ dnorm( mu , sigma ) ,
mu <- a + b1*age + b2*age^2 + b3*age^3,
a ~ dnorm(130, 50),
b1 ~ dnorm(0, 10),
b2 ~ dnorm(0, 10),
b3 ~ dnorm(0, 10),
sigma ~ dnorm(0, 10)
), data = d1)
m4 <- rethinking::map(
alist(
height ~ dnorm( mu , sigma ) ,
mu <- a + b1*age + b2*age^2 + b3*age^3 + b4*age^4,
a ~ dnorm(130, 50),
b1 ~ dnorm(0, 10),
b2 ~ dnorm(0, 10),
b3 ~ dnorm(0, 10),
b4 ~ dnorm(0, 10),
sigma ~ dnorm(0, 10)
), data = d1)
m5 <- rethinking::map(
alist(
height ~ dnorm( mu , sigma ) ,
mu <- a + b1*age + b2*age^2 + b3*age^3 + b4*age^4 + b5*age^5,
a ~ dnorm(130, 50),
b1 ~ dnorm(0, 10),
b2 ~ dnorm(0, 10),
b3 ~ dnorm(0, 10),
b4 ~ dnorm(0, 10),
b5 ~ dnorm(0, 10),
sigma ~ dnorm(0, 10)
), data = d1)
m6 <- rethinking::map(
alist(
height ~ dnorm( mu , sigma ) ,
mu <- a + b1*age + b2*age^2 + b3*age^3 + b4*age^4 + b5*age^5 + b6*age^6,
a ~ dnorm(130, 50),
b1 ~ dnorm(0, 10),
b2 ~ dnorm(0, 10),
b3 ~ dnorm(0, 10),
b4 ~ dnorm(0, 10),
b5 ~ dnorm(0, 10),
b6 ~ dnorm(0, 10),
sigma ~ dnorm(0, 10)
), data = d1)
```
```{r}
compare(m1,m2,m3,m4,m5,m6)
```
```{r}
```