Solved – How to set up a zero-inflated poisson in JAGS

jagspoisson distributionrzero inflation

I am trying to set up a zero-inflated poisson model in R and JAGS. I am new to JAGS and I need some guidance on how to do that.

I've been trying with the following where y[i] is the observed variable

model {
for (i in 1:I) {

    y.null[i] <- 0
    y.pois[i] ~ dpois(mu[i])
    pro[i] <- ilogit(theta[i])
    x[i] ~ dbern(pro[i])

    y[i] <- step(2*x[i]-1)*y.pois[i] + (1-step(2*x[i]-1))*y.null[i]

    log(mu[i]) <- bla + bla +bla + ....
    theta[i] <- bla + bla + bla + ....
}

}

However this does not work as you cannot use <- on an observed variable.

Any ideas how to change/fix this? Is there an other way to set up the zero-inflated poisson model in JAGS?

Best Answer

Here is a simple solution using the fact that the poisson will give you zeros when the lambda parameter is zero. Note however that JAGS tends to break if lambda is exactly zero, thus the "+ 0.00001".

model {
  for (i in 1:I) {

    y[i] ~ dpois(mu1[i])

    mu1[i] <- mu[i]*x[i] + 0.00001

    x[i] ~ dbern(pro[i])
    logit(pro[i]) <- theta[i]

    mu[i] <- bla + bla +bla + ....
    theta[i] <- bla + bla + bla + ....
  }
Related Question