-
-
Notifications
You must be signed in to change notification settings - Fork 478
/
election88_full.stan
49 lines (48 loc) · 1.33 KB
/
election88_full.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
data {
int<lower=0> N;
int<lower=0> n_age;
int<lower=0> n_age_edu;
int<lower=0> n_edu;
int<lower=0> n_region_full;
int<lower=0> n_state;
array[N] int<lower=0, upper=n_age> age;
array[N] int<lower=0, upper=n_age_edu> age_edu;
vector<lower=0, upper=1>[N] black;
array[N] int<lower=0, upper=n_edu> edu;
vector<lower=0, upper=1>[N] female;
array[N] int<lower=0, upper=n_region_full> region_full;
array[N] int<lower=0, upper=n_state> state;
vector[N] v_prev_full;
array[N] int<lower=0, upper=1> y;
}
parameters {
vector[n_age] a;
vector[n_edu] b;
vector[n_age_edu] c;
vector[n_state] d;
vector[n_region_full] e;
vector[5] beta;
real<lower=0, upper=100> sigma_a;
real<lower=0, upper=100> sigma_b;
real<lower=0, upper=100> sigma_c;
real<lower=0, upper=100> sigma_d;
real<lower=0, upper=100> sigma_e;
}
transformed parameters {
vector[N] y_hat;
for (i in 1 : N) {
y_hat[i] = beta[1] + beta[2] * black[i] + beta[3] * female[i]
+ beta[5] * female[i] * black[i] + beta[4] * v_prev_full[i]
+ a[age[i]] + b[edu[i]] + c[age_edu[i]] + d[state[i]]
+ e[region_full[i]];
}
}
model {
a ~ normal(0, sigma_a);
b ~ normal(0, sigma_b);
c ~ normal(0, sigma_c);
d ~ normal(0, sigma_d);
e ~ normal(0, sigma_e);
beta ~ normal(0, 100);
y ~ bernoulli_logit(y_hat);
}