If you are running the model in parallel you cannot track dic
or ped
. The reason for this is that the extend.jags
function requires "...multiple chains WITHIN the same simulation" (emphasis added, see help file and look up the monitor
arguments for the extend.jags
function). When running in parallel you only have a single chain per core.
However, you can collect these AFTER you have fit the model with the extract
function. Here is a reproducible example of a simple JAGS model to illustrate how to do this.
library(runjags)
# generate data
y <- rnorm(1000, 3, 10)
# the model
modelstring="
model{
mu ~ dnorm(0, 0.001)
tau ~ dgamma(0.001,0.001)
sigma <- 1 / sqrt(tau)
for(i in 1:1000){
y[i] ~ dnorm(mu, tau)
}
}
"
# save this model string in your working directory
fileconn <- file("simple_norm.R")
writeLines(modelstring, fileconn)
close(fileconn)
# fit the model
model = run.jags(model = "simple_norm.R",
data = data_list,
monitor = c("mu", "sigma"),
n.chains = 3,
burnin = 1000,
sample = 5000,
method = "rjparallel"
)
# collect DIC and ped
my_dic <- extract(model, what = "dic")
my_ped <- extract(model, what = "ped")
# the output
> my_dic
Mean deviance: 7411
penalty 1.979
Penalized deviance: 7413
> my_ped
Mean deviance: 7411
penalty 3.961
Penalized deviance: 7415