Hi all.
I am new to NIMBLE, and I am trying unsuccessfully to set different deterministic initial values for each chain. The help file for runMCMC states that the inits argument can be "a list of length nchains, each element being a named list of initial values which be used for one MCMC chain." However, NIMBLE appears to only use the first list of initial values I give it. In the following example, I ask for two chains, in each of two different runs. In the first run, I ask for two different sets of initial values:
inits = list(inits1=I1, inits2=I1).
I get identical chains in both runs.
I will reprint the code below from the run where I ask for different initial values, and I will reprint the output I get regardless of the run.
set.seed(10120)
myData <- rgamma(1000, shape = 0.4, rate = 0.8)
myCode <- nimbleCode({
a ~ dunif(0, 100)
b ~ dnorm(0, 100)
for (i in 1:length_y) {
y[i] ~ dgamma(shape = a, rate = b)
}
})
I1 <- list(a=0.3,b=0.9)
I2 <- list(a=0.5, b=0.7)
myModel <- nimbleModel(code = myCode,
data = list(y = myData),
constants = list(length_y = 1000),
inits = list(inits1=I1, inits2=I2))
CmyModel <- compileNimble(myModel)
myMCMC <- buildMCMC(CmyModel)
CmyMCMC <- compileNimble(myMCMC)
results <- runMCMC(CmyMCMC, niter = 10, setSeed = c(1,1), nchains=2)
cbind(as.numeric(results[[1]][,"a"]),as.numeric(results[[2]][,"a"]),as.numeric(results[[1]][,"b"]),as.numeric(results[[2]][,"b"]))
# a1 a2 b1 b2
# [1,] 0.3 0.3 0.9000000 0.6052796
# [2,] 0.3 0.3 0.9000000 0.6052796
# [3,] 0.3 0.3 0.6052796 0.6052796
# [4,] 0.3 0.3 0.6052796 0.6052796
# [5,] 0.3 0.3 0.6052796 0.6052796
# [6,] 0.3 0.3 0.6052796 0.6052796
# [7,] 0.3 0.3 0.6052796 0.6052796
# [8,] 0.3 0.3 0.6052796 0.6052796
# [9,] 0.3 0.3 0.6052796 0.6052796
# [10,] 0.3 0.3 0.6052796 0.6052796
If anyone can offer me some advice, I'd very much appreciate it. Once I figure out how to do this with sequential chains, I hope to do it with parallel chains. (I can get everything else to work in parallel.)
Thank you!!
Rebecca