Winbug错误使用了未定义的节点d

时间:2016-11-23 13:20:01

标签: compilation winbugs

我试图用自己的数据编辑下载的网络元分析模型,它运行正常,直到我在加载数据后编译模型。 Winbugs警告说"使用了未定义的节点d"。我试着解决它,但我失败了。请帮我。该模型和我的数据显示如下。

# Binomial likelihood, logit link, inconsistency model
# Random effects model
model{                      # *** PROGRAM STARTS
for(i in 1:ns){             # LOOP THROUGH STUDIES
    delta[i,1]<-0           # treatment effect is zero in control arm
    mu[i] ~ dnorm(0,.0001)  # vague priors for trial baselines
    for (k in 1:na[i])  {   # LOOP THROUGH ARMS
        r[i,k] ~ dbin(p[i,k],n[i,k]) # binomial likelihood
        logit(p[i,k]) <- mu[i] + delta[i,k]  # model for linear predictor
#Deviance contribution
        rhat[i,k] <- p[i,k] * n[i,k] # expected value of the numerators 
        dev[i,k] <- 2 * (r[i,k] * (log(r[i,k])-log(rhat[i,k]))  
          +  (n[i,k]-r[i,k]) * (log(n[i,k]-r[i,k]) - log(n[i,k]-rhat[i,k])))   
      }
# summed residual deviance contribution for this trial
   resdev[i] <- sum(dev[i,1:na[i]])
   for (k in 2:na[i]) {  # LOOP THROUGH ARMS
# trial-specific LOR distributions
        delta[i,k] ~ dnorm(d[t[i,1],t[i,k]] ,tau) 
      }
  }   
totresdev <- sum(resdev[])   # Total Residual Deviance
for (c in 1:(nt-1)) {  # priors for all mean treatment effects
    for (k in (c+1):nt)  { d[c,k] ~ dnorm(0,.0001) } 
  }  
sd ~ dunif(0,5)  # vague prior for between-trial standard deviation
var <- pow(sd,2) # between-trial variance
tau <- 1/var     # between-trial precision
} # *** PROGRAM ENDS


# ns= number of studies; nt=number of treatments
list(nt=13,ns=17)   
t[,1]   t[,2]   t[,3]   t[,4]   r[,1]   r[,2]   r[,3]   r[,4]   n[,1]   n[,2]   n[,3]   n[,4]   na[]    #   study
9   3   7   11  9   8   6   7   20  16  14  15  4   #   1
9   7   8   NA  117 83  122 NA  229 231 247 NA  3   #   2
9   3   NA  NA  8   3   NA  NA  18  13  NA  NA  2   #   3
9   5   NA  NA  13  16  NA  NA  20  20  NA  NA  2   #   4
9   1   2   NA  105 103 165 NA  226 228 227 NA  3   #   5
9   2   13  NA  30  67  52  NA  96  200 195 NA  3   #   6
9   6   NA  NA  7   7   NA  NA  17  18  NA  NA  2   #   7
7   12  NA  NA  5   2   NA  NA  14  12  NA  NA  2   #   8
9   7   8   12  14  8   12  8   24  23  21  26  4   #   9
9   8   NA  NA  5   12  NA  NA  30  34  NA  NA  2   #   10
9   10  NA  NA  3   10  NA  NA  25  25  NA  NA  2   #   11
9   3   4   11  12  8   17  8   22  24  25  26  4   #   12
9   8   NA  NA  8   17  NA  NA  21  24  NA  NA  2   #   13
1   7   NA  NA  9   4   NA  NA  15  15  NA  NA  2   #   14
9   1   NA  NA  8   1   NA  NA  30  29  NA  NA  2   #   15
9   3   11  NA  3   5   0   NA  21  23  8   NA  3   #   16
9   8   NA  NA  13  15  NA  NA  19  16  NA  NA  2   #   17





END
list(d=c( NA, 0,0,0,0,0,0,0,0,0,0,0,0), sd=1)

1 个答案:

答案 0 :(得分:0)

我在尝试运行不一致模型时遇到了同样的问题,起初它真的很烦人,因为很难发现问题出在哪里。实际上,如果你查看WinBUGS代码的第三个块,你没有为某些节点定义先验,例如d [9,1],d [9,2] ... d [9,8];这就是错误消息不断弹出的原因。

解决这个问题很简单。在不一致模型中,t [,1]应始终低于t [,2],t [,2]应始终低于t [,3],依此类推。

我希望它有所帮助...