-
-
Notifications
You must be signed in to change notification settings - Fork 478
/
electric_1c_chr.stan
42 lines (40 loc) · 1.02 KB
/
electric_1c_chr.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
data {
int<lower=0> N;
int<lower=0> n_grade;
int<lower=0> n_grade_pair;
int<lower=0> n_pair;
array[N] int<lower=1, upper=n_grade> grade;
array[n_pair] int<lower=1, upper=n_grade_pair> grade_pair;
array[N] int<lower=1, upper=n_pair> pair;
vector[N] pre_test;
vector[N] treatment;
vector[N] y;
}
parameters {
vector[n_pair] eta_a;
vector[n_grade_pair] mu_a;
vector<lower=0, upper=100>[n_grade_pair] sigma_a;
vector<lower=0, upper=100>[n_grade] sigma_y;
vector[n_grade] b;
vector[n_grade] c;
}
transformed parameters {
vector[n_pair] a;
vector<lower=0, upper=100>[N] sigma_y_hat;
vector[N] y_hat;
for (i in 1 : n_pair) {
a[i] = 50 * mu_a[grade_pair[i]] + sigma_a[grade_pair[i]] * eta_a[i];
}
for (i in 1 : N) {
y_hat[i] = a[pair[i]] + b[grade[i]] * treatment[i]
+ c[grade[i]] * pre_test[i];
sigma_y_hat[i] = sigma_y[grade[i]];
}
}
model {
eta_a ~ normal(0, 1);
mu_a ~ normal(0, 1);
b ~ normal(0, 100);
c ~ normal(0, 100);
y ~ normal(y_hat, sigma_y_hat);
}