Hi, I’ve fitted a hierarchical linear regression model with a generated quantities block to simulate posterior predictive values. However, I can’t find the values in the stan fit object (fits4). Any suggestions on what might be causing this issue?
data {
int<lower=0> N;
int<lower=0> J;
vector[N] y;
vector[N] x;
int group[N];
}
parameters {
real<lower=0> sigma;
real<lower=0> tau_mu;
real<lower=0> tau_beta;
real nu_mu;
real nu_beta;
vector<offset=nu_mu, multiplier=tau_mu>[J] mu;
vector<offset=nu_beta, multiplier=tau_beta>[J] beta;
}
model {
nu_mu ~ normal(0,1);
nu_beta ~ normal(0,1);
tau_mu ~ gamma(1,1);
tau_beta ~ gamma(1,1);
sigma ~ gamma(1,1);
mu ~ normal(nu_mu, tau_mu);
beta ~ normal(nu_beta, tau_beta);
y ~ normal(mu[group] + beta[group] .* x, sigma);
}
generated quantities {
vector[N]y_pred;
vector[J]beta_pred;
vector[J]mu_pred;
for (j in 1:J){
mu_pred[j] = normal_rng(nu_mu, tau_mu);
}
for (j in 1:J){
beta_pred[j] = normal_rng(nu_beta, tau_beta);
}
for (i in 1:N){
y_pred[i] = normal_rng(mu_pred[group[i]] + beta_pred[group[i]]*x[i], sigma);
}
}
stan_fit4 <- list(N=length(sim.data.hier$x),
J=20,
y=df$y,
x=df$x,
group=df$group_int)
fits4 <- sampling(model4, data=stan_fit4)