Tomas
Tomas

Reputation: 59555

DIC and PED when running JAGS parallely

I am running JAGS in parallel, i.e. each chain in separate process/thread. I am calling run.jags(..., method = "rjparallel", params = c(..., "dic", "ped")). I get the following error:

jags The DIC, PED, pD, full.pD and pOpt cannot be assessed when using parallel or separate chains

Hmmm....

  1. Is it because DIC and PED are computed from all the chains, not just one? Couldn't it be done in the run.jags function after collecting the results from all of the threads?

  2. Is there any way around that? How can I get DIC and PED while having parallel run? It must be possible somehow, right?

Upvotes: 2

Views: 796

Answers (2)

Matt Denwood
Matt Denwood

Reputation: 2583

The answer provided by @M_Fidino is quite correct, but I will just a technical aspect of the question that this answer did not address - i.e.:

  1. Is there any way around that? How can I get DIC and PED while having parallel run? It must be possible somehow, right?

JAGS calculates the penalty term for both DIC and PED using an estimate of the Kullback–Leibler divergence between chains at each iteration for each observed stochastic variable. The majority of the information required to calculate this outside of JAGS is not stored, and while it could in principle be stored to a file by JAGS this would get quite large quite quickly (at least when the number of observations is reasonably large). So it isn't done, and there are no plans to make it do so, so the short answer to your question is 'No, sorry'.

Note however that calculation of 'pD' (and therefore 'DIC') differs depending on who you ask - and some methods of estimating pD do not require multiple chains. See also:

JAGS and WinBUGS giving differing DIC

Finally, there will be some improvements in DIC/PED/WAIC monitors in JAGS version 5 - and the WAIC monitors will not require multiple chains within the same simulation.

Matt

Upvotes: 1

mfidino
mfidino

Reputation: 3055

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 

Upvotes: 2

Related Questions