epinowcast
discretised_logit_hazard.stan File Reference

Go to the source code of this file.

Functions

real loglogistic_lcdf (real y, real alpha, real beta)
 
vector lcdf_discretised (real mu, real sigma, int u, int dist)
 
vector normalise_lcdf_as_uniform_double_censored (vector lcdf, int u, int max_strat)
 
vector lcdf_to_uniform_double_censored_log_prob (vector lcdf, int u)
 
vector lprob_to_uniform_double_censored_log_hazard (vector lprob, vector lcdf, int u)
 Compute discretised logit hazard. More...
 
vector log_hazard_to_logit_hazard (vector lhaz)
 
vector discretised_logit_hazard (real mu, real sigma, int dmax, int dist, int max_strat, int ref_as_p)
 

Function Documentation

◆ discretised_logit_hazard()

vector discretised_logit_hazard ( real  mu,
real  sigma,
int  dmax,
int  dist,
int  max_strat,
int  ref_as_p 
)

Calculate logit hazard or log probability for discretised delay distribution

Computes logit hazards or log probabilities for a specified discretised parametric distribution up to a maximum possible delay. Employs various normalisation strategies and assumes that delays are double-censored and that the interval width is approximately uniformly distributed.

Parameters
muLocation parameter of the parametric distribution.
sigmaScale parameter of the parametric distribution.
dmaxMaximum possible delay. The parametric distribution will be truncated at dmax.
distDistribution type indicator (e.g., exponential, lognormal, ...).
max_stratStrategy for normalising LCDF values (e.g., handling probability mass beyond the maximum observed value).
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
This function integrates several steps:
  1. Generates LCDF values using lcdf_discretised.
  2. Normalises these LCDF values with normalise_lcdf_as_uniform_double_censored.
  3. Converts LCDF to log probabilities using lcdf_to_uniform_double_censored_log_prob.
  4. If ref_as_p is 0, further processes these probabilities into logit hazards using lprob_to_uniform_double_censored_log_hazard and log_hazard_to_logit_hazard.

Dependencies:

  • lcdf_discretised
  • normalise_lcdf_as_uniform_double_censored
  • lcdf_to_uniform_double_censored_log_prob
  • lprob_to_uniform_double_censored_log_hazard
  • log_hazard_to_logit_hazard

Definition at line 286 of file discretised_logit_hazard.stan.

◆ lcdf_discretised()

vector lcdf_discretised ( real  mu,
real  sigma,
int  u,
int  dist 
)

Compute the discretised LCDF for various distributions

Computes the LCDF at integer points from 1 to u for a selected parametric distribution. Supports exponential, lognormal, gamma, and log-logistic distributions.

Parameters
muLocation parameter for the distribution.
sigmaScale parameter for the distribution.
uUpper bound of the discretised LCDF.
distInteger flag for distribution type (1: exponential, 2: lognormal, 3: gamma, 4: log-logistic).
Returns
Vector of LCDF values for the specified distribution.
Note
Uses loglogistic_lcdf for the log-logistic distribution.

Definition at line 40 of file discretised_logit_hazard.stan.

◆ lcdf_to_uniform_double_censored_log_prob()

vector lcdf_to_uniform_double_censored_log_prob ( vector  lcdf,
int  u 
)

Compute LPMF from discretised LCDF under double censoring

Converts LCDF values to log-scale probability mass function (LPMF) assuming double censoring and a uniform interval approximation. Suitable for discretised LCDFs evaluated at integers 1 to u.

Parameters
lcdfVector of LCDF values.
uUpper bound of the discretised LCDF / LPMF.
Returns
Vector of log-scale PMF values.
Note
While the elements of the LCDF vector correspond to delays 1 to u, the elements of the PMF correspond to delays 0:(u-1). Hence, log(p_0) = lpmf[1].
Processes output of normalise_lcdf_as_uniform_double_censored.

Definition at line 138 of file discretised_logit_hazard.stan.

◆ log_hazard_to_logit_hazard()

vector log_hazard_to_logit_hazard ( vector  lhaz)

Convert log hazards to logit hazards efficiently

Transforms log hazards to logit hazards without converting to the natural scale. Used in the final step of converting discretised probability distributions to logit hazards.

Parameters
lhazVector of log hazards.
Returns
Vector of logit hazards.
Note
Final transformation step in discretised_logit_hazard.

Definition at line 233 of file discretised_logit_hazard.stan.

◆ loglogistic_lcdf()

real loglogistic_lcdf ( real  y,
real  alpha,
real  beta 
)

Compute the log cumulative distribution function (LCDF) for a log-logistic distribution

Calculates the LCDF of a log-logistic distribution for a given value using specified scale and shape parameters.

Parameters
yThe value at which to compute the LCDF.
alphaScale parameter of the log-logistic distribution (alpha > 0).
betaShape parameter of the log-logistic distribution (beta > 0).
Returns
The log-logistic LCDF of y.

Definition at line 16 of file discretised_logit_hazard.stan.

◆ lprob_to_uniform_double_censored_log_hazard()

vector lprob_to_uniform_double_censored_log_hazard ( vector  lprob,
vector  lcdf,
int  u 
)

Compute discretised logit hazard.

Compute logit hazards from log probabilities.

Derives logit hazards from log probabilities of a delay LPMF, assuming double censoring and a uniform interval approximation for discretised delays.

Parameters
lprobVector of log probabilities from the LPMF.
lcdfVector of corresponding LCDF values for the LMPF. This could also be computed from lprob, but by re-using the precomputed LCDF from elsewhere we reduce overall computation.
uUpper bound of discretised LCDF.
Returns
Vector of logit hazards.
Note
While the elements of the LCDF vector correspond to delays 1 to u, the elements of the PMF correspond to delays 0:(u-1). Hence, log(h_0) = lhaz[1].
Processes output of lcdf_to_uniform_double_censored_log_prob and `normalise_lcdf_as_uniform_double_censored

\[ \begin{align*} \text{Let } & h_d = \text{ hazard at delay } d, \\ & p_d = \text{ probability at delay } d, \\ & F_d = \text{ cumulative distribution function (cdf) evaluated at } d, \\ & 1 - F_d = \text{ complementary cumulative distribution function (ccdf) evaluated at } d. \\ \\ % Hazard definition h_d &= \frac{p_d}{1 - \sum_{i=0}^{d-1} p_i} \\ &= \frac{F_{d+1} - F_{d-1}}{1 - \sum_{i=0}^{d-1} (F_{i+1} - F_{i-1})} \\ &= \frac{F_{d+1} - F_{d-1}}{1 - (F_d + F_{d-1})} \\ &= \frac{F_{d+1} - F_{d-1}}{(1 - F_d) - F_{d-1}}. \\ \\ % Log transformation \log(h_d) &= \log(F_{d+1} - F_{d-1}) - \log((1 - F_d) - F_{d-1}). \end{align*} \]

Definition at line 195 of file discretised_logit_hazard.stan.

◆ normalise_lcdf_as_uniform_double_censored()

vector normalise_lcdf_as_uniform_double_censored ( vector  lcdf,
int  u,
int  max_strat 
)

Normalise a discretised LCDF under double censoring

Adjusts LCDF values for the probability mass beyond the upper bound of the discretised LCDF, assuming double censoring and a uniform interval approximation. Different strategies are applied depending on max_strat.

Parameters
lcdfVector of LCDF values to be adjusted.
uUpper bound of the discretised LCDF.
max_stratStrategy for handling probability mass beyond upper bound.
Returns
Vector of adjusted LCDF values.
Note
Used on the output of lcdf_discretised.

Definition at line 84 of file discretised_logit_hazard.stan.