Prior predictive check

Hello all Stan coders,

I am trying to obtain a prior predictive check graph, but I do not know how to specify the random normal draws from a vector of betas. I tried specifying vector [P] beta = normal_rng(0, 2), but did not work.

Here is my code.

data {
int<lower=0> N; // Number of data items
int<lower=0> P; // number of predictors in regression

matrix[N,P] X; // matrix for regression
vector[N] Y;

}

generated quantities {

vector [N] y_predict;

vector[P] beta = normal_rng(0, 2); ???

real alpha = normal_rng(0, 2);

real<lower = 0> sigma = inv_gamma_rng(2,2);

for (i in 1:N) {
y_predict[i] ~ normal_rng(alpha + X[i]*beta, sigma);
}

}

Thanks, champs.

Antony

Can anybody help here? Please?

normal_rng will return a scalar value when the arguments (mean, sd) are scalars.

Solutions include:

  • using a loop to call normal_rng(0, 2) for each element
  • passing vectors as arguments to normal_rng

For more info check out this thread: Applying Vectorization in generated quantities section

1 Like

Thanks for responding. I appreciate it.