functions { int poisson_log_safe_rng(real eta) { real pois_rate = exp(eta); if (pois_rate >= exp(20.79)) return -9; return poisson_rng(pois_rate); } } data { int N; int complaints[N]; vector[N] traps; vector[N] super; //vector[N] log_sqfoot; // exposure term vector[N] sqfoot; // exposure term } transformed data{ vector[N] log_sqfoot=log(sqfoot); } parameters { real alpha; real beta1; real beta2; } model { alpha ~ normal(log(4), 1); beta1 ~ normal(-0.25, 1); beta2 ~ normal(-0.5, 1); complaints ~ poisson_log(alpha + beta1 * traps + beta2 * super + log_sqfoot); } generated quantities { int y_rep[N]; for (n in 1:N) y_rep[n] = poisson_log_safe_rng(alpha + beta1 * traps[n] + beta2 * super[n] + log_sqfoot[n]); }