I came across Implementing Consul’s generalized Poisson distribution in Stan – James E. Pustejovsky, which implements generalized Poisson. I need to analyze count data. However, due to equipment limits, the data will be right-censored. According to the responses we’ve seen in past experiments, the data may be right-censored. I have been trying to start from Pustejovsky’s implementation, but I lack the skill to incorporate right censoring or zero inflation alone, and certainly not both.
How could I proceed?
I’m not sure what brms implements as far as censoring and inflation. Mathematically, the two are independent. The zero inflation is a spike of probability mass at zero—it’s mathematically treated like a mixture model. The right censoring is something where the censored observations increment the likelihood with the complementary cumulative distribution function (i.e, one minus the cdf, or the probability that the value is greater than the censoring point, being careful to include or not include the censoring point itself depending on how the censoring is reported).
So if you have a random variable X \sim p_X(x). You can think of censoring as a transform
Y = \begin{cases} X & \text{if } X < \tau \\ \tau & \text{otherwise} \end{cases}
If F_X(x) = \Pr[x \leq X] = \int_{-\infty}^x p_X(x) \, \text{d}x, is the cdf then
p_Y(y) = \begin{cases} p_X(x) & \text{if } x < \tau \\ 1 - F_X(\tau) & \text{otherwise} \end{cases}
and you can code it in Stan usut like this. The function \log(1 - F_X(\tau)) is just poisson_lcddf(tau | ...)
and \log p_X(x) is just poisson_lpmf(x | ...)
.
The zero inflation is just a mixture. We now get a new B \sim \text{bernoulli}(\lambda) for some inflation \lambda \in (0, 1) variable
Z = \begin{cases} 0 & \text{if } B = 1 \\ Y & \text{otherwise} \end{cases}
That gives us the following density for Z,
p_Z(z) = \begin{cases} \lambda + (1 - \lambda) \cdot p_Y(0) & \text{if } z = 0 \\ (1 - \lambda) \cdot p_Y(z) & \text{otherwise} \end{cases}
In Stan, the log_mix
function implements two-component mixtures like this.