Skip to content
DraconiticResearch
Search Sources API
201,683 studies31 sourcesUpdated 23 min ago
Peer-reviewedCC BY 4.0Ecology and Evolution

RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder

  1. 1National Institute of Aquatic Resources Technical University of Denmark Lyngby Denmark

Abstract

Hierarchical and latent variable models are fundamental in ecology, fisheries science, and epidemiology, but fitting them efficiently relies on automatic differentiation (AD) combined with approximations such as the Laplace approximation. Template Model Builder ( TMB ) has become a standard tool for this kind of inference in R, but it requires users to write the objective function in C++, which is a potential obstacle for those unfamiliar with it, slows model iteration through compilation, and complicates debugging and simulation. We present RTMB , an R package that exposes the full power of TMB 's AD machinery directly from plain R. Users write the joint negative log‐likelihood as an ordinary R function; RTMB traces it onto an AD tape and hands the result to TMB 's existing optimization, Laplace approximation, and reporting routines. We describe the design of the package, illustrate its use through a worked example, and provide a side‐by‐side comparison with the equivalent TMB implementation of a theta‐logistic state‐space population model. The result is a transparent, debuggable, and pedagogically accessible interface to state‐of‐the‐art latent variable inference, with runtime performance comparable to native TMB .

Related

  1. A Latent Inflammatory Tissue-State Variable Mechanistically Links Radiotherapy-Induced Immune Remodeling to Recurrent Tumor Permissiveness
    M. A. Mayeaux, X. M. Zhou, M. Rafat
    bioRxivPreprintCC BYFull textSystems & synthetic biologybioRxiv
  2. Fixed-Dimensional Latent Flow for Generating Variable-Size 3D Molecules
    Weichi Yao, Cameron Gruich, Bryan R. Goldsmith +1
    arXivPreprintarXiv licenceFull textBioinformatics & computational biologyPhysical chemistryarXiv
  3. Latent variable modelling of condition and reproductive investment in Gryllus vocalis field crickets
    Madison Von Deylen, Agustí Muñoz-Garcia, Ian M. Hamilton +1
    Royal Society Open SciencePeer-reviewedCC BY 4.0Full textEvolutionary biologyPhysiologyCrossrefEurope PMCPMC
  4. From labels to latents: revealing state-dependent hippocampal computations and non-spatial replay with Jump Latent Variable Model
    Zheyang (Sam) Zheng, Ipshita Zutshi, Roman Huszar +4
    bioRxivPreprintCC BY-NC-ND 4.0Full text1 citedNeurosciencePMC
  5. Rolf Christian Gaillard (1944–2011): A builder of modern European endocrinology and neuroendocrinology
    Philippe Chanson, Eduardo Spinedi, François Pralong
    Journal of NeuroendocrinologyPeer-reviewedCC BYFull textGeneral biologyEndocrinology & metabolismHAL
BibTeX
@article{kristensen2026rtmb,
  title = {{RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder}},
  author = {Kasper Kristensen and Anders Nielsen and Christoffer Moesgaard Albertsen and Casper Willestofte Berg and Vanessa Trijoulet},
  journal = {Ecology and Evolution},
  year = {2026},
  month = oct,
  doi = {10.1002/ece3.74572},
  url = {https://onlinelibrary.wiley.com/doi/10.1002/ece3.74572},
  note = {CC BY 4.0},
}
RIS
TY  - JOUR
TI  - RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder
AU  - Kasper Kristensen
AU  - Anders Nielsen
AU  - Christoffer Moesgaard Albertsen
AU  - Casper Willestofte Berg
AU  - Vanessa Trijoulet
PY  - 2026
DA  - 2026/10/29
JO  - Ecology and Evolution
DO  - 10.1002/ece3.74572
UR  - https://onlinelibrary.wiley.com/doi/10.1002/ece3.74572
AB  - Hierarchical and latent variable models are fundamental in ecology, fisheries science, and epidemiology, but fitting them efficiently relies on automatic differentiation (AD) combined with approximations such as the Laplace approximation. Template Model Builder ( TMB ) has become a standard tool for this kind of inference in R, but it requires users to write the objective function in C++, which is a potential obstacle for those unfamiliar with it, slows model iteration through compilation, and complicates debugging and simulation. We present RTMB , an R package that exposes the full power of TMB 's AD machinery directly from plain R. Users write the joint negative log‐likelihood as an ordinary R function; RTMB traces it onto an AD tape and hands the result to TMB 's existing optimization, Laplace approximation, and reporting routines. We describe the design of the package, illustrate its use through a worked example, and provide a side‐by‐side comparison with the equivalent TMB implementation of a theta‐logistic state‐space population model. The result is a transparent, debuggable, and pedagogically accessible interface to state‐of‐the‐art latent variable inference, with runtime performance comparable to native TMB .
SN  - 2045-7758
SN  - 2045-7758
ER  -