I use my JAGS model, and then use that model to make predictions, propogating parameter uncertainty into those predictions. I currently have a zero-inflated Poisson (ZIP) model that runs fine making a single prediction. It looks like this:
j.model ="
model{
for (i in 1:N){
#this fits the blended model to your data.
y[i] ~ dpois(m[i]*t[i])
#This blends the poisson and zero inflation models
m[i] <- mu[i]*x[i] + 0.00001
#this is the bernoulli outcome of the zero inflation
x[i] ~ dbern(pro[i])
#this logit transforms the theta model for 0-1 probability of zero inflation
logit(pro[i]) <- theta[i]
#mu[i] is predictors for poisson model- log link function.
log(mu[i]) <- int.p + x1[i]*b1.p + x2[i]*b2.p + x3[i]*b3.p + x4[i]*b4.p + x5[i]*b5.p
#theta[i] is predictors for zero inflation
theta[i] <- int.z + x1[i]*b1.z + x2[i]*b2.z + x3[i]*b3.z + x4[i]*b4.z + x5[i]*b5.z
}
#predictions
#This gets the range of pred.m blended model values, before they get sent through the poisson distribution, and corrected for time.
#x5 prediction
for (i in 1:N.pred){
x5.pred[i] <- pred5.mu[i]*pred5.x[i] + 0.00001
pred5.x[i] ~ dbern(pred5.pro[i])
logit(pred5.pro[i]) <- pred5.theta[i]
log(pred5.mu[i]) <- int.p + x1.m*b1.p + x2.m*b2.p + x3.m*b3.p + x4.m*b4.p + x5.r[i]*b5.p
pred5.theta[i] <- int.z + x1.m*b1.z + x2.m*b2.z + x3.m*b3.z + x4.m*b4.z + x5.r[i]*b5.z
}
#priors
b1.p ~ dnorm(0, .0001)
b2.p ~ dnorm(0, .0001)
b3.p ~ dnorm(0, .0001)
b4.p ~ dnorm(0, .0001)
b5.p ~ dnorm(0, .0001)
b1.z ~ dnorm(0, .0001)
b2.z ~ dnorm(0, .0001)
b3.z ~ dnorm(0, .0001)
b4.z ~ dnorm(0, .0001)
b5.z ~ dnorm(0, .0001)
int.p ~ dnorm(0, .0001)
int.z ~ dnorm(0, .0001)
}
"
However, if I insert a second prediction loop into this model for predictor x4
I get an error. The second prediction loops looks like this, and is inserted between the model
loop and the x5
prediction loop.
#x4 prediction
for (i in 1:N.pred){
map.pred[i] <- pred4.mu[i]*pred4.x[i] + 0.00001
pred4.x[i] ~ dbern(pred4.pro[i])
logit(pred4.pro[i]) <- pred4.theta[i]
log(pred4.mu[i]) <- int.p + x1.m*b1.p + x2.m*b2.p + x3.m*b3.p + x4.r[i]*b4.p + x5.m*b5.p
pred4.theta[i] <- int.z + x1.m*b1.z + x2.m*b2.z + x3.m*b3.z + x4.r[i]*b4.z + x5.m*b5.z
}
It returns this error:
RUNTIME ERROR:
Compilation error on line 20.
Unable to resolve node pred4.mu[1]
This may be due to an undefined ancestor node or a directed cycle in the graph
This surprises me, as this prediction loop is formatted exactly the same as the x5
prediction loop, so I know everything should be defined, as it worked great before. Is there something about having two of these that is causing the problem?