Data Analysis with R Open access Peer reviewed

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

Kasper Kristensen, Anders Nielsen, Christoffer Moesgaard Albertsen, Casper Willestofte Berg and 1 more

Ecology and Evolution | Oct 29, 2026

Scollr summary

What this paper is about

RTMB, an R package that exposes the full power of TMB's AD machinery directly from plain R, is presented, a transparent, debuggable, and pedagogically accessible interface to state-of-the-art latent variable inference, with runtime performance comparable to native TMB.

Full abstract

Read the full 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.

Direct answer

What can I do from this paper page?

Use this page to scan "RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder" quickly: start with the summary and abstract, then check the authors, source, topics, and related papers. From here, open Scollr to follow Data Analysis with R research, save the paper, or map adjacent work.

Authors

Researchers on this paper

Kasper Kristensen

first | Technical University of Denmark | ORCID 0000-0003-3425-3762

Anders Nielsen

middle | Technical University of Denmark | ORCID 0000-0001-9683-9262

Christoffer Moesgaard Albertsen

middle | Technical University of Denmark | ORCID 0000-0003-0088-4363

Casper Willestofte Berg

middle | Technical University of Denmark | ORCID 0000-0002-3812-5269

Vanessa Trijoulet

last | Technical University of Denmark | ORCID 0000-0002-3831-1416

Research areas

Follow related topics

Citation

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},
  doi = {10.1002/ece3.74572},
  url = {https://doi.org/10.1002/ece3.74572}
}

FAQ

Using this paper in a discovery workflow

How do I find related work for this paper?

Use the related papers and topic links on this page as starting points. In Scollr, you can also open the paper and build a literature map around its references, citing papers, and related work.

How can I keep up with new Data Analysis with R research papers?

Follow Data Analysis with R research in Scollr. New papers from the topic flow into a personalized feed, and you can save useful studies to revisit later.

Can I cite this paper from this page?

This page includes a static BibTeX block for RTMB: An R Package for Fitting Latent Variable Models With Template Model Builder. Always verify the DOI, source, and publication details against the publisher record before submitting a manuscript.

Follow this research in Scollr

Follow the topics and authors behind this paper, save useful studies, and build a literature map when you are ready to go deeper.

Get the app