This question is a follow-up to my previous question. The following stan code is a minimum reproducible example of the problem that I am encountering:
data{
int<lower=0> N;
int<lower=0> offset[N];
int<lower=0> y[N];
int<lower=0> pred_N;
int<lower=0> pred_offset[pred_N];
}
parameters {
real alpha_poisson ;
}
model{
alpha_poisson ~ normal(0,1) ;
for(n in 1:N) target += poisson_log_lpmf(y[n] | alpha_poisson + log(offset[n]));
}
generated quantities {
int<lower=0> y_sim[N] ;
int<lower=0> y_pred[N] ;
for(n in 1:N){
if(alpha_poisson + log(offset[n])<20.7944)
y_sim[n]=poisson_log_rng(alpha_poisson + log(offset[n]));
else
y_sim[n]=999999;
}
for(n in 1:pred_N){
if(alpha_poisson + log(pred_offset[n])<20.7944)
y_pred[n]=poisson_log_rng(alpha_poisson + log(pred_offset[n]));
else
y_pred[n]=999999;
}
}
When I run this I get the following error:
Chain 1: Exception: model2130306f11b_poisson_namespace::write_array: y_pred[k0__] is -2147483648, but must be greater than or equal to 0 (in 'model2130306f11b_poisson' at line 21)
Am I doing something wrong or is this a bug in the random number generator?
Thanks a lot for the help!