-
-
Notifications
You must be signed in to change notification settings - Fork 478
/
lsat.stan
51 lines (49 loc) · 1.02 KB
/
lsat.stan
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
// LSAT: item response
// http://www.openbugs.net/Examples/Lsat.html
data {
int<lower=0> N; // 1000, number of students
int<lower=0> R; // 32, number of patterns of results: 2^T
int<lower=0> T; // 5, number of questions
array[R] int<lower=0> culm;
array[R, T] int<lower=0> response;
}
transformed data {
array[T, N] int r;
vector[N] ones;
for (j in 1 : culm[1]) {
for (k in 1 : T) {
r[k, j] = response[1, k];
}
}
for (i in 2 : R) {
for (j in (culm[i - 1] + 1) : culm[i]) {
for (k in 1 : T) {
r[k, j] = response[i, k];
}
}
}
for (i in 1 : N) {
ones[i] = 1.0;
}
}
parameters {
array[T] real alpha;
vector[N] theta;
real<lower=0> beta;
}
model {
alpha ~ normal(0, 100.);
theta ~ normal(0, 1);
beta ~ normal(0.0, 100.);
for (k in 1 : T) {
r[k] ~ bernoulli_logit(beta * theta - alpha[k] * ones);
}
}
generated quantities {
real mean_alpha;
array[T] real a;
mean_alpha = mean(alpha);
for (t in 1 : T) {
a[t] = alpha[t] - mean_alpha;
}
}