data(Trolley, package = "rethinking")
d <- Trolley
# set up ordered categories for education
d <-
d %>%
mutate(edu_new =
recode(edu,
"Elementary School" = 1,
"Middle School" = 2,
"Some High School" = 3,
"High School Graduate" = 4,
"Some College" = 5,
"Bachelor's Degree" = 6,
"Master's Degree" = 7,
"Graduate Degree" = 8) %>%
as.integer())
# estimate total effect of education
m_total <- brm(
data = d,
family = cumulative,
response ~ 1 + mo(edu_new),
prior = c( prior(normal(0, 1.5), class = Intercept),
prior(normal(0, 0.143), class = b, coef = moedu_new),
prior(dirichlet(2, 2, 2, 2, 2, 2, 2), class = simo, coef = moedu_new1)),
iter=2000, warmup=1000, cores=4, chains=4,
file=here("files/models/hw6.1")
)
# estimate direct effect of education
m_direct <- brm(
data = d,
family = cumulative,
response ~ 1 + age + mo(edu_new),
prior = c( prior(normal(0, 1.5), class = Intercept),
prior(normal(0, 1), class=b),
prior(normal(0, 0.143), class = b, coef = moedu_new),
prior(dirichlet(2, 2, 2, 2, 2, 2, 2), class = simo, coef = moedu_new1)),
iter=2000, warmup=1000, cores=4, chains=4,
file=here("files/models/hw6.2")
)