No-U-turn sampling for TMB and ADMB models
Cole C. Monnahan
2025-08-13
Source:vignettes/adnuts.Rmd
adnuts.Rmd
Summary
adnuts
(pronounced A-D NUTS like A-D MB) provides a
wrapper for performing Bayesian analyses using the no-U-turn (NUTS)
algorithm (Hoffman and Gelman 2014) for
TMB (Kristensen et al. 2016) and ADMB
(Fournier et al. 2012) models.
For TMB models the NUTS algorithm is in the Stan software (Carpenter et al. 2017) and linked through the
StanEstimators
R package. adnuts
implements the sparse NUTS (SNUTS)
algorithm of (Monnahan et al. in prep) by
decorrelating and descaling the posterior distribution prior to passing
to Stan. For models with high correlations and sparse precision
matrices, SNUTS can substantially improve sampling efficiency.
Importantly, it works for TMB and RTMB models, and can be run on models
from existing packages.
Basic usage for a TMB or RTMB object obj
is shown as
follows, with a more in depth article on the website.
fit <- sample_snuts(obj)
print(fit)
plot(fit)
pairs(fit, order='slow')
post <- as.data.frame(fit)
launch_shinytmb(fit)
ADMB models contain the algorithm code internally, but this package
provides the user a convenient environment to run and diagnose Markov
chains, and make inference. Development for ADMB models is frozen but
should maintain backwards compatibility in the near future. This package
aims to give ADMB models similar functionality to the software Stan and
rstan
in particular (Carpenter et
al. 2017; Stan Development Team 2017).
Assuming a valid ADMB model located in directory path
has been built and optimized successfully, then
fit <- sample_nuts(model='simple', path=path)
print(fit)
plot(fit)
pairs(fit, order='slow')
post <- as.data.frame(fit)
launch_shinyadmb(fit)
History
The package has undergone several shifts in focus. Initially, it was
developed to provide a NUTS implementation in R for models where the
log-density and log-density gradient could be written as R functions
(e.g., TMB). However, the tmbstan
package was developed and
became the preferred option for TMB users, so the focus switched to ADMB
models and TMB functionality was de-emphasized. In 2025, with the
development of SNUTS, the primary focus of adnuts
was
shifted back to TMB models via the SNUTS approach.