# Prior predictive check

**URL:** <https://discourse.mc-stan.org/t/prior-predictive-check/24052>\
**Category:** Modeling\
**Tags:** specification\
**Created:** [August 20, 2021, 9:09am UTC](https://discourse.mc-stan.org/t/prior-predictive-check/24052 "2021-08-20T09:09:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ants007](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ants007](https://discourse.mc-stan.org/u/ants007)\
**Post date:** [August 20, 2021, 9:09am UTC](https://discourse.mc-stan.org/t/prior-predictive-check/24052/1 "2021-08-20T09:09:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ants007](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ants007](https://discourse.mc-stan.org/u/ants007)\
**Post date:** [August 25, 2021, 8:09am UTC](https://discourse.mc-stan.org/t/prior-predictive-check/24052/2 "2021-08-25T08:09:44Z")

</div>

Can anybody help here? Please?

---

<div class="post-metadata">

**Author:** ![mbjoseph](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mbjoseph/32/870_2.png) [@mbjoseph](https://discourse.mc-stan.org/u/mbjoseph)\
**Post date:** [August 25, 2021, 5:54pm UTC](https://discourse.mc-stan.org/t/prior-predictive-check/24052/3 "2021-08-25T17:54:58Z")

</div>

`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](https://discourse.mc-stan.org/t/applying-vectorization-in-generated-quantities-section/13769)

---

<div class="post-metadata">

**Author:** ![ants007](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ants007](https://discourse.mc-stan.org/u/ants007)\
**Post date:** [August 26, 2021, 1:41am UTC](https://discourse.mc-stan.org/t/prior-predictive-check/24052/4 "2021-08-26T01:41:13Z")

</div>

Thanks for responding. I appreciate it.
