![]() |
EpiNow2 Stan Functions
|
Functions for estimating infection trajectories. More...

Subgroups | |
| Estimates Smoothing | |
| Functions for smoothing estimates using Gaussian processes. | |
| Observation Model | |
| Functions for modeling the observation process. | |
Functions | |
| real | update_infectiousness (vector infections, vector gt_rev_pmf, int seeding_time, int index) |
| vector | renewal_infections (vector seed, vector R, vector gt_rev_pmf, real pop, int use_pop, data real pop_floor, int nht) |
| vector | generate_infections (vector R, int uot, vector gt_rev_pmf, array[] real initial_infections, real pop, int use_pop, data real pop_floor, int ht, int obs_scale, real fraction_observed, int initial_as_scale) |
| Generate infections using a renewal equation approach. | |
| vector | deconvolve_infections (vector shifted_cases, vector noise, int fixed, int prior) |
Functions for estimating infection trajectories.
This group contains functions for estimating and modeling infection dynamics, including implementation of the renewal equation and backcalculation approaches. Core infection estimation functions from infections.stan and related generated quantities functions.
| vector deconvolve_infections | ( | vector | shifted_cases, |
| vector | noise, | ||
| int | fixed, | ||
| int | prior ) |
Backcalculate infections from cases
This function estimates infections by working backwards from observed cases, applying noise to account for uncertainty in the process.
| shifted_cases | Vector of shifted case counts |
| noise | Vector of noise values |
| fixed | Whether to use fixed (1) or variable (0) noise |
| prior | Prior type to use (0: noise only, 1: cases * noise, 2: random walk) |
shifted_cases = {10, 20, 30}, no noise (noise = {0, 0, 0}, so exp(noise) = 1) and prior = 1, each case count is scaled by 1 and offset by the 1e-5 numerical floor: deconvolve_infections(shifted_cases, noise, 0, 1) returns approximately {10, 20, 30}. Definition at line 141 of file infections.stan.
| vector generate_infections | ( | vector | R, |
| int | uot, | ||
| vector | gt_rev_pmf, | ||
| array[]real | initial_infections, | ||
| real | pop, | ||
| int | use_pop, | ||
| data real | pop_floor, | ||
| int | ht, | ||
| int | obs_scale, | ||
| real | fraction_observed, | ||
| int | initial_as_scale ) |
Generate infections using a renewal equation approach.
This function implements the renewal equation to generate a time series of infections based on reproduction numbers and the generation time distribution. It can also account for population depletion if a population size is specified. It sets the seeding infections and then calls renewal_infections().
| R | Vector of reproduction numbers |
| uot | Unobserved time (seeding time) |
| gt_rev_pmf | Vector of reversed generation time PMF |
| initial_infections | Array of initial infection values |
| pop | Initial susceptible population (0 for unlimited) |
| use_pop | Population adjustment mode (0=none, 1=forecast only, 2=all) |
| pop_floor | Minimum susceptible population (floor to prevent instability) |
| ht | Horizon time |
| obs_scale | Whether to scale by fraction observed (1) or not (0) |
| fraction_observed | Fraction of infections that are observed |
| initial_as_scale | Whether initial infections are a scaling factor (1) or not (0) |
Definition at line 93 of file infections.stan.
References R_to_r(), and renewal_infections().

| vector renewal_infections | ( | vector | seed, |
| vector | R, | ||
| vector | gt_rev_pmf, | ||
| real | pop, | ||
| int | use_pop, | ||
| data real | pop_floor, | ||
| int | nht ) |
Run the renewal equation from the seeding infections.
Implemented in C++, with a hand-written gradient, in inst/include/epinow2/renewal_infections.hpp, which gives the maths.
| seed | Vector of seeding infections |
| R | Vector of reproduction numbers |
| gt_rev_pmf | Vector of reversed generation time PMF |
| pop | Initial susceptible population |
| use_pop | Population adjustment mode (0=none, 1=after nht, 2=all) |
| pop_floor | Minimum susceptible population |
| nht | Number of time steps before the adjustment when use_pop = 1 |
Referenced by generate_infections().

| real update_infectiousness | ( | vector | infections, |
| vector | gt_rev_pmf, | ||
| int | seeding_time, | ||
| int | index ) |
Infection Modeling Functions
This group of functions handles the generation, calculation, and backcalculation of infection time series in the model. These functions implement the core epidemiological dynamics, including the renewal equation approach. Calculate infectiousness for a single time point
This function computes the weighted sum of past infections with the generation time distribution to determine the current infectiousness.
| infections | Vector of infection counts |
| gt_rev_pmf | Vector of reversed generation time PMF |
| seeding_time | Number of time steps used for seeding |
| index | Current time index (relative to seeding_time) |
infections = {10, 20, 30, 40, 50}, gt_rev_pmf = {0.2, 0.5, 0.3}, seeding_time = 0 and index = 3, the infectiousness is the weighted sum of the three most recent infections up to time 3: update_infectiousness(infections, gt_rev_pmf, 0, 3) returns 10 * 0.2 + 20 * 0.5 + 30 * 0.3 = 21. Definition at line 32 of file infections.stan.
Referenced by calculate_growth_infness(), and calculate_Rt().
