3

我已经编写了一个 Weibull 生存代码,OpenBUGS使用. 经过数小时的调试,我仍然收到以下错误:R2OpenBUGSR

节点的这个组件不是随机的 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)
4

0 回答 0