Sequential reduction for discrete latent variables in ecological and evolutionary models using RTMB
Abstract
Statistical models of ecological and evolutionary dynamics often include latent variables that are either continuous (e.g., average body size) or discrete (e.g., numerical abundance). Mixed-type hierarchical models containing both are typically fitted using Markov chain Monte Carlo (MCMC), which can be prohibitively slow for large models. Here, we introduce an alternative in the R package RTMB that automates the sequential reduction of small groups of related discrete variables, allowing them to be efficiently marginalized. Sequential reduction is combined with automatic differentiation and the Laplace approximation to estimate parameters and predict both continuous and discrete variables. We demonstrate speed and flexibility using demographic examples (occupancy, dynamic occupancy, N-mixture, and open dynamic N-mixture models), benchmarking RTMB against JAGS and unmarked. We then develop two novel applications. The first is a multi-site open N-mixture model with a spatial latent variable governing site-specific initial abundance and recruitment, which shows that continuous Gaussian Markov random fields can be estimated jointly with discrete abundance dynamics in under a minute. The second is phylogenetic trait imputation for a published data set of female Liolaemus lizards, where we jointly impute a binary trait (viviparity), estimate its state-switching rates, and estimate its effect on a continuous trait (body size) during ancestral state reconstruction. This indicates that phylogenetic comparative methods can estimate linkages among discrete and continuous traits. We envision that intuitive and efficient specification of mixed-type models will allow more expressive representation of ecological and evolutionary dynamics.
Related
- Spatial segregation and multi-scale space-use adjustments to socio-ecological variables in western gorillas
- Spatial segregation and multi-scale space-use adjustments to socio-ecological variables in western gorillas
- Beyond the tangled bank: An evolving meta‐ecosystems framework to integrate ecological and evolutionary perspectives
- Ecological and evolutionary drivers of thermal performance curves across the tree of life
- Contemporary environmental conditions decouple ecological similarity from evolutionary relatedness in vector mosquito communities
BibTeX
@misc{cahill2026sequential,
title = {{Sequential reduction for discrete latent variables in ecological and evolutionary models using RTMB}},
author = {Christopher L. Cahill and James T. Thorson and Kasper Kristensen},
howpublished = {arXiv},
year = {2026},
month = sep,
doi = {10.48550/arxiv.2609.13333},
eprint = {2609.13333},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2609.13333},
note = {CC BY 4.0},
}
RIS
TY - UNPB
TI - Sequential reduction for discrete latent variables in ecological and evolutionary models using RTMB
AU - Christopher L. Cahill
AU - James T. Thorson
AU - Kasper Kristensen
PY - 2026
DA - 2026/09/11
PB - arXiv
DO - 10.48550/arxiv.2609.13333
UR - https://arxiv.org/abs/2609.13333
AB - Statistical models of ecological and evolutionary dynamics often include latent variables that are either continuous (e.g., average body size) or discrete (e.g., numerical abundance). Mixed-type hierarchical models containing both are typically fitted using Markov chain Monte Carlo (MCMC), which can be prohibitively slow for large models. Here, we introduce an alternative in the R package RTMB that automates the sequential reduction of small groups of related discrete variables, allowing them to be efficiently marginalized. Sequential reduction is combined with automatic differentiation and the Laplace approximation to estimate parameters and predict both continuous and discrete variables. We demonstrate speed and flexibility using demographic examples (occupancy, dynamic occupancy, N-mixture, and open dynamic N-mixture models), benchmarking RTMB against JAGS and unmarked. We then develop two novel applications. The first is a multi-site open N-mixture model with a spatial latent variable governing site-specific initial abundance and recruitment, which shows that continuous Gaussian Markov random fields can be estimated jointly with discrete abundance dynamics in under a minute. The second is phylogenetic trait imputation for a published data set of female Liolaemus lizards, where we jointly impute a binary trait (viviparity), estimate its state-switching rates, and estimate its effect on a continuous trait (body size) during ancestral state reconstruction. This indicates that phylogenetic comparative methods can estimate linkages among discrete and continuous traits. We envision that intuitive and efficient specification of mixed-type models will allow more expressive representation of ecological and evolutionary dynamics.
ER -