I have several parameters and do not wish to manually specify initial values for n=3 chains. I am wondering whether RJAGS will give different initial values for each chain. The manual for JAGS says that the same initial value is used for each chain however when I tried to get some samples without any adaptation the initial values seem to be different. Thanks.
It looks like jags.model()
will use the same initial values if you don't provide them. The samples will differ from each other because of the randomness inherent in the MCMC sampling, so that is not an indication of different initial values being used. You can use the state()
function to see the state of your model after initialization, which will give all of the initial values. Here's a simple example. When we don't provide initial values for mu
, they are both 0.
jd <- list(x = runif(100))
jm <- "
model{
for(i in 1:100){
x[i] ~ dnorm(mu, 1)
}
mu ~ dnorm(0,3)
}
"
cat(jm, file="tmp.mod")
jm <- jags.model("tmp.mod", data=jd, n.chains=2)
jm$state()
# [[1]]
# [[1]]$mu
# [1] 0
#
#
# [[2]]
# [[2]]$mu
# [1] 0
When we provide initial values, the state()
function identifies that they are in fact the ones we provided.
jm2 <- jags.model("tmp.mod",
data=jd,
n.chains=2,
inits = list(list(mu=2), list(mu=-2)))
jm2$state()
# [[1]]
# [[1]]$mu
# [1] 2
#
#
# [[2]]
# [[2]]$mu
# [1] -2