My original model is
y_{ijk} \sim (X_k b+z_{1i}+z_{2j}, \sigma)\\ z_{1i} \sim N(0, \theta_1), z_{2j} \sim N(0, \theta_2)
with the following Stan code
data {
int<lower=1> N;
vector[N] Y;
int<lower=1> K;
matrix[N, K] X;
int<lower=1> J_1[N];
int<lower=1> N_1;
int<lower=1> M_1;
vector[N] Z_1_1;
int<lower=1> J_2[N];
int<lower=1> N_2;
int<lower=1> M_2;
vector[N] Z_2_1;
}
transformed data {
int Kc = K - 1;
matrix[N, K - 1] Xc;
vector[K - 1] means_X;
for (i in 2:K) {
means_X[i - 1] = mean(X[, i]);
Xc[, i - 1] = X[, i] - means_X[i - 1];
}
}
parameters {
vector[Kc] b;
real temp_Intercept;
real<lower=0> sigma;
vector<lower=0>[M_1] sd_1;
vector[N_1] z_1[M_1];
vector<lower=0>[M_2] sd_2;
vector[N_2] z_2[M_2];
}
transformed parameters {
vector[N_1] r_1_1 = sd_1[1] * (z_1[1]);
vector[N_2] r_2_1 = sd_2[1] * (z_2[1]);
}
model {
vector[N] mu = temp_Intercept + Xc * b;
for (n in 1:N) {
mu[n] += r_1_1[J_1[n]] * Z_1_1[n] + r_2_1[J_2[n]] * Z_2_1[n];
}
target += student_t_lpdf(temp_Intercept | 3, 0, 10);
target += student_t_lpdf(sigma | 3, 0, 10)
- 1 * student_t_lccdf(0 | 3, 0, 10);
target += student_t_lpdf(sd_1 | 3, 0, 10)
- 1 * student_t_lccdf(0 | 3, 0, 10);
target += normal_lpdf(z_1[1] | 0, 1);
target += student_t_lpdf(sd_2 | 3, 0, 10)
- 1 * student_t_lccdf(0 | 3, 0, 10);
target += normal_lpdf(z_2[1] | 0, 1);
}
}
generated quantities {
real b_Intercept = temp_Intercept - dot_product(means_X, b);
}
Now I would like to change the prior distribution for z_1 from Gaussian to Student’s t(1,0, 10)
y_{ijk} \sim (X_k b+z_{1i}+z_{2j}, \sigma) \\ z_{1i} \sim t(1, 0, 10), z_{2j} \sim N(0, \theta_2)
I have trouble getting the code working. In addition to replacing
target += student_t_lpdf(sd_1 | 3, 0, 10)
- 1 * student_t_lccdf(0 | 3, 0, 10);
target += normal_lpdf(z_1[1] | 0, 1);
with
target += student_t_lpdf(z_1[1] | 1, 0, 10);
what else should I change? I’m not so sure how to adjust the following
transformed parameters {
vector[N_1] r_1_1 = sd_1[1] * (z_1[1]);
vector[N_2] r_2_1 = sd_2[1] * (z_2[1]);
}