Using log_mix in Zero-inflated poisson model

For a zero-inflated model Poisson model, if you observe y=0, then the likelihood is a mixture:
\begin{align*} \text{Pr} (0 | p, \lambda) & = \text{Pr} (\text{Zero generating process} | p) * (1) + \text{Pr} (\text{Other Process} | p) \times \text{Pr} (0 | \lambda) \\ & = p + (1 - p) \text{ exp} (- \lambda) \end{align*}


My understanding is that the probability of observing 0, given that you are in the state that produces zero’s only, is equal to 1. So would use the following code for this term:

...
if ( y[i] == 0 ) target += log_mix(p, 1, poisson_lpmf(0 | lambda));
...

Why is it then that for any online resource I can find (including for example this Stan workshop) this term is coded as:

if ( y[i] == 0 ) target += log_mix(p, 0, poisson_lpmf(0 | lambda));

I.e. using zero instead of 1 for the second argument in log_mix? I was wondering if my understanding of the log_mix was incorrect, because the latter implies:

\begin{align*} \text{Pr} (0 | p, \lambda) & = \text{Pr} (\text{Zero generating process} | p) * (0) + \text{Pr} (\text{Other Process} | p) \times \text{Pr} (0 | \lambda) \\ & = (1 - p) \text{ exp} (- \lambda) \end{align*}

Which I think is incorrect. Can anyone explain what am I missing here?

I think I know, but would like to get confirmation on this. Is it because you specify the log of the probability in the arguments of log_mix? Seems like it.

1 Like

The calculations are done on the log scale, so \log(1) = 0. It could also have been more didactically written as:

log_sum_exp(log(p) + log(1), 
            log1m(p) + poisson_lpmf(0 | lambda)
          )

or (most clear for me)

log_sum_exp(bernoulli(1 | p), 
            bernoulli(0 | p) + poisson_lpmf(0 | lambda)
          )