3

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)
Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
Sam
  • 4,357
  • 6
  • 36
  • 60
  • 1
    I don't know if this affects your problem, but as a long term solution, you might want to consider moving to JAGS (or possibly even Stan). See this [blog](http://geospaced.blogspot.com/2013/04/why-you-should-not-use-winbugs-or.html) and this question on [CV](http://stats.stackexchange.com/questions/9202/openbugs-vs-jags). – Richard Erickson Aug 10 '15 at 16:24
  • 1
    Thanks @RichardErickson. I'll look into the blog and as you suggested, I may soon start using JAGS and Stan. However, my main priority is to firsts figure out why my code above does not work. Any help is very much appreciated. Thanks again for your comment – Sam Aug 11 '15 at 16:39
  • 1
    You're welcome. Another resource you might check out is the [OpenBugs](http://mathstat.helsinki.fi/openbugs/community/CommBBSFrames.html) mailing list. I've never used it (and don't know how active the list is), but you might try posting your question there if you don't get a response here in a few days. – Richard Erickson Aug 11 '15 at 16:45
  • 1
    Awesome. Thanks very much @RichardErickson. Just sent an email to the mailing list. – Sam Aug 11 '15 at 18:39

0 Answers0