Strange Errors in my OpenBUGS code (using R2OpenBUGS)

1.9k views Asked by At

I've written a Weibull survival code in OpenBUGS using the R2OpenBUGS package in R. After hours of debugging, I still get the errors below:

this component of node is not stochastic Beta0[1] error pos 30

this component of node is not stochastic Beta0[1] error pos 31

this component of node is not stochastic Beta0[1] error pos 30

update error for node algorithm slice updater error can not sample node too many iterations

inference can not be made when sampler is in adaptive phase

Here is my full code along with the initial values:

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

There are 0 answers