As part of a prior predictive simulation, I would like to use Stan to generate values from a hurdle model, i.e. a Bernoulli trial to predict whether the outcome is 0 and a truncated Poisson for outcomes >= 1.
Does anyone have advice on how I can invert the Poisson CDF similar to R’s qpois
function? The examples in the manual are for continuous functions where there’s a sensible analytical solution.
functions {
int poisson_trunc_rng(real lambda) {
real p = poisson_cdf(0, lambda);
real u = uniform_rng(p, 1);
// In R, the following line would be
int y = qpois(u, lambda);
return y;
}
}```