PyRenew
Bayesian renewal modeling with JAX and NumPyro.
PyRenew is a flexible tool for simulation and statistical inference of epidemiological models, emphasizing hierarchical multi-signal renewal models. Built on top of NumPyro, PyRenew provides configurable classes that encapsulate the components of a renewal model, and methods to orchestrate their composition into programs that clearly express model structure and choices.
Renewal models
A renewal model estimates new infections from recent past infections using a generation interval distribution \(w(s)\): the probability that \(s\) time units separate infection in an index case and a secondary case. The core renewal equation is:
where \(R_t\) is the time-varying reproduction number.
Inference is complicated by the fact that observational data require their own models (Bhatt et al., 2023, S2). The observation equation links infections to expected observations:
where \(\alpha\) is the ascertainment rate and \(\pi(s)\) is the delay distribution from infection to observation.
Design
PyRenew's building blocks are:
RandomVariable-- an abstract base class for quantities that models can sample from, including stochastic draws vianumpyro.sample(), mechanistic computations, and fixed values.Model-- an abstract base class that defines model structure through asample()method and provides functionality for fitting and simulation.PyrenewBuilder-- an orchestrator that composesRandomVariablecomponents into a complete renewal model, auto-computing derived quantities like the number of initialization points.
Components (generation interval, reproduction number process, observation process) are specified independently, so each can be swapped without changing the rest of the model. This makes it straightforward to move a quantity between "known" and "inferred" and keeps modeling choices explicit and reviewable.
Multi-signal models
PyRenew's strength lies in multi-signal integration: pooling information across diverse observed data streams such as hospital admissions, wastewater concentrations, and emergency department visits, where each signal has distinct observation delays, noise characteristics, and spatial resolutions. For single-signal renewal models, we recommend the excellent R package EpiNow2.
Installation
pip install git+https://github.com/CDCgov/PyRenew@main
Tutorials
- The RandomVariable abstract base class -- PyRenew's core abstraction and its concrete implementations.
- Building multi-signal models -- composing a renewal model from PyRenew components using
PyrenewBuilder. - Observation processes: count data -- connecting latent infections to observed counts.
- Observation processes: measurements -- connecting latent infections to continuous measurements.
- Latent hierarchical infections -- modeling infections with subpopulation structure.
Resources
Models implemented with PyRenew
- pyrenew-covid-wastewater -- forecasting COVID-19 hospitalizations using wastewater data.
- pyrenew-flu-light -- an influenza forecasting model used in the 2023-24 respiratory season.