![]() |
EpiNow2 Stan Functions
|
Functions for delay distribution handling. More...

Functions | |
| int | get_delay_length (int i, array[] int delay_types_p, array[] int delay_types_id, array[] int delay_max, array[] int delay_np_pmf_groups) |
| 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) |
Functions for delay distribution handling.
Functions from delays.stan for creating, parameterizing and applying delay distributions.
| 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.
| delay_np_pmf | Fixed PMF vector (concatenated ragged array). |
| delay_n_np_est | Number of estimated nonparametric delays. |
| delay_np_est_groups | Ragged-array boundaries into delay_np_est_raw (length delay_n_np_est + 1). |
| delay_np_est_pos | For each estimated element, its position within delay_np_pmf. |
| delay_np_est_raw | Raw gamma values backing each segment. |
Definition at line 237 of file delays.stan.
| 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
| delay_params | Ragged vector of parameters for parametric delay distributions |
| delay_params_mean | Ragged vector of prior means for delay parameters |
| delay_params_sd | Ragged vector of prior standard deviations for delay parameters |
| delay_params_groups | Array of lookup indices for the ragged parameter vectors |
| delay_dist | Array of distribution types using primarycensored convention (1: lognormal, 2: gamma, 3: weibull, 4: exponential) |
| weight | Array of weights for each delay distribution in the log density |
Definition at line 173 of file delays.stan.
| 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.
| delay_np_est_raw | Raw gamma-distributed values backing each estimated nonparametric PMF segment. |
| delay_np_est_alpha | Dirichlet concentration parameters, matched element-wise to delay_np_est_raw. |
Definition at line 211 of file delays.stan.
| int get_delay_length | ( | int | i, |
| array[]int | delay_types_p, | ||
| array[]int | delay_types_id, | ||
| 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).
Per-delay values (PMFs, parameters) are packed into ragged vectors: one vector holds the concatenated values for every delay, and a companion *_groups array of lookup indices marks where each delay's segment starts and ends within that vector. See the Stan User's Guide section on ragged data structures: https://mc-stan.org/docs/stan-users-guide/sparse-ragged.html#ragged-data-structs.section Get the PMF length of one delay, i.e. its maximum delay plus one
| i | Index of the delay among all delays |
| delay_types_p | Array indicating whether each delay is parametric (1) or non-parametric (0) |
| delay_types_id | Array mapping delay types to their respective IDs |
| delay_max | Array of maximum delays for parametric distributions |
| delay_np_pmf_groups | Array of lookup indices for the ragged non-parametric PMF vector |
Definition at line 30 of file delays.stan.
Referenced by get_delay_rev_pmf(), and get_delay_type_max().

| 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
| delay_id | Identifier for the specific delay distribution |
| len | Length of the output PMF |
| delay_types_p | Array indicating whether each delay is parametric (1) or non-parametric (0) |
| delay_types_id | Array mapping delay types to their respective IDs |
| delay_types_groups | Array of lookup indices for the ragged groups of delay types |
| delay_max | Array of maximum delays for parametric distributions |
| delay_np_pmf | Ragged vector of probability mass functions for non-parametric delays |
| delay_np_pmf_groups | Array of lookup indices for the ragged non-parametric PMF vector |
| delay_params | Ragged vector of parameters for parametric delay distributions |
| delay_params_groups | Array of lookup indices for the ragged parameter vector |
| delay_dist | Array of distribution types using primarycensored convention (1: lognormal, 2: gamma, 3: weibull, 4: exponential) |
| left_truncate | Left truncation point (0 for no truncation) |
| reverse_pmf | Whether to reverse the PMF (1) or not (0) |
| cumulative | Whether to return cumulative (1) or daily (0) values. The cumulative sum is taken before any reversal, so setting both gives the reversed CDF, as used for right truncation. |
Definition at line 101 of file delays.stan.
References convolve_with_rev_pmf(), discretised_pmf(), and get_delay_length().

| 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 ) |
Get the maximum delay for each delay type
| delay_types | Number of delay types |
| delay_types_p | Array indicating whether each delay is parametric (1) or non-parametric (0) |
| delay_types_id | Array mapping delay types to their respective IDs |
| delay_types_groups | Array of lookup indices for the ragged groups of delay types |
| delay_max | Array of maximum delays for parametric distributions |
| delay_np_pmf_groups | Array of lookup indices for the ragged non-parametric PMF vector |
Definition at line 56 of file delays.stan.
References get_delay_length().

| vector normal_lb_rng | ( | vector | mu, |
| vector | sigma, | ||
| vector | lb ) |
Generate random samples from a normal distribution with lower bounds
| mu | Vector of means |
| sigma | Vector of standard deviations |
| lb | Vector of lower bounds |
Definition at line 264 of file delays.stan.