-
Notifications
You must be signed in to change notification settings - Fork 0
/
multinomial-test.stan
57 lines (49 loc) · 1001 Bytes
/
multinomial-test.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
52
53
54
55
56
57
data {
int<lower=0> N;
real us[N];
int<lower=1, upper=3> ADM[N];
}
transformed data {
int zero[3];
int ADMx[N,3];
vector[3] totalcount;
vector[3] a0;
for(j in 1:3) {
zero[j] = 0;
totalcount[j] = 0;
}
for(i in 1:N) {
ADMx[i] = zero;
ADMx[i, ADM[i]] = 1;
}
for(i in 1:N) {
totalcount[ADM[i]] += 1;
}
for(j in 1:3) {
a0[j] = logit(totalcount[j] / N);
}
for(j in 1:3) {
// Adding a constant to all values of alpha leaves the model unchanged
a0[j] -= a0[3];
}
print("a0: ", a0);
}
parameters {
vector[3] alpha;
vector[3] beta;
}
model {
alpha ~ normal(a0, 0.25);
beta ~ normal(0, 0.5);
// peg the third (ED) entry (technically we should exclude them from the priors
// above, but this will be fine)
alpha[3] ~ normal(a0[3], 0.1);
beta[3] ~ normal(0, 0.1);
for(i in 1:N) {
vector[3] theta;
for(j in 1:3) {
theta[j] = alpha[j] + beta[j] * us[i];
}
ADMx[i] ~ multinomial_logit(theta);
}
}