EpiNow2 Stan Functions

Functions for modeling the observation process. More...

Collaboration diagram for Observation Model:

Functions

vector day_of_week_effect (vector reports, array[] int day_of_week, vector effect)
 
vector scale_obs (vector reports, real fraction_observed)
 
vector truncate_obs (vector reports, vector trunc_rev_cmf, int reconstruct)
 
void truncation_lp (array[] real truncation_mean, array[] real truncation_sd, array[] real trunc_mean_mean, array[] real trunc_mean_sd, array[] real trunc_sd_mean, array[] real trunc_sd_sd)
 
real reporting_phi (real reporting_overdispersion, int model_type)
 
void report_lp (array[] int cases, array[] int case_times, vector reports, real reporting_overdispersion, int model_type, real weight)
 
vector accumulate_reports (vector reports, array[] int accumulate)
 
vector report_log_lik (array[] int cases, vector reports, real reporting_overdispersion, int model_type, real weight)
 
array[] int report_rng (vector reports, real reporting_overdispersion, int model_type)
 

Description

Functions for modeling the observation process.

This group contains functions related to how infections or reports are observed, including day-of-week effects, reporting delays, and various likelihood models.

Function Documentation

◆ accumulate_reports()

vector accumulate_reports ( vector reports,
array[]int accumulate )

Accumulate reports according to a binary flag at each time point

This function accumulates reports according to a binary flag at each time point.

Parameters
reportsVector of expected reports.
accumulateArray of integers indicating, for each time point, whether to accumulate or not.
Returns
A vector of accumulated reports.
Example
For reports = {10, 12, 8, 15, 20} and accumulate = {0, 1, 0, 0}, index 2 is not separately observed, so its value is rolled forward into index 3 (8 + 12 = 20), giving {10, 12, 20, 15, 20}. This models, for example, a day whose cases are only reported together with the following day's.

Definition at line 206 of file observation_model.stan.

◆ day_of_week_effect()

vector day_of_week_effect ( vector reports,
array[]int day_of_week,
vector effect )

Apply day of the week effect to reports

This function applies a day of the week effect to a vector of reports.

Parameters
reportsVector of reports to be adjusted.
day_of_weekArray of integers representing the day of the week for each report.
effectVector of day of week effects.
Returns
A vector of reports adjusted for day of the week effects.
Example
For reports = {100, 100}, day_of_week = {1, 6} and effect = {0.8, 0.9, 1.0, 1.0, 1.0, 1.1, 1.2} (a week's worth of relative effects, mean 1), scaling by wl = 7 gives {100 * 0.8 * 7, 100 * 1.1 * 7} = {560, 770}.

Definition at line 21 of file observation_model.stan.

◆ report_log_lik()

vector report_log_lik ( array[]int cases,
vector reports,
real reporting_overdispersion,
int model_type,
real weight )

Calculate log likelihood for reported cases

This function calculates the log likelihood for reported cases based on the specified model type.

Parameters
casesArray of integer observed cases.
reportsVector of expected reports.
reporting_overdispersionArray of real values for reporting overdispersion.
model_typeInteger indicating the model type (0 for Poisson, >0 for Negative Binomial).
weightReal value for weighting the log likelihood contribution.
Returns
A vector of log likelihoods for each time point.

Definition at line 234 of file observation_model.stan.

References reporting_phi().

Here is the call graph for this function:

◆ report_lp()

void report_lp ( array[]int cases,
array[]int case_times,
vector reports,
real reporting_overdispersion,
int model_type,
real weight )

Update log density for reported cases

This function updates the log density for reported cases based on the specified model type.

Parameters
casesArray of integer observed cases.
case_timesArray of integer time indices for observed cases.
reportsVector of expected reports.
reporting_overdispersionReal values for reporting overdispersion.
model_typeInteger indicating the model type (0 for Poisson, >0 for Negative Binomial).
weightReal value for weighting the log density contribution.

Definition at line 164 of file observation_model.stan.

References reporting_phi().

Here is the call graph for this function:

◆ report_rng()

array[] int report_rng ( vector reports,
real reporting_overdispersion,
int model_type )

Generate random samples of reported cases

This function generates random samples of reported cases based on the specified model type.

Parameters
reportsVector of expected reports.
reporting_overdispersionReal value for reporting overdispersion.
model_typeInteger indicating the model type (0 for Poisson, >0 for Negative Binomial).
Returns
An array of integer sampled reports.

Definition at line 302 of file observation_model.stan.

References neg_binomial_2_safe_rng(), and reporting_phi().

Here is the call graph for this function:

◆ reporting_phi()

real reporting_phi ( real reporting_overdispersion,
int model_type )

Negative binomial overdispersion for the reporting model

Converts the reporting overdispersion parameter into the phi of the negative binomial. When no overdispersion is modelled a large value is returned so the negative binomial behaves like a Poisson.

Parameters
reporting_overdispersionReal value for reporting overdispersion.
model_typeInteger indicating the model type (0 for Poisson, >0 for Negative Binomial).
Returns
The negative binomial overdispersion phi.
Example
reporting_phi(0.2, 1) returns 1 / 0.2^2 = 25, while reporting_phi(0.2, 0) ignores the overdispersion and returns 1e5.

Definition at line 144 of file observation_model.stan.

Referenced by report_log_lik(), report_lp(), and report_rng().

Here is the caller graph for this function:

◆ scale_obs()

vector scale_obs ( vector reports,
real fraction_observed )

Scale observations by fraction reported

This function scales a vector of reports by a fraction observed.

Parameters
reportsVector of reports to be scaled.
fraction_observedReal value representing the fraction observed.
Returns
A vector of scaled reports.
Example
scale_obs({100, 200, 300}, 0.4) returns {40, 80, 120}.

Definition at line 43 of file observation_model.stan.

◆ truncate_obs()

vector truncate_obs ( vector reports,
vector trunc_rev_cmf,
int reconstruct )

Truncate observed data by a truncation distribution

This function truncates a vector of reports based on a truncation distribution.

Parameters
reportsVector of reports to be truncated.
trunc_rev_cmfVector representing the reverse cumulative mass function of the truncation distribution.
reconstructInteger flag indicating whether to reconstruct (1) or truncate (0) the data.
Returns
A vector of truncated reports.
Example
truncate_obs({100, 100, 100, 100}, {1.0, 0.9, 0.7, 0.4}, reconstruct = 0) multiplies each entry by the matching truncation fraction, returning {100, 90, 70, 40}. Calling truncate_obs() again on that result with reconstruct = 1 divides by the same fractions, recovering {100, 100, 100, 100}.

Definition at line 73 of file observation_model.stan.

◆ truncation_lp()

void truncation_lp ( array[]real truncation_mean,
array[]real truncation_sd,
array[]real trunc_mean_mean,
array[]real trunc_mean_sd,
array[]real trunc_sd_mean,
array[]real trunc_sd_sd )

Update log density for truncation distribution priors

This function updates the log density for truncation distribution priors.

Parameters
truncation_meanArray of real values for truncation mean.
truncation_sdArray of real values for truncation standard deviation.
trunc_mean_meanArray of real values for mean of truncation mean prior.
trunc_mean_sdArray of real values for standard deviation of truncation mean prior.
trunc_sd_meanArray of real values for mean of truncation standard deviation prior.
trunc_sd_sdArray of real values for standard deviation of truncation standard deviation prior.

Definition at line 109 of file observation_model.stan.