-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstan_example.R
29 lines (24 loc) · 868 Bytes
/
stan_example.R
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
# Fitting the MathAchieve mixed model using lmer
library(lme4)
library(nlme)
data(MathAcheivement)
data(MathAchieve)
students <- MathAchieve
fit.lmer = lmer(MathAch ~ 1 + (1 | School), students)
# prepping the stan data
sub = with(MathAchieve, levels(School)[1:8])
students = MathAchieve[MathAchieve$School %in% sub,]
students$School = factor(as.character(students$School))
schools = MathAchSchool[MathAchSchool$School %in% sub,]
schools$School = factor(as.character(schools$School))
##
## First Example
##
math_data.1 = list(N = nrow(students),
J = nrow(schools),
score = students$MathAch,
ses = students$SES,
school = as.integer(students$School))
setwd("~/Desktop/")
fit.stan <- fit <- stan(file = 'schools.stan', data = math_data.1,
iter = 1000, chains = 4)