1

我使用我的 JAGS 模型,然后使用该模型进行预测,将参数不确定性传播到这些预测中。我目前有一个零膨胀泊松 (ZIP) 模型,它可以很好地进行单一预测。它看起来像这样:

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)
}
"

但是,如果我在这个模型中插入第二个预测循环作为预测器,x4我会得到一个错误。第二个预测循环看起来像这样,并插入到model循环和x5预测循环之间。

#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 
}

它返回此错误:

  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

这让我感到惊讶,因为这个预测循环的格式与预测循环完全相同x5,所以我知道应该定义所有内容,因为它以前工作得很好。有两个导致问题的原因吗?

4

0 回答 0