Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ARM/Ch.10/ideo_interactions.stan
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ data {
vector[N] x;
}
transformed data {
vector[N] inter;

inter = party .* x;
vector[N] inter = party .* x;
matrix[N,3] cov = [party', x', inter']';
}
parameters {
vector[4] beta;
real alpha;
vector[3] beta;
real<lower=0> sigma;
}
model {
score1 ~ normal(beta[1] + beta[2] * party + beta[3] * x + beta[4] * inter,sigma);
score1 ~ normal_id_glm(cov, alpha, beta, sigma);
}
8 changes: 6 additions & 2 deletions ARM/Ch.10/ideo_reparam.stan
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ data {
vector[N] z1; //z value for party 0, 0 otherwise
vector[N] z2; //z value for party 1, 0 otherwise
}
transformed data {
matrix[N,3] x = [party', z1', z2']';
}
parameters {
vector[4] beta;
real alpha;
vector[3] beta;
real<lower=0> sigma;
}
model {
score1 ~ normal(beta[1] + beta[2] * party + beta[3] * z1 + beta[4] * z2,sigma);
score1 ~ normal_id_glm(x, alpha, beta, sigma);
}
8 changes: 6 additions & 2 deletions ARM/Ch.10/ideo_two_pred.stan
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ data {
vector[N] score1;
vector[N] x;
}
transformed data {
matrix[N,2] cov = [party', x']';
}
parameters {
vector[3] beta;
real alpha;
vector[2] beta;
real<lower=0> sigma;
}
model {
score1 ~ normal(beta[1] + beta[2] * party + beta[3] * x,sigma);
score1 ~ normal_id_glm(cov, alpha, beta, sigma);
}
14 changes: 9 additions & 5 deletions ARM/Ch.10/sesame_multi_preds_3a.stan
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ transformed data {
vector[N] site2;
vector[N] site3;
vector[N] site4;
vector[N] site5;
vector[N] site5;
matrix[N,7] x;

for (i in 1:N) {
site2[i] = site[i] == 2;
site3[i] = site[i] == 3;
site4[i] = site[i] == 4;
site5[i] = site[i] == 5;
}

x = [encouraged', pretest', site2', site3',
site4', site5', setting']';
}
parameters {
vector[8] beta;
real alpha;
vector[7] beta;
real<lower=0> sigma;
}
model {
watched ~ normal(beta[1] + beta[2] * encouraged + beta[3] * pretest
+ beta[4] * site2 + beta[5] * site3 + beta[6] * site4
+ beta[7] * site5 + beta[8] * setting,sigma);
watched ~ normal_id_glm(x, alpha, beta, sigma);
}
14 changes: 9 additions & 5 deletions ARM/Ch.10/sesame_multi_preds_3b.stan
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ transformed data {
vector[N] site2;
vector[N] site3;
vector[N] site4;
vector[N] site5;
vector[N] site5;
matrix[N,7] x;

for (i in 1:N) {
site2[i] = site[i] == 2;
site3[i] = site[i] == 3;
site4[i] = site[i] == 4;
site5[i] = site[i] == 5;
}

x = [watched_hat', pretest', site2', site3',
site4', site5', setting']';
}
parameters {
vector[8] beta;
real alpha;
vector[7] beta;
real<lower=0> sigma;
}
model {
y ~ normal(beta[1] + beta[2] * watched_hat + beta[3] * pretest
+ beta[4] * site2 + beta[5] * site3 + beta[6] * site4
+ beta[7] * site5 + beta[8] * setting,sigma);
y ~ normal_id_glm(x, alpha, beta, sigma);
}
8 changes: 6 additions & 2 deletions ARM/Ch.10/sesame_one_pred_2b.stan
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ data {
vector[N] watched_hat;
vector[N] y;
}
transformed data {
matrix[N,1] x = [watched_hat']';
}
parameters {
vector[2] beta;
real alpha;
vector[1] beta;
real<lower=0> sigma;
}
model {
y ~ normal(beta[1] + beta[2] * watched_hat,sigma);
y ~ normal_id_glm(x, alpha, beta, sigma);
}
8 changes: 6 additions & 2 deletions ARM/Ch.10/sesame_one_pred_a.stan
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ data {
vector[N] encouraged;
vector[N] watched;
}
transformed data {
matrix[N,1] x = [encouraged']';
}
parameters {
vector[2] beta;
real alpha;
vector[1] beta;
real<lower=0> sigma;
}
model {
watched ~ normal(beta[1] + beta[2] * encouraged,sigma);
watched ~ normal_id_glm(x, alpha, beta, sigma);
}
8 changes: 6 additions & 2 deletions ARM/Ch.10/sesame_one_pred_b.stan
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ data {
vector[N] encouraged;
vector[N] y;
}
transformed data {
matrix[N,1] x = [encouraged']';
}
parameters {
vector[2] beta;
real alpha;
vector[1] beta;
real<lower=0> sigma;
}
model {
y ~ normal(beta[1] + beta[2] * encouraged,sigma);
y ~ normal_id_glm(x, alpha, beta, sigma);
}
8 changes: 6 additions & 2 deletions ARM/Ch.12/radon_complete_pool.stan
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ data {
vector[N] x;
vector[N] y;
}
transformed data {
matrix[N,1] cov = [x']';
}
parameters {
vector[2] beta;
real alpha;
vector[1] beta;
real<lower=0> sigma;
}
model {
sigma ~ cauchy(0, 2.5);
y ~ normal(beta[1] + beta[2] * x, sigma);
y ~ normal_id_glm(cov, alpha, beta, sigma);
}
17 changes: 8 additions & 9 deletions ARM/Ch.12/radon_group.stan
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ data {
vector[N] x;
vector[N] y;
}
transformed data {
matrix[N,2] cov = [x', u']';
}
parameters {
vector[J] alpha;
vector[2] beta;
real mu_alpha;
real mu_beta;
real<lower=0> sigma;
real<lower=0> sigma_alpha;
real<lower=0> sigma_beta;
vector<offset=mu_alpha, multiplier=sigma_alpha>[J] alpha;
vector<offset=mu_beta, multiplier=sigma_beta>[2] beta;
}
model {
vector[N] y_hat;
for (i in 1:N)
y_hat[i] = alpha[county[i]] + x[i] * beta[1] + u[i] * beta[2];

alpha ~ normal(mu_alpha, sigma_alpha);
beta ~ normal(mu_beta, sigma_beta);
sigma ~ cauchy(0, 2.5);
mu_alpha ~ normal(0, 1);
mu_alpha ~ std_normal();
sigma_alpha ~ cauchy(0, 2.5);
mu_beta ~ normal(0, 1);
mu_beta ~ std_normal();
sigma_beta ~ cauchy(0, 2.5);

y ~ normal(y_hat, sigma);
y ~ normal_id_glm(cov, alpha[county], beta, sigma);
}
26 changes: 10 additions & 16 deletions ARM/Ch.12/radon_group_chr.stan
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,22 @@ data {
vector[N] x;
vector[N] y;
}
transformed data {
matrix[N,2] cov = [x', u']';
}
parameters {
vector[2] beta;
vector[J] eta;
real mu_b;
real mu_a;
real<lower=0> sigma;
real<lower=0> sigma_b;
}
transformed parameters {
vector[J] b;
vector[N] y_hat;

b = mu_b + sigma_b * eta;

for (i in 1:N)
y_hat[i] = b[county[i]] + x[i] * beta[1] + u[i] * beta[2];
real<lower=0> sigma_a;
vector<offset=mu_a, multiplier=sigma_a>[J] alpha;
}
model {
mu_b ~ normal(0, 1);
eta ~ normal(0, 1);
mu_a ~ std_normal();
beta ~ normal(0, 100);
sigma ~ cauchy(0, 2.5);
sigma_b ~ cauchy(0, 2.5);
sigma_a ~ cauchy(0, 2.5);
alpha ~ normal(mu_a, sigma_a);

y ~ normal(y_hat, sigma);
y ~ normal_id_glm(cov, alpha[county], beta, sigma);
}
12 changes: 4 additions & 8 deletions ARM/Ch.12/radon_intercept.stan
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ data {
vector[N] y;
}
parameters {
vector[J] a; # county intercepts
real mu_a;
real<lower=0> sigma_a;
real<lower=0> sigma_y;
vector<offset=mu_a, multiplier=sigma_a>[J] a; # county intercepts
}
model {
vector[N] y_hat;
for (i in 1:N)
y_hat[i] = a[county[i]];

mu_a ~ normal(0, 1);
mu_a ~ std_normal();
sigma_a ~ cauchy(0, 2.5);
sigma_y ~ cauchy(0, 2.5);
a ~ normal (mu_a, sigma_a);
y ~ normal(y_hat, sigma_y);
a ~ normal(mu_a, sigma_a);
y ~ normal(a[county], sigma_y);
}

16 changes: 4 additions & 12 deletions ARM/Ch.12/radon_intercept_chr.stan
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,17 @@ data {
vector[N] y;
}
parameters {
vector[J] eta;
real mu_a;
real<lower=0> sigma_a;
real<lower=0> sigma_y;
vector<offset=(10 * mu_a), multiplier=sigma_a>[J] alpha;
}
transformed parameters {
vector[J] a;
vector[N] y_hat;

a = 10 * mu_a + sigma_a * eta;

for (i in 1:N)
y_hat[i] = a[county[i]];
}
model {
mu_a ~ normal(0, 1);
eta ~ normal(0, 1);
mu_a ~ std_normal();
alpha ~ normal(10 * mu_a, sigma_a);
sigma_a ~ cauchy(0, 2.5);
sigma_y ~ cauchy(0, 2.5);

y ~ normal(y_hat, sigma_y);
y ~ normal(alpha[county], sigma_y);
}
17 changes: 8 additions & 9 deletions ARM/Ch.12/radon_no_pool.stan
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ data {
vector[N] x;
vector[N] y;
}
transformed data {
matrix[N,1] cov = [x']';
}
parameters {
vector[J] a;
real beta;
vector[1] beta;
real<lower=0> sigma_a;
real<lower=0> sigma_y;
real mu_a;
vector<offset=mu_a, multiplier=sigma_a>[J] a;
}
model {
vector[N] y_hat;
for (i in 1:N)
y_hat[i] = beta * x[i] + a[county[i]];

beta ~ normal(0, 1);
mu_a ~ normal(0, 1);
beta ~ std_normal();
mu_a ~ std_normal();
sigma_a ~ cauchy(0, 2.5);
sigma_y ~ cauchy(0, 2.5);

a ~ normal(mu_a, sigma_a);
y ~ normal(y_hat, sigma_y);
y ~ normal_id_glm(cov, a[county], beta, sigma_y);
}
24 changes: 9 additions & 15 deletions ARM/Ch.12/radon_no_pool_chr.stan
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,22 @@ data {
vector[N] x;
vector[N] y;
}
transformed data {
matrix[N,1] cov = [x']';
}
parameters {
real beta;
vector[J] eta;
vector[1] beta;
real mu_a;
real<lower=0> sigma_a;
real<lower=0> sigma_y;
}
transformed parameters {
vector[J] a;
vector[N] y_hat;

a = mu_a + sigma_a * eta;

for (i in 1:N)
y_hat[i] = beta * x[i] + a[county[i]];
vector<offset=mu_a, multiplier=sigma_a>[J] alpha;
}
model {
beta ~ normal(0, 1);
mu_a ~ normal(0, 1);
eta ~ normal(0, 1);
beta ~ std_normal();
mu_a ~ std_normal();
alpha ~ normal(mu_a, sigma_a);
sigma_a ~ cauchy(0, 2.5);
sigma_y ~ cauchy(0, 2.5);

y ~ normal(y_hat, sigma_y);
y ~ normal_id_glm(cov, alpha[county], beta, sigma_y);
}