# Unable to view posterior predictive values

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)
``````

Can you post the code you’re using to view the results? Are you using RStan, cmdstanr, PyStan, or cmdstanpy?

I’m using RStan. I used the following code to extract y_pred and plot the density curves but it gives me an error stating there is no parameter y_pred

``````y_pred4 <- as.matrix(fits4, pars="y_pred")
ppc_dens_overlay(y, y_pred4[1:100,])
``````

My RStan is rusty; does that code work for a parameter? For example `mu`? Also, I don’t think this would be the problem, but as a long-shot: add a space between the variable type declaration and the variable names in the GQ block.

I can see values of the parameters mu and beta but not y_pred