diff --git a/inst/stan/functions/observation_model.stan b/inst/stan/functions/observation_model.stan index 8c6fb594d..3c6f450f5 100644 --- a/inst/stan/functions/observation_model.stan +++ b/inst/stan/functions/observation_model.stan @@ -110,11 +110,15 @@ int[] report_rng(vector reports, real[] rep_phi, int model_type) { } for (s in 1:t) { - // defer to poisson if phi is large, to avoid overflow - if (sqrt_phi > 1e4) { - sampled_reports[s] = poisson_rng(reports[s] > 1e8 ? 1e8 : reports[s]); + if (reports[s] < 1e-8) { + sampled_reports[s] = 0; } else { - sampled_reports[s] = neg_binomial_2_rng(reports[s] > 1e8 ? 1e8 : reports[s], sqrt_phi); + // defer to poisson if phi is large, to avoid overflow + if (sqrt_phi > 1e4) { + sampled_reports[s] = poisson_rng(reports[s] > 1e8 ? 1e8 : reports[s]); + } else { + sampled_reports[s] = neg_binomial_2_rng(reports[s] > 1e8 ? 1e8 : reports[s], sqrt_phi); + } } } return(sampled_reports);