Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ The PyRenew package is a flexible tool for simulation and statistical inference
Built on top of the [numpyro](https://num.pyro.ai/) Python library, `pyrenew` provides core components for model building.

A renewal model estimates new infections from recent past infections using a generation interval (the time between successive infections in a transmission chain).
From this, it infers $R_t$, the time-varying reproduction number, which indicates whether the number of infectious individuals is increasing or decreasing.
From this, it infers $\mathcal{R}(t)$, the time-varying reproduction number, which indicates whether the number of infectious individuals is increasing or decreasing.
The core renewal equation is:

$$I(t) = R_t \sum_{s} I(t-s) \, w(s)$$
$$I(t) = \mathcal{R}(t) \sum_{s} I(t-s) \, w(s)$$

where $w(s)$ is the generation interval distribution: the probability that $s$ time units separate infection in an index case and a secondary case.

Expand Down
16 changes: 8 additions & 8 deletions docs/tutorials/building_multisignal_models.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ from pyrenew.observation import (

Renewal models in PyRenew combine two types of components:

1. **Latent infection process**: Generates unobserved infections via the renewal equation, driven by a time-varying reproduction number $R(t)$
1. **Latent infection process**: Generates unobserved infections via the renewal equation, driven by a time-varying reproduction number $\mathcal{R}(t)$

2. **Observation processes**: Transform latent infections into observable signals (hospital admissions, wastewater concentrations, etc.) by applying delays, ascertainment, and noise

A **multi-signal model** combines multiple observation processes—each representing a different data stream, e.g., hospital admissions, wastewater concentrations, which stem from the same underlying latent infection process. By jointly modeling these signals, we can improve estimation and prediction of the time-varying reproduction number $R(t)$. Such a model must:
A **multi-signal model** combines multiple observation processes—each representing a different data stream, e.g., hospital admissions, wastewater concentrations, which stem from the same underlying latent infection process. By jointly modeling these signals, we can improve estimation and prediction of the time-varying reproduction number $\mathcal{R}(t)$. Such a model must:

- Generate a single coherent infection trajectory (or set of trajectories for subpopulations)
- Route those infections to each observation process appropriately
Expand All @@ -106,7 +106,7 @@ The builder computes initialization requirements, wires components together, and

Before diving into multi-signal models, you may want to review these foundational tutorials:

- **[Hierarchical Latent Infections](latent_hierarchical_infections.qmd)**: Understanding temporal process choices for $R(t)$
- **[Hierarchical Latent Infections](latent_hierarchical_infections.qmd)**: Understanding temporal process choices for $\mathcal{R}(t)$
- **[Observation Processes: Counts](observation_processes_counts.qmd)**: Modeling count data (admissions, deaths)
- **[Observation Processes: Measurements](observation_processes_measurements.qmd)**: Modeling continuous data (wastewater)

Expand All @@ -116,7 +116,7 @@ This tutorial shows how to combine these components into a complete multi-signal

This tutorial demonstrates building a multi-signal renewal model using:

- `HierarchicalInfections` — subpopulations share a jurisdiction-level baseline $R(t)$ with subpopulation-specific deviations
- `HierarchicalInfections` — subpopulations share a jurisdiction-level baseline $\mathcal{R}(t)$ with subpopulation-specific deviations
- `Counts` — hospital admissions (jurisdiction-level)
- A custom `Wastewater` class — viral concentrations (subpopulation-level)

Expand Down Expand Up @@ -180,7 +180,7 @@ Latent infection processes implement the renewal equation to generate infection

- **Generation interval**: PMF for secondary infection timing
- **Initial infections (I0)**: Starting condition for the renewal process
- **Temporal dynamics**: How $R(t)$ evolves over time
- **Temporal dynamics**: How $\mathcal{R}(t)$ evolves over time

### Generation Interval

Expand Down Expand Up @@ -217,11 +217,11 @@ initial_log_rt_rv = DistributionalVariable(
)
```

### Temporal Processes for $R(t)$
### Temporal Processes for $\mathcal{R}(t)$

We configure two temporal processes:

- **Jurisdiction-level** (`baseline_rt_process`): AR(1) process for the baseline $R(t)$
- **Jurisdiction-level** (`baseline_rt_process`): AR(1) process for the baseline $\mathcal{R}(t)$
- **Subpopulation-level** (`subpop_rt_deviation_process`): RandomWalk for subpopulation deviations

The RandomWalk allows flexible evolution of subpopulation-specific transmission without mean reversion.
Expand Down Expand Up @@ -1119,6 +1119,6 @@ This tutorial demonstrated composing a multi-signal renewal model using `Pyrenew

### Next Steps

- Explore different temporal processes for $R(t)$ in the [Hierarchical Latent Infections](latent_hierarchical_infections.qmd) tutorial
- Explore different temporal processes for $\mathcal{R}(t)$ in the [Hierarchical Latent Infections](latent_hierarchical_infections.qmd) tutorial
- Learn about count-based observation models in [Observation Processes: Counts](observation_processes_counts.qmd)
- Learn about continuous measurement models in [Observation Processes: Measurements](observation_processes_measurements.qmd)
12 changes: 6 additions & 6 deletions docs/tutorials/latent_hierarchical_infections.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ You have a jurisdiction (e.g., a state or metropolitan area) with multiple subpo
- Allow local transmission to deviate from the jurisdiction average
- Produce estimates for both observed and unobserved areas

`HierarchicalInfections` addresses this by decomposing the effective reproduction number $R(t)$ into:
`HierarchicalInfections` addresses this by decomposing the effective reproduction number $\mathcal{R}(t)$ into:

$$\log R_k(t) = \log R_{\text{baseline}}(t) + \delta_k(t)$$
$$\log \mathcal{R}_k(t) = \log \mathcal{R}_{\text{baseline}}(t) + \delta_k(t)$$

where:

- $R_{\text{baseline}}(t)$ is the jurisdiction-level reproduction number (shared across all subpopulations)
- $\mathcal{R}_{\text{baseline}}(t)$ is the jurisdiction-level reproduction number (shared across all subpopulations)
- $\delta_k(t)$ is the deviation for subpopulation $k$, constrained so that $\sum_k \delta_k(t) = 0$

The sum-to-zero constraint ensures $R_{\text{baseline}}(t)$ represents the geometric mean of subpopulation $R$ values—a natural "center" for the hierarchy.
The sum-to-zero constraint ensures $\mathcal{R}_{\text{baseline}}(t)$ represents the geometric mean of subpopulation $\mathcal{R}$ values—a natural "center" for the hierarchy.

Each subpopulation runs its own renewal equation with its own $R_k(t)$, then results are aggregated for jurisdiction-level quantities (like total hospital admissions).
Each subpopulation runs its own renewal equation with its own $\mathcal{R}_k(t)$, then results are aggregated for jurisdiction-level quantities (like total hospital admissions).

## Model Inputs

Expand Down Expand Up @@ -359,7 +359,7 @@ i0_df = pd.DataFrame(i0_data)

### Temporal Processes

The temporal process determines how $R_{\text{baseline}}(t)$ and the deviations $\delta_k(t)$ evolve over time. PyRenew provides three options:
The temporal process determines how $\mathcal{R}_{\text{baseline}}(t)$ and the deviations $\delta_k(t)$ evolve over time. PyRenew provides three options:

| Process | What It Does | Epidemiological Interpretation |
|---------|--------------|-------------------------------|
Expand Down
6 changes: 3 additions & 3 deletions equations.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ flowchart LR

direction TB

subgraph rt["R(t)"]
subgraph rt["\mathcal{R}(t)"]
rt_elements["-Gaussian\n-AR\n-Link\n-User-def"]
end
style rt_elements text-align:left
Expand Down Expand Up @@ -219,8 +219,8 @@ flowchart LR

direction LR

Rt(("R(t)")) --> Rtdots(("..."))
Rtdots --> Rtj(("R(t, j)"))
Rt(("\mathcal{R}(t)")) --> Rtdots(("..."))
Rtdots --> Rtj(("\mathcal{R}(t, j)"))
style Rtdots fill:transparent,stroke:transparent
end

Expand Down
4 changes: 2 additions & 2 deletions pyrenew/latent/infections.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class Infections(RandomVariable):
The mathematical model is given by:

```math
I(t) = R(t) \times \sum_{\tau < t} I(\tau) g(t-\tau)
I(t) = \mathcal{R}(t) \times \sum_{\tau < t} I(\tau) g(t-\tau)
```

where $I(t)$ is the number of infections at time $t$,
$R(t)$ is the reproduction number at time $t$, and
$\mathcal{R}(t)$ is the reproduction number at time $t$, and
$g(t-\tau)$ is the generation interval.
"""

Expand Down
Loading