Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
This may be helpful: Bayesian models for categorical data By P. Congdon – user4618 Nov 8 '11 at 4:34
up vote 2 down vote accepted

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 + ....
share|improve this answer
C <- 10000 #Constant 1/0 trick

# Likelihood:
for ( i in 1:ny ) {

#Likelihood of the count model component
LikCountModel[i] <- pow(mu[i],y[i])/y_fact[i]*exp(-mu[i])

#Count model component
eta[i] <- bet0 + inprod( beta[] , B[i,] )
mu[i] <- exp(eta[i])

#ZI Component
zeta[i] <- gamm0 + inprod( gamma[] , G[i,] )
w[i] <- exp(zeta[i])/(1+exp(zeta[i]))

#1/0 Tricks: ones is a column containing only ones, with the same size of y
  p[i] <- L[i] / C
  ones[i] ~ dbern(p[i])

#Full likelihood expression
L[i] <- LikCountModel[i] * (1-w[i]) + equals(y[i],0)*w[i]

#then set your priors for all beta and gamma
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.