EUVIMEDObjevte EUVIMED
Open access · CC BY 4.0

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

Kasper Kristensen iD, Anders Nielsen iD, Christoffer Moesgaard Albertsen iD, Casper Willestofte Berg iD, Vanessa Trijoulet iD

Ecology and Evolution · 2026-11 · 16 (11)

DOI: 10.1002/ece3.74572 ↗

At a glance

Journal article in Ecology and Evolution, published online on 2026-10-29. Written by Kasper Kristensen and 4 co-authors. Institution: National Institute of Aquatic Resources Technical University of Denmark Lyngby Denmark. 24 references. The full text is freely available (open access, CC BY 4.0).

AbstraktSubjectsBibliografické údajeCiteRelated studies

Abstract (original language)

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 .

Subjects

Author keywords

Laplace approximationTMBautomatic differentiationecologyepidemiologyfisheries sciencehierarchical modelsstate‐space models

Authors and institutions

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

ORCID profiles: Kasper Kristensen, Anders Nielsen, Christoffer Moesgaard Albertsen, Casper Willestofte Berg, Vanessa Trijoulet

Cite

APA

Kristensen, K., Nielsen, A., Albertsen, C. M., Berg, C. W., & Trijoulet, V. (2026). RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder. Ecology and Evolution, 16(11). https://doi.org/10.1002/ece3.74572

Vancouver

Kristensen K, Nielsen A, Albertsen CM, Berg CW, Trijoulet V. RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder. Ecology and Evolution. 2026;16(11). doi:10.1002/ece3.74572

BibTeX
@article{Kristensen2026,
  author = {Kristensen, Kasper and Nielsen, Anders and Albertsen, Christoffer Moesgaard and Berg, Casper Willestofte and Trijoulet, Vanessa},
  title = {RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder},
  journal = {Ecology and Evolution},
  year = {2026},
  volume = {16},
  number = {11},
  doi = {10.1002/ece3.74572}
}
Start for free →