我的OpenBUGS代码中的奇怪错误(使用R2OpenBUGS)

时间:2015-08-10 16:13:22

标签: r bayesian openbugs

我使用OpenBUGS中的R2OpenBUGS包在R中编写了一个Weibull生存代码。经过几个小时的调试,我仍然得到以下错误:

  

节点的这个组件不是随机的Beta0 [1]错误pos 30

     

节点的这个组件不是随机的Beta0 [1]错误pos 31

     

节点的这个组件不是随机的Beta0 [1]错误pos 30

     

节点算法更新错误切片更新程序错误无法对节点进行过多的迭代采样

     当采样器处于自适应阶段时,无法进行推理

这是我的完整代码以及初始值:

#--------------
# Model Code --
#--------------
linemodel <- function(){
  for(i in 1:N){ 
    for (j in 1:M){
      weibSamp[i,j] ~ dweib(tau, gamma[i]) %_% I(weibCens[i,j],)
    }
    gamma[i] <- exp(Beta0[i] + Beta1*X[i])
    S[i] ~ dcat(pi[])
    Beta0[i] <- Beta0Pool[S[i]]
    for (j in 1:C){
      SC[i,j] <- equals(j, S[i])
    }
  }
  # Precision Parameter for DP:
  alpha ~ dgamma(0.1, 0.1)

  # Let's construct the DP:
  p[1] <- r[1]
  for (j in 2:C){
    p[j] <- r[j]*(1 - r[j - 1])*p[j-1]/r[j-1]
  }
  p.sum <- sum(p[])
  for (j in 1:C){
    Beta0Pool[j] ~ dnorm(A, B)
    r[j] ~ dbeta(1, alpha)
    # scaling to ensure p sums to 1
    pi[j] <- p[j]/p.sum
  }

  # Hyper priors A and B inside of DP (for G0)
  A ~ dnorm(0, 0.01)
  B ~ dgamma(0.1, 0.1)

  # Total number of clusters:
  K <- sum(cl[])
  for (j in 1:C){
   sumSC[j] <- sum(SC[,j])
    cl[j] <- step(sumSC[j] - 1)
  }
  tau ~ dexp(0.001)
  Beta1 ~ dnorm(0, 0.01)
}

#---------------
# Initializing -
#---------------
lineinits <- function(){
  list(tau = runif(1, 0.1, 3), Beta0 = rnorm(N, 0, 2), Beta1 = rnorm(1, 0,
       2), alpha = 2, A = 0, B = 2)
}

#------------------------------------
# Time to get OpenBUGS run the code -
#------------------------------------
library(coda)
lineout <- bugs(data, lineinits, c("tau", "Beta0", "Beta1"), linemodel, 
            n.iter = 1000, n.burnin = 200, n.thin = 1, codaPkg = T, 
            debug = T)

0 个答案:

没有答案