epinowcast
log_expected_latent_from_r.stan File Reference

Go to the source code of this file.

Functions

array[] vector log_expected_latent_from_r (matrix lexp_latent_int, vector r, array[] int r_g, int r_t, int r_seed, int gt_n, vector lrgt, int t, int g)
 

Function Documentation

◆ log_expected_latent_from_r()

array[] vector log_expected_latent_from_r ( matrix  lexp_latent_int,
vector  r,
array[]int  r_g,
int  r_t,
int  r_seed,
int  gt_n,
vector  lrgt,
int  t,
int  g 
)

Iteratively compute expected latent values using the renewal equation

This function calculates expected latent values over time for different groups using the renewal equation. It's designed to handle scenarios where the generation time is represented either as a constant (leading to exponential growth) or as a vector (requiring a dot product calculation). The function operates on the natural scale for stability and then transforms the results back to the log scale when the generation time is a vector.

Parameters
lexp_latent_intMatrix of initial log expected latent values.
rVector representing growth rate or the log of the effective reproduction number.
r_gArray of indices marking the start of each group in the rate vector.
r_tNumber of time periods for rate adjustments.
r_seedSeed time period for rate-based adjustments.
gt_nLength of the generation time vector (1 for constant generation time).
lrgtLog of the generation time vector or scalar.
tTotal number of time periods.
gNumber of groups.
Returns
An array of vectors containing log-transformed expected latent values for each group and time period.
Note
The function performs the following operations:
  1. For each group: a. Extracts a segment of rates specific to the current group. b. If 'gt_n' is 1 (constant generation time), directly applies a cumulative sum on the log scale to model exponential growth. c. If 'gt_n' > 1 (vector generation time): i. Converts the log rate and log initial latent values to the natural scale. ii. Uses a dot product with the generation time vector for each time point, following the renewal equation. iii. Converts the resulting expected values back to the log scale, as this approach is expected to be more numerically stable than performing the renewal equation directly in log space.

Definition at line 49 of file log_expected_latent_from_r.stan.