EpiNow2 Stan Functions
Rt Estimation

Functions for estimating reproduction numbers. More...

Collaboration diagram for Rt Estimation:

Subgroups

 Estimates Smoothing
 Functions for smoothing estimates using Gaussian processes.
 
 Observation Model
 Functions for modeling the observation process.
 

Functions

vector calculate_Rt (vector infections, int seeding_time, vector gt_rev_pmf, int smooth)
 
vector calculate_growth (vector infections, int seeding_time)
 
vector update_Rt (int t, real R0, vector noise, array[] int bps, vector bp_effects, int stationary)
 Update a vector of effective reproduction numbers (Rt) based on an intercept, breakpoints (i.e. a random walk), and a Gaussian process.
 
void rt_lp (array[] real initial_infections_scale, vector bp_effects, array[] real bp_sd, int bp_n, array[] int cases, real initial_infections_guess)
 
real R_to_r_newton_step (real R, real r, vector pmf)
 
real R_to_r (real R, vector gt_rev_pmf, real abs_tol)
 

Description

Functions for estimating reproduction numbers.

This group contains functions for estimating and processing reproduction numbers (Rt), including updating Rt values, calculating growth rates, and converting between reproduction numbers and growth rates. Includes functions from rt.stan and related generated quantities.

Function Documentation

◆ calculate_growth()

vector calculate_growth ( vector infections,
int seeding_time )

Calculate growth rate

This function calculates the growth rate from a time series of infections by taking the log difference between consecutive time points.

Parameters
infectionsVector of infection counts
seeding_timeNumber of time steps used for seeding
Returns
A vector of growth rates

Definition at line 63 of file generated_quantities.stan.

◆ calculate_Rt()

vector calculate_Rt ( vector infections,
int seeding_time,
vector gt_rev_pmf,
int smooth )

Generated Quantities Functions

Functions for calculating additional quantities from model outputs. Calculate Rt directly from inferred infections

This function estimates the reproduction number (Rt) using the Cori et al. approach, directly from a time series of infections. Optionally applies smoothing.

Parameters
infectionsVector of infection counts
seeding_timeNumber of time steps used for seeding
gt_rev_pmfVector of reversed generation time PMF
smoothNumber of time steps to use for smoothing (0 for no smoothing)
Returns
A vector of reproduction numbers (Rt)

Definition at line 21 of file generated_quantities.stan.

References update_infectiousness().

Here is the call graph for this function:

◆ R_to_r()

real R_to_r ( real R,
vector gt_rev_pmf,
real abs_tol )

Estimate the growth rate r from reproduction number R

This function uses the Newton method to solve for the growth rate r that corresponds to a given reproduction number R, using the generation time distribution.

Code is based on Julia code from https://github.com/CDCgov/Rt-without-renewal/blob/d6344cc6e451e3e6c4188e4984247f890ae60795/EpiAware/test/predictive_checking/fast_approx_for_r.jl under Apache license 2.0.

Parameters
RReproduction number
gt_rev_pmfReversed probability mass function of the generation time
abs_tolAbsolute tolerance for the Newton solver
Returns
The estimated growth rate r

Definition at line 128 of file rt.stan.

References R_to_r_newton_step().

Referenced by generate_infections().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ R_to_r_newton_step()

real R_to_r_newton_step ( real R,
real r,
vector pmf )

Helper function for calculating r from R using Newton's method

This function performs a single Newton step in the iterative calculation of the growth rate r from the reproduction number R.

Code is based on Julia code from https://github.com/CDCgov/Rt-without-renewal/blob/d6344cc6e451e3e6c4188e4984247f890ae60795/EpiAware/test/predictive_checking/fast_approx_for_r.jl under Apache license 2.0.

Parameters
RReproduction number
rCurrent estimate of the growth rate
pmfGeneration time probability mass function (first index: 0)
Returns
The Newton step for updating r

Definition at line 101 of file rt.stan.

Referenced by R_to_r().

Here is the caller graph for this function:

◆ rt_lp()

void rt_lp ( array[]real initial_infections_scale,
vector bp_effects,
array[]real bp_sd,
int bp_n,
array[]int cases,
real initial_infections_guess )

Calculate the log-probability of the reproduction number (Rt) priors

This function adds the log density contributions from priors on initial infections and breakpoint effects to the target.

Parameters
initial_infections_scaleArray of initial infection values
bp_effectsVector of breakpoint effects
bp_sdArray of breakpoint standard deviations
bp_nNumber of breakpoints
casesArray of observed case counts
initial_infections_guessInitial guess for infections based on cases

Definition at line 73 of file rt.stan.

◆ update_Rt()

vector update_Rt ( int t,
real R0,
vector noise,
array[]int bps,
vector bp_effects,
int stationary )

Update a vector of effective reproduction numbers (Rt) based on an intercept, breakpoints (i.e. a random walk), and a Gaussian process.

Reproduction Number (Rt) Functions

This group of functions handles the calculation, updating, and conversion of reproduction numbers in the model. The reproduction number represents the average number of secondary infections caused by a single infected individual.

Parameters
tLength of the time series
R0Initial reproduction number
noiseVector of Gaussian process noise values
bpsArray of breakpoint indices
bp_effectsVector of breakpoint effects
stationaryWhether the Gaussian process is stationary (1) or non-stationary (0)
Returns
A vector of length t containing the updated Rt values

Definition at line 25 of file rt.stan.