primarycensored
Loading...
Searching...
No Matches
Log CDFs for the ode function

Helper function to compute the log CDF for the delay distribution. More...

Collaboration diagram for Log CDFs for the ode function:

Functions

real primarycensored_inv_gamma_lcdf (real y, real alpha, real beta)
 
real gamma_lcdf_logx (real log_x, real a)
 
real gamma_log_rate (real rate)
 
real gengamma_lcdf (real y, real shape, real scale, real k)
 
int dist_has_positive_support (data int dist_id)
 
int lognormal_lcdf_underflows (real y, real mu, real sigma)
 
real dist_lcdf (real delay, array[] real params, int dist_id)
 

Description

Helper function to compute the log CDF for the delay distribution.

Function Documentation

◆ dist_has_positive_support()

int dist_has_positive_support ( data int dist_id)

Test whether a delay distribution has support only on the non-negative reals

Used internally to decide whether to short-circuit dist_lcdf at delay <= 0 and whether the ODE / nested CDF calls need to integrate over negative arguments. Returns 1 for distributions with strictly non-negative support, 0 otherwise. IDs match pcd_distributions$stan_id in R.

Parameters
dist_idDistribution identifier
Returns
1 if the delay distribution has non-negative support, 0 otherwise.

Definition at line 91 of file primarycensored_ode.stan.

Here is the caller graph for this function:

◆ dist_lcdf()

real dist_lcdf ( real delay,
array[]real params,
int dist_id )

Compute the log CDF of the delay distribution

Parameters
delayTime delay
paramsDistribution parameters
dist_idDistribution identifier matching pcd_distributions in R: 1: Lognormal, 2: Gamma, 3: Weibull, 4: Exponential, 5: Generalised gamma, 9: Beta, 12: Cauchy, 13: Chi-square, 15: Gumbel, 16: Inverse Gamma, 17: Logistic, 18: Normal, 19: Inverse Chi-square, 20: Double Exponential, 21: Pareto, 22: Scaled Inverse Chi-square, 23: Student's t, 24: Uniform, 25: von Mises, 26: Non-parametric step (params = [boundaries (K+1), pmf (K)], length 2*K + 1), 27/28: Non-parametric discrete hazard (params = [boundaries (K+1), hazards (K)], length 2*K + 1; hazards[K] must equal 1). 27 and 28 share this likelihood and only differ in the prior on the hazards (random walk for 27, IID random effect for 28).
Returns
Log CDF of the delay distribution
// Example: Lognormal distribution
real delay = 5.0;
array[2] real params = {0.0, 1.0}; // mean and standard deviation on log scale
int dist_id = 1; // Lognormal
real log_cdf = dist_lcdf(delay, params, dist_id);
real dist_lcdf(real delay, array[] real params, int dist_id)

Definition at line 165 of file primarycensored_ode.stan.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gamma_lcdf_logx()

real gamma_lcdf_logx ( real log_x,
real a )

Compute the log CDF of a unit rate Gamma distribution from the log of x

Returns log P(a, x) for x = exp(log_x). Below x = (a + 1) / 2 it sums the lower series P(a, x) = x^a exp(-x) / Gamma(a + 1) * (1 + x / (a + 1) + ...) in log space, where gamma_lcdf() underflows and its shape gradient is wrong. The series uses elementary operations, so autodiff is exact. Elsewhere it calls gamma_lcdf().

Parameters
log_xLog of the argument, log(x)
aShape parameter of the Gamma distribution (a > 0)
Returns
log P(a, exp(log_x)). Rejects a shape that is not positive and finite.

Definition at line 18 of file primarycensored_ode.stan.

Here is the caller graph for this function:

◆ gamma_log_rate()

real gamma_log_rate ( real rate)

Compute the log of a Gamma rate

Parameters
rateRate parameter of the Gamma distribution
Returns
log(rate). Rejects a rate that is not positive and finite.

Definition at line 46 of file primarycensored_ode.stan.

Here is the caller graph for this function:

◆ gengamma_lcdf()

real gengamma_lcdf ( real y,
real shape,
real scale,
real k )

Compute the log CDF of the generalised gamma distribution

Uses the Stacy parameterisation of flexsurv::pgengamma.orig() in R. The CDF is the regularised lower incomplete gamma function P(k, (y / scale)^shape), so the Gamma (shape = 1) and Weibull (k = 1) distributions are special cases.

Parameters
yValue at which to evaluate the log CDF (y >= 0)
shapeShape (power) parameter
scaleScale parameter
kShape parameter of the underlying Gamma distribution
Returns
Log CDF of the generalised gamma distribution

Definition at line 69 of file primarycensored_ode.stan.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lognormal_lcdf_underflows()

int lognormal_lcdf_underflows ( real y,
real mu,
real sigma )

Test whether lognormal_lcdf underflows to -inf at these arguments

Underflow makes the autodiff partial 0 / 0, and Stan's reverse pass chains that NaN into mu and sigma whatever weight the term is later given. Callers must therefore test this before calling lognormal_lcdf, rather than checking its result.

The threshold is -38 on the standardised scale (log(y) - mu) / sigma, inside the region where the CDF is still representable: log F(y) is below -726 there, so a term dropped on this test cannot change a result at double precision.

Parameters
yValue at which the log CDF would be evaluated
muLocation parameter on the log scale
sigmaScale parameter on the log scale
Returns
1 if lognormal_lcdf would underflow or y is non-positive, 0 otherwise

Definition at line 127 of file primarycensored_ode.stan.

Here is the caller graph for this function:

◆ primarycensored_inv_gamma_lcdf()

real primarycensored_inv_gamma_lcdf ( real y,
real alpha,
real beta )

Compute the log CDF of an Inverse gamma delay

The CDF is Q(alpha, x) with x = beta / y. It is evaluated on the log scale from the series for P(alpha, x) when x <= alpha + 1 and the continued fraction for Q(alpha, x) (modified Lentz) above. Unlike inv_gamma_lcdf it does not underflow in the lower tail.

Parameters
yPositive value at which the log CDF is evaluated
alphaShape parameter
betaScale parameter
Returns
Log CDF at y. Rejects if the series or continued fraction does not converge.

Definition at line 373 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function: