I am given a zip-inflated Poisson (ZIP) model, where random data $ X_1, .., X_n$ are of the form $ X_i=R_iY_i$ , where the $ Y_i$ ‘s have Poisson distribution ($ \lambda$ ) and the $ R_i$ ‘s have Bernoulli distribution ($ p$ ), and all independent from each other. If given an outcome $ x = (x_1, .., x_n)$ , the objective is to estimate both $ \lambda$ and $ p$ .

We can use a hierarchical Bayes model:

$ p$ ~ Uniform(0,1) (prior for $ p$ ),

$ (\lambda|p)$ ~ Gamma(a,b) (prior for $ \lambda$ ),

$ (r_i|p, \lambda )$ ~ Bernoulli($ p$ ) independently (from the model above),

$ (x_i|r, \lambda, p )$ ~ Poisson($ \lambda r_i$ ) independently (from the model above)

Since $ a$ and $ b$ are known parameters, and $ r = (r_1,…,r_n)$ , it follows that

$ f(x,r, \lambda, p) = \frac{b^\alpha \lambda^{\alpha-1} e^{-b \lambda}}{\Gamma(\alpha)} \prod_{i=1}^n\frac{e^{-\lambda r_i} (\lambda r_i)^{x_i}}{x_i!} p^{r_i}(1-p)^{1-r_i}$

My question is to obtain the following:

1) $ \lambda|p,r,x\sim Gamma(a+ \sum_{i}x_i, b+ \sum_{i}r_i)$

2) $ p|\lambda,r,x\sim Beta(1+ \sum_{i}r_i, n+1 – \sum_{i}r_i)$

3) $ r_i|\lambda,p,x \sim Bernoulli(\frac{pe^{- \lambda}}{pe^{- \lambda}+(1-p)I{\{x_i=0}\}})$

for 1) and 2), I am able to deduce them by integrating and removing the other variables. However, for 3), I was not able to do so and eventually obtained the following expression:

$ e^{\lambda \sum r_i} r_i^{\sum x_i} p^{\sum r_i} (1-p)^{n-\sum r_i}$

Can anyone show me if what I did it correct and perhaps how to obtain the required expression?

Thank you.