kenkellner / jagsUI

R package to Run JAGS (Just Another Gibbs Sampler) analyses from within R
https://kenkellner.github.io/jagsUI/
35 stars 7 forks source link

Reproducible output with parallel=FALSE #45

Closed mikemeredith closed 3 years ago

mikemeredith commented 3 years ago

Currently jags does not give reproducible output with parallel=FALSE while seed=NULL, ie, you can't get reproducible output by calling set.seed before jags. Here's a bit of code to show the problem:

example(jags)  # set up everything for the example

set.seed(42)
out1 <- jags(data, inits, params, modfile, n.chains = 3, n.iter = 1000)

set.seed(42)
out2 <- jags(data, inits, params, modfile, n.chains = 3, n.iter = 1000)

all.equal(out1$samples, out2$samples)  # not the same

With parallel=TRUE it's ok. Same with jags.basic. The difference is due to & parallel in line 70 of the "geninits.R" file. Functions in the rjags package ignore the seed set in R, so to get reproducible results a seed needs to be passed in inits for serial as well as parallel. Deleting & parallel fixes this.

I've tested this with R CMD check on R 4.1.0 and R devel (build r80301) a few days ago and ran all the AHM code with the new version in R devel and some chapters in R 4.1.0 as well. I got the latest R devel this morning (build r80354) and got an error installing jagsUI as it can't find DLL rjags: an issue with R devel I guess.

mikemeredith commented 3 years ago

The issue with installation on R devel applies only to the 32-bit version, likely related to the plan to discontinue support for 32-bit Windows in 4.2. I reinstalled R devel with only 64-bit version, and everything worked fine.

kenkellner commented 3 years ago

Thanks Mike. Though this worked already but you're right, it doesn't.