EpiNow2 Stan Functions
Delay Handlers

Functions for delay distribution handling. More...

Collaboration diagram for Delay Handlers:

Functions

array[] int get_delay_type_max (int delay_types, array[] int delay_types_p, array[] int delay_types_id, array[] int delay_types_groups, array[] int delay_max, array[] int delay_np_pmf_groups)
 
vector get_delay_rev_pmf (int delay_id, int len, array[] int delay_types_p, array[] int delay_types_id, array[] int delay_types_groups, array[] int delay_max, vector delay_np_pmf, array[] int delay_np_pmf_groups, vector delay_params, array[] int delay_params_groups, array[] int delay_dist, int left_truncate, int reverse_pmf, int cumulative)
 
void delays_lp (vector delay_params, vector delay_params_mean, vector delay_params_sd, array[] int delay_params_groups, array[] int delay_dist, array[] int weight)
 
void delays_np_lp (vector delay_np_est_raw, vector delay_np_est_alpha)
 
vector combine_np_pmf (vector delay_np_pmf, int delay_n_np_est, array[] int delay_np_est_groups, array[] int delay_np_est_pos, vector delay_np_est_raw)
 
vector normal_lb_rng (vector mu, vector sigma, vector lb)
 

Description

Functions for delay distribution handling.

Functions from delays.stan for creating, parameterizing and applying delay distributions.

Function Documentation

◆ combine_np_pmf()

vector combine_np_pmf ( vector delay_np_pmf,
int delay_n_np_est,
array[]int delay_np_est_groups,
array[]int delay_np_est_pos,
vector delay_np_est_raw )

Combine fixed and estimated nonparametric delay PMFs

Returns a copy of the fixed PMF vector with the estimated entries overwritten by per-segment normalisation of the raw gamma values. Fixed entries and structural zeros are left unchanged.

Parameters
delay_np_pmfFixed PMF vector (concatenated ragged array).
delay_n_np_estNumber of estimated nonparametric delays.
delay_np_est_groupsRagged-array boundaries into delay_np_est_raw (length delay_n_np_est + 1).
delay_np_est_posFor each estimated element, its position within delay_np_pmf.
delay_np_est_rawRaw gamma values backing each segment.
Returns
A vector of length num_elements(delay_np_pmf) containing the combined PMF.

Definition at line 206 of file delays.stan.

◆ delays_lp()

void delays_lp ( vector delay_params,
vector delay_params_mean,
vector delay_params_sd,
array[]int delay_params_groups,
array[]int delay_dist,
array[]int weight )

Update log density for delay distribution priors

Parameters
delay_paramsVector of parameters for parametric delay distributions
delay_params_meanVector of prior means for delay parameters
delay_params_sdVector of prior standard deviations for delay parameters
delay_params_groupsArray of indices for accessing delay parameters
delay_distArray of distribution types using primarycensored convention (1: lognormal, 2: gamma, 3: weibull, 4: exponential)
weightArray of weights for each delay distribution in the log density

Definition at line 138 of file delays.stan.

◆ delays_np_lp()

void delays_np_lp ( vector delay_np_est_raw,
vector delay_np_est_alpha )

Update log prior density for estimated nonparametric delays

Applies Gamma(alpha, 1) priors to the raw vector that backs the estimated nonparametric PMFs. Once normalised within each ragged segment, this induces a Dirichlet(alpha) prior on the segment. See https://mc-stan.org/docs/stan-users-guide/simplexes.html for the gamma-normalisation construction.

Parameters
delay_np_est_rawRaw gamma-distributed values backing each estimated nonparametric PMF segment.
delay_np_est_alphaDirichlet concentration parameters, matched element-wise to delay_np_est_raw.

Definition at line 180 of file delays.stan.

◆ get_delay_rev_pmf()

vector get_delay_rev_pmf ( int delay_id,
int len,
array[]int delay_types_p,
array[]int delay_types_id,
array[]int delay_types_groups,
array[]int delay_max,
vector delay_np_pmf,
array[]int delay_np_pmf_groups,
vector delay_params,
array[]int delay_params_groups,
array[]int delay_dist,
int left_truncate,
int reverse_pmf,
int cumulative )

Get the reversed probability mass function for a delay

Parameters
delay_idIdentifier for the specific delay distribution
lenLength of the output PMF
delay_types_pArray indicating whether each delay is parametric (1) or non-parametric (0)
delay_types_idArray mapping delay types to their respective IDs
delay_types_groupsArray of indices defining groups of delay types
delay_maxArray of maximum delays for parametric distributions
delay_np_pmfVector of probability mass functions for non-parametric delays
delay_np_pmf_groupsArray of indices for accessing non-parametric PMFs
delay_paramsVector of parameters for parametric delay distributions
delay_params_groupsArray of indices for accessing delay parameters
delay_distArray of distribution types using primarycensored convention (1: lognormal, 2: gamma, 3: weibull, 4: exponential)
left_truncateLeft truncation point (0 for no truncation)
reverse_pmfWhether to reverse the PMF (1) or not (0)
cumulativeWhether to return cumulative (1) or daily (0) values
Returns
A vector containing the (reversed) PMF of length len

Definition at line 65 of file delays.stan.

References convolve_with_rev_pmf(), and discretised_pmf().

Here is the call graph for this function:

◆ get_delay_type_max()

array[] int get_delay_type_max ( int delay_types,
array[]int delay_types_p,
array[]int delay_types_id,
array[]int delay_types_groups,
array[]int delay_max,
array[]int delay_np_pmf_groups )

Delay Distribution Functions

This group of functions handles the creation, manipulation, and application of delay distributions in the model. Delay distributions represent the time between events (e.g., infection to symptom onset, symptom onset to reporting). Get the maximum delay for each delay type

Parameters
delay_typesNumber of delay types
delay_types_pArray indicating whether each delay is parametric (1) or non-parametric (0)
delay_types_idArray mapping delay types to their respective IDs
delay_types_groupsArray of indices defining groups of delay types
delay_maxArray of maximum delays for parametric distributions
delay_np_pmf_groupsArray of indices for accessing non-parametric PMFs
Returns
An array of maximum delays for each delay type

Definition at line 23 of file delays.stan.

◆ normal_lb_rng()

vector normal_lb_rng ( vector mu,
vector sigma,
vector lb )

Generate random samples from a normal distribution with lower bounds

Parameters
muVector of means
sigmaVector of standard deviations
lbVector of lower bounds
Returns
A vector of random samples from the truncated normal distribution

Definition at line 233 of file delays.stan.