Skip to content

Commit 47dd176

Browse files
committed
added 17.3-17.6 preliminary models
1 parent afd307b commit 47dd176

File tree

4 files changed

+186
-0
lines changed

4 files changed

+186
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
data {
2+
int<lower=0> N;
3+
int<lower=0> n_treatment;
4+
int<lower=0> n_airport;
5+
int<lower=0,upper=n_treatment> treatment[N];
6+
int<lower=0,upper=n_airport> airport[N];
7+
}
8+
parameters {
9+
real<lower=0> sigma;
10+
real<lower=0> sigma_gamma;
11+
real<lower=0> sigma_delta;
12+
vector[n_treatment] gamma;
13+
vector[n_airport] delta;
14+
}
15+
model {
16+
vector[N] y_hat;
17+
18+
sigma ~ uniform(0, 100);
19+
sigma_gamma ~ uniform(0, 100);
20+
sigma_delta ~ uniform(0, 100);
21+
22+
mu ~ normal(0, 100);
23+
24+
gamma ~ normal(0, sigma_gamma);
25+
delta ~ normal(0, sigma_delta);
26+
27+
for (i in 1:N)
28+
y_hat[i] <- mu + gamma[treatment[i]] + delta[airport[i]];
29+
30+
y ~ normal(y_hat, sigma);
31+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
data {
2+
int<lower=0> N;
3+
int<lower=0> n_age;
4+
int<lower=0> n_edu;
5+
int<lower=0> n_region;
6+
int<lower=0> n_state;
7+
8+
int<lower=0, upper=1> female[N];
9+
int<lower=0, upper=1> black[N];
10+
int<lower=0, upper=n_age> age[N];
11+
int<lower=0, upper=n_edu> edu[N];
12+
int<lower=0, upper=n_state> region[N];
13+
int<lower=0, upper=n_state> state[N];
14+
}
15+
parameters {
16+
real<lower=0> sigma;
17+
real<lower=0> sigma_age;
18+
real<lower=0> sigma_edu;
19+
real<lower=0> sigma_state;
20+
real<lower=0> sigma_region;
21+
real<lower=0> sigma_age_edu;
22+
23+
real b_0;
24+
real b_female;
25+
real b_black;
26+
real b_female_black;
27+
28+
real b_v_prev;
29+
30+
vector[n_age] b_age;
31+
vector[n_edu] b_edu;
32+
vector[n_region] b_region;
33+
matrix[n_age,n_edu] b_age_edu;
34+
35+
vector[n_state] b_hat;
36+
}
37+
model {
38+
vector[N] p;
39+
vector[n_state] b_state_hat;
40+
41+
b_0 ~ normal(0, 100);
42+
b_female ~ normal(0, 100);
43+
b_black ~ normal(0, 100);
44+
b_female_black ~ normal(0, 100);
45+
46+
b_age ~ normal(0, sigma_age);
47+
b_edu ~ normal(0, sigma_edu);
48+
b_region ~ normal(0, sigma_region);
49+
50+
for (j in 1:n_age)
51+
b_age_edu[j,] ~ normal(0, sigma_age_edu);
52+
53+
b_v_prev ~ normal(0, 100);
54+
55+
for (j in 1:n_state)
56+
b_state_hat[j] <- b_region[region[j]] + b_v_prev * v_prev[j];
57+
58+
b_hat ~ normal(b_state_hat, sigma_state);
59+
60+
for (i in 1:N)
61+
p[i] <- max(0, min(1, inv_logit(b_0 + b_female*female[i]
62+
+ b_black*black[i] + b_female_black*female[i]*black[i] +
63+
b_age[age[i]] + b_edu[edu[i]] + b_age_edu[age[i],edu[i]] +
64+
b_state[state[i]])));
65+
66+
y ~ binomial(1, p);
67+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
data {
2+
int<lower=0> N;
3+
int<lower=0> n_eth;
4+
int<lower=0> n_precint;
5+
6+
int<lower=0, upper=n_precint> precint[N];
7+
int<lower=0, upper=n_eth> eth[N];
8+
vector offeset[N];
9+
vector stops[N];
10+
}
11+
parameters {
12+
real mu;
13+
real<lower=0> sigma_epsilon;
14+
real<lower=0> sigma_eth;
15+
real<lower=0> sigma_precint;
16+
17+
vector[n_eth] b_eth;
18+
vector[n_precint] b_precint;
19+
vector[N] epsilon;
20+
}
21+
model {
22+
real mu_adj;
23+
vector[n_eth] b_eth_adj;
24+
vector[n_precint] b_precint_adj;
25+
26+
mu ~ normal(0, 100);
27+
mu_adj <- mu + mean(b_eth) + mean(b_precint);
28+
29+
b_eth ~ normal(0, sigma_eth);
30+
b_eth_adj <- b_eth - mean(b_eth);
31+
32+
b_precint ~ normal(0, sigma_precint);
33+
b_precint_adj <- b_precint - mean(b_precint);
34+
35+
epsilon ~ normal(0, sigma_epsilon);
36+
37+
for (i in 1:N)
38+
lambda[i] <- offeset[i] + mu + b_eth[eth[i]] + b_precint[precint[i]]
39+
+ epsilon[i];
40+
41+
stops ~ poisson_log(lambda);
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
data {
2+
int<lower=0> N;
3+
int<lower=0> n_cut;
4+
int<lower=0> n_player;
5+
6+
int<lower=0, upper=n_player> player[N];
7+
vector y[N];
8+
}
9+
parameters {
10+
vector[n_cut] mu_c;
11+
real mu_log_s;
12+
13+
vector<lower=0>[n_cut] sigma_c;
14+
real<lower=0> sigma_log_s;
15+
16+
matrix[n_player,2] C;
17+
vector[n_player] s;
18+
}
19+
model {
20+
real mu_adj;
21+
matrix[N,n_cut] Q;
22+
matrix[N,n_cut] P;
23+
24+
mu_c ~ normal(0, 1000);
25+
mu_log_s ~ normal(0, 100);
26+
27+
for (i in 1:n_player) {
28+
C[i,1] ~ normal(mu_c[1], sigma_c[1]) T[0,C[i,2]];
29+
C[i,2] ~ normal(mu_c[2], sigma_c[1]) T[C[i,1],100];
30+
s[i] ~ lognormal(mu_log_s, sigma_log_s) T[1,100];
31+
}
32+
33+
for (i in 1:N) {
34+
for (i_cut in 1:n_cut)
35+
Q[i,i_cut] <- inv_logit((x[i] - C[player[i],i_cut])/s[player[i]]);
36+
37+
P[i,1] <- 1 - Q[i,1];
38+
P[i,n_cut+1] <- Q[i,n_cut];
39+
for (i_cut in 2:n_cut)
40+
P[i,i_cut] <- Q[i,i_cut-1] - Q[i,i_cut];
41+
}
42+
43+
for (i in 1:N)
44+
y[i] ~ categorical(P[i,]);
45+
46+
}

0 commit comments

Comments
 (0)