12

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?

mpiktas
  • 33,140
  • 5
  • 82
  • 138
George Michaelides
  • 1,039
  • 1
  • 9
  • 19
  • This may be helpful: [Bayesian models for categorical data By P. Congdon](http://books.google.com/books?id=rzTegn21i58C&lpg=PA167&dq=congdon%20zero-inflated%20model&pg=PA167#v=onepage&q&f=false) – user4618 Nov 08 '11 at 04:34

2 Answers2

4
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
random_user
  • 760
  • 1
  • 5
  • 20
3

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 + ....
  }
nassimhddd
  • 363
  • 1
  • 10