Skip to content

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:

\[I(t) = \mathcal{R}(t) \sum_{s} I(t-s) \, w(s)\]

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:

\[\mu(t) = \alpha \sum_{s} I(t-s) \, \pi(s)\]

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 via numpyro.sample(), mechanistic computations, and fixed values.
  • Model -- an abstract base class that defines model structure through a sample() method and provides functionality for fitting and simulation.
  • PyrenewBuilder -- an orchestrator that composes RandomVariable components 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

Resources

Models implemented with PyRenew

Further reading