Hi,
Before trying to understand what is wrong with the code (unfortunately we don't have to provide better help) I always check the possibility of not needing the ZIP and use the Poisson. The key point is that marginally excess of zeroes does not always require ZIP.
There are several ways to compare goodness-of-fit. I prefer to consider the negated sum of the log CPO.
See the simple Poisson regression example bellow
library(INLA)
set.seed(1)
n <- 30
dataset <- list(x = rexp(n, 1))
dataset$y <- rpois(n, exp(1 -x))
table(dataset$y)
n*dpois(0:5, mean(dataset$y)) ### if iid
result1 <- inla(y ~ x, 'poisson',
data=dataset,
control.compute=list(cpo=TRUE))
result2 <- inla(y ~ x, 'zeroinflatedpoisson0',
data=dataset,
control.compute=list(cpo=TRUE))
result3 <- inla(y ~ x, 'zeroinflatedpoisson1',
data=dataset,
control.compute=list(cpo=TRUE))
### check if fail
c(sum(result1$cpo$fail>0),
sum(result2$cpo$fail>0),
sum(result3$cpo$fail>0))
### negated sum of CPO
c(-sum(log(result1$cpo$cpo)),
-sum(log(result2$cpo$cpo)),
-sum(log(result3$cpo$cpo)))
Elias