# Generate data from prior

Hi all,
I am trying to understand how “fake” data can be generated from priors and to check if the generated dataset is similar to observed data - this is prior predictive check right? So I have used the following simple regression model as an example.

``````parameters{
real alpha;
real beta;
real<lower=0> sigma;
}
model {
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
sigma ~ normal(0, 1);
}
generated quantities {
real y[10];
real x[10];
for (n in 1:10) {
x[n] = normal_rng(0, 1);
y[n] = normal_rng(alpha * x[n] + beta, sigma);
}
}
``````

I would like to know if the above method for generating data is correct. Or would i need to generate data within mode{} section as below? Which method is correct? After generating data, I would like to use it to check my model too.

``````data{
real x[10]
}
parameters{
real alpha;
real beta;
real<lower=0> sigma;
real y[10];
}
model {
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
sigma ~ normal(0, 1);
y~ normal(alpha * x+ beta, sigma);
}

``````

Thanks

The first is closer to correct, but you would pass `x` into the `data` block rather than drawing it from a distribution in the generated quantities block, unless you intend to model `x` in your ultimate model.

Thanks @bgoodri. That cleared my doubts.

I’m encountering the similar problem as you met, still don’t know how it works.
Can you post the whole code after revising?

This would be the corrected model, with a couple of amendments (use of `vector` and `std_normal`):

``````data{
vector[10] x;
}
parameters{
real alpha;
real beta;
real<lower=0> sigma;
}
model {
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
sigma ~ std_normal();
}
generated quantities {
vector[10] y;
for (n in 1:10) {
y[n] = normal_rng(alpha * x[n] + beta, sigma);
}
}
``````

thanks!