I want to perform a prior predictive check but have troubles with what I think is fairly easy model. I am confused why it does not work in stan, since I have successfully implemented the same prior predictive sampling procedure in R without any problems.

My stan code is the following:

```
data {
vector[2] mu;
vector<lower = 0>[2] prev_beta;
cov_matrix[2] Sigma;
int<lower=0> n;
}
model{
// empty model block
}
generated quantities {
vector[2] logit_Se_Sp;
real<lower=0, upper=1> prev;
int<lower=0,upper=n> y;
real<lower=0,upper=1> Se = inv_logit(logit_Se_Sp[1]);
real<lower=0,upper=1> Sp = inv_logit(logit_Se_Sp[2]);
real<lower=0,upper=1> p = prev*Se + (1-prev)*(1-Sp);
logit_Se_Sp = multi_normal_rng(mu, Sigma);
prev = beta_rng(prev_beta[1],prev_beta[2]);
y = binomial_rng(n, p);
}
```

I use rstan to pass the priors:

```
sampling(prior_predictive_model, data=list(n=1000, mu=c(3,3), Sigma=matrix(c(1,0,0,1), nrow=2), prev_beta=c(1,1)), chains=4, iter=2000, refresh=500, cores=4, algorithm="Fixed_param")
```

The error message that I receive:

```
Exception: binomial_rng: Probability parameter is nan, but must be in the interval [0, 1]
```

I cannot make sense of this error message because as I read the code, all the parameters are correctly constrained. Any advice is highly appreciated.