--- title: "Options for MCMC engines in occumb()" output: rmarkdown::html_vignette resource_files: - images/ess_fish.png - images/rhat_fish.png - images/ess_insects.png - images/rhat_insects.png vignette: > %\VignetteIndexEntry{Options for MCMC engines in occumb()} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- As of occumb v1.3.0, users can choose NIMBLE instead of JAGS for MCMC sampling in the `occumb()` function. To use NIMBLE, simply specify `engine = “NIMBLE”` when calling `occumb()`. [NIMBLE](https://r-nimble.org/) is an actively developed MCMC engine. As shown in the benchmark results below, NIMBLE demonstrates exceptionally high performance when fitting models with `occumb()`. Therefore, while the default MCMC engine for `occumb()` remains JAGS, users are encouraged to use NIMBLE for model fitting. NIMBLE allows flexible changes to the sampling algorithm for each parameter. Taking advantage of this, occumb significantly improves sampling performance in NIMBLE by specifying the Barker proposal sampler—a gradient-based adaptive Metropolis-Hastings algorithm with a multivariate normal proposal distribution—for `Mu`, `sigma`, and `r`. In NIMBLE, models are compiled at runtime, so there is a delay before MCMC begins. In addition, compared to fitting with JAGS, fitting with NIMBLE can require a longer burn-in period. Even so, NIMBLE is likely to take less time overall: at a modest estimate, NIMBLE can produce higher-quality MCMC samples in less than half the time required by JAGS. ## Benchmarks To evaluate NIMBLE’s relative performance compared to JAGS, a benchmark was conducted using the `fish` eDNA dataset included in the package and [an aquatic insect eDNA dataset](https://github.com/fukayak/eDNA_aquatic_insects). The same model was applied to each dataset using `occumb()` to compare the distributions of effective sample sizes (ESS) generated per unit time (hour), as a measure of MCMC sampling efficiency, and the distributions of R-hat values, as a measure of convergence, between JAGS and NIMBLE. ### Fish dataset In the model for the fish dataset, `formula_psi = ~riverbank` and `formula_phi_shared = ~mismatch` were specified. To ensure that the chains converge to a stationary distribution, the following MCMC settings were specified: `n.burnin = 30000`, `n.thin = 500`, and `n.iter = 530000` for JAGS, and `n.burnin = 750000`, `n.thin = 250`, and `n.iter = 1000000` for NIMBLE. Three chains were run in parallel.