PepsiCo
PepsiCo

Reputation: 1409

What's wrong with this WinBUGS model

I used Winbugs from R via R2WinBUGS and BRugs package, I write the model and try to run it, but the result didn't come out, and I read the WinBUGS log, seems nothing got wrong. Here is the model:

require(BRugs)
require(R2WinBUGS)
#  MCMC mosel
model<-function(){
  for(i in 1:M){
    y[i] ~ dnorm(x[i], sigma.y)
  }
  x[1] ~ dnorm(theta[1], sigma.x)
  theta[1] <- 0
  for(j in 2:M){
    x[j] ~ dnorm(theta[j], sigma.x)
    theta[j] <- a + b*x[j-1]
  }
  a ~ dunif(0, 1)
  b ~ dunif(-1, 1)
  tau.y ~ dgamma(0.1, 0.1)
  tau.x ~ dgamma(0.1, 0.1)
  sigma.y <- 1/sqrt(tau.y)
  sigma.x <- 1/sqrt(tau.x)
}

write.model(model, con = "model.bug")
modelCheck("model.bug")
#  model is syntactically correct

data=list(M = 90, y = rnorm(90)

inits = function(){
  list(tau.x = rgamma(1, 0.1, 0.1), tau.y = rgamma(1, 0.1, 0.1), a = runif(0, 1), b = runif(-1, 1))
}
parameters=c("a", "b", "x")

ret.sim <- bugs(data, inits, parameters, "model.bug",
            n.chains = 1, n.iter = 1000,
            n.sims = 500,
            program= "winbugs",
            working.directory = NULL,
            debug = T)

model check is passed, and the log of WinBUGS is here:

display(log)
check(C:/Users/ADMINI~1.PC-/AppData/Local/Temp/Rtmp2LfZTu/model.bug.txt)
model is syntactically correct
data(C:/Users/ADMINI~1.PC-/AppData/Local/Temp/Rtmp2LfZTu/data.txt)
data loaded
compile(1)
model compiled
inits(1,C:/Users/ADMINI~1.PC-/AppData/Local/Temp/Rtmp2LfZTu/inits1.txt)
this chain contains uninitialized variables
gen.inits()
initial values generated, model initialized
thin.updater(1)
update(500)

The WinBUGS didn't go on, and no wrong messages are displayed, so I cann't find anything wrong.

Upvotes: 4

Views: 920

Answers (1)

Tomas
Tomas

Reputation: 59535

This error message is clearly about initial values. Try to run runif(-1, 1) on the R console and you will see :-) You meant runif(1, -1, 1) (and also runif(1, 0, 1) for the previous one.

Good luck!

Upvotes: 1

Related Questions