epinowcast
Loading...
Searching...
No Matches
primarycensored_pmf.stan File Reference

Go to the source code of this file.

Functions

int enw_to_pcens_dist_id (int dist)
 
array[] real enw_to_pcens_params (real mu, real sigma, int dist)
 
vector log_hazard_to_logit_hazard (vector lhaz)
 
vector lprob_to_log_hazard (vector lprob, int u)
 
vector discretised_pcens_logit_hazard (real mu, real sigma, int dmax, int dist, int ref_as_p)
 

Function Documentation

◆ discretised_pcens_logit_hazard()

vector discretised_pcens_logit_hazard ( real mu,
real sigma,
int dmax,
int dist,
int ref_as_p )

Discretise a parametric delay distribution using primary event censoring

Computes the log probability mass function of a double interval censored delay distribution using the vendored primarycensored Stan functions and, optionally, converts it to logit hazards (the output contract of log_hazard_to_logit_hazard()).

Parameters
muLocation parameter of the parametric distribution (epinowcast transformed scale).
sigmaScale parameter of the parametric distribution (epinowcast transformed scale).
dmaxMaximum possible delay. The distribution is discretised over delays 0 to (dmax - 1) and normalised over that range.
distepinowcast model_refp distribution id (1: exponential, 2: lognormal, 3: gamma).
ref_as_pFlag indicating whether to return log probabilities directly (1) or to convert to logit hazards (0).
Returns
A vector of logit hazards or log probabilities of the discretised distribution, representing discrete delays from 0 to (dmax - 1).
Note
Uses a uniform primary event window of width 1 and assumes an integer secondary censoring window of width 1, matching epinowcast's daily discretisation. Right truncation is applied at dmax via the primarycensored D argument.

Definition at line 178 of file primarycensored_pmf.stan.

◆ enw_to_pcens_dist_id()

int enw_to_pcens_dist_id ( int dist)

Primary event censored discretisation wrapper for epinowcast

Wraps the vendored primarycensored Stan functions (see primarycensored.stan) to discretise a parametric reference date delay distribution. This accounts for double interval censoring: a uniform primary event window convolved with a secondary reporting interval, with right truncation at the maximum delay. Translate an epinowcast distribution id to a primarycensored dist_id

epinowcast uses model_refp ids (1: exponential, 2: lognormal, 3: gamma) which differ from primarycensored's pcd_stan_dist_id() convention (1: lognormal, 2: gamma, 3: weibull, 4: exponential). This function maps the supported epinowcast ids onto the primarycensored ids.

Parameters
distepinowcast model_refp distribution id.
Returns
The corresponding primarycensored dist_id.
Note
The exponential (epinowcast id 1) is routed through the primarycensored gamma id (2) as a Gamma(shape = 1) special case, which uses the analytical gamma-uniform solution rather than the slower per-delay integration of primarycensored's standalone exponential id (4).
The log-logistic distribution is unsupported pending primarycensored support (see https://github.com/epinowcast/primarycensored/issues/321); any other id is rejected.

Definition at line 33 of file primarycensored_pmf.stan.

◆ enw_to_pcens_params()

array[] real enw_to_pcens_params ( real mu,
real sigma,
int dist )

Translate epinowcast (mu, sigma) parameters to primarycensored parameters

epinowcast parameterises its parametric reference delay distributions on a transformed scale (e.g. log rate for the exponential, log shape for the gamma). The vendored primarycensored functions expect the native Stan parameterisation. This function performs the translation.

Parameters
muLocation parameter on the epinowcast transformed scale.
sigmaScale parameter on the epinowcast transformed scale.
distepinowcast model_refp distribution id.
Returns
A length two array of native primarycensored distribution parameters.

Definition at line 60 of file primarycensored_pmf.stan.

◆ log_hazard_to_logit_hazard()

vector log_hazard_to_logit_hazard ( vector lhaz)

Convert log hazards to logit hazards

Transforms log hazards to logit hazards without converting to the natural scale.

Parameters
lhazVector of log hazards.
Returns
Vector of logit hazards.
Note
The final hazard is fixed to 1, so its logit hazard is +Inf and all remaining mass is reported at the maximum delay.

Definition at line 97 of file primarycensored_pmf.stan.

◆ lprob_to_log_hazard()

vector lprob_to_log_hazard ( vector lprob,
int u )

Convert a proper discretised log PMF to logit hazards

Computes logit hazards from a non-overlapping discretised log PMF (such as the one returned by the primarycensored functions) using the standard discrete survival hazard h_d = p_d / S_{d-1}, where the survival function is S_{d-1} = 1 - sum_{i < d} p_i.

Parameters
lprobVector of log probabilities, one per discrete delay 0:(u - 1).
uNumber of discrete delays (length of lprob).
Returns
Vector of logit hazards matching the output contract of log_hazard_to_logit_hazard().
Note
The final hazard is fixed to 1 (logit hazard +inf) so that all remaining probability mass is reported at the maximum delay.

Definition at line 124 of file primarycensored_pmf.stan.