primarycensored
Loading...
Searching...
No Matches

Helper functions for analytical solutions. More...

Collaboration diagram for Helpers for Analytical Solutions:

Functions

int check_for_uniform_terms (int dist_id, int primary_id)
 
int check_uniform_terms_params (int dist_id, array[] real params)
 
int check_for_analytical (int dist_id, int primary_id)
 
real primarycensored_uniform_lcdf_from_terms (vector terms_d, vector terms_q, data real pwindow)
 
vector primarycensored_gamma_uniform_terms (real t, array[] real params)
 
vector primarycensored_lognormal_uniform_terms (real t, array[] real params)
 
real log_weibull_g (real t, real shape, real scale)
 
vector primarycensored_weibull_uniform_terms (real t, array[] real params)
 
vector primarycensored_gengamma_uniform_terms (real t, array[] real params)
 
vector primarycensored_exponential_uniform_terms (real t, array[] real params)
 
vector primarycensored_normal_uniform_terms (real t, array[] real params)
 
vector primarycensored_beta_uniform_terms (real t, array[] real params)
 
vector primarycensored_invgamma_uniform_terms (real t, array[] real params)
 
vector primarycensored_pareto_uniform_terms (real t, array[] real params)
 
vector primarycensored_uniform_terms (real t, data int dist_id, array[] real params)
 
int check_for_analytical_vectorized (int dist_id, int primary_id, data real pwindow)
 

Description

Helper functions for analytical solutions.

Function Documentation

◆ check_for_analytical()

int check_for_analytical ( int dist_id,
int primary_id )

Check if an analytical solution exists for the given distribution combination

The non-parametric step (26) and discrete-hazard (27, 28) delays are analytic for every primary primary_lcdf currently supports, the uniform (1) and exponential growth (2). That list is repeated by hand below, so adding a primary to primary_lcdf does not extend the analytic path on its own: without a matching update here the new primary silently falls back to numerical integration.

Parameters
dist_idDistribution identifier for the delay distribution
primary_idDistribution identifier for the primary distribution
Returns
1 if an analytical solution exists, 0 otherwise

Definition at line 60 of file primarycensored_analytical_cdf.stan.

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

◆ check_for_analytical_vectorized()

int check_for_analytical_vectorized ( int dist_id,
int primary_id,
data real pwindow )

Check if the analytical solution can be vectorised over integer delays

The analytical uniform primary CDF at d combines terms at d and at q = max(d - pwindow, 0) (d - pwindow for delays on the reals). With an integer pwindow q is an integer delay too, so primarycensored_analytical_lcdf_vectorized() can compute the terms once per delay and share them. This needs the analytical solutions built from primarycensored_uniform_terms(), see check_for_uniform_terms(). The non-parametric delays in check_for_analytical() have no such terms.

Parameters
dist_idDistribution identifier for the delay distribution
primary_idDistribution identifier for the primary distribution
pwindowPrimary event window
Returns
1 if the vectorised analytical solution applies, 0 otherwise

Definition at line 766 of file primarycensored_analytical_cdf.stan.

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

◆ check_for_uniform_terms()

int check_for_uniform_terms ( int dist_id,
int primary_id )

Check if the analytical solution is built from uniform primary terms

These are the delays whose censored CDF with a uniform primary is primarycensored_uniform_lcdf_from_terms() applied to primarycensored_uniform_terms() at d and q. Some only hold for part of the parameter space, see check_uniform_terms_params().

Parameters
dist_idDistribution identifier for the delay distribution
primary_idDistribution identifier for the primary distribution
Returns
1 if the solution is built from uniform primary terms, 0 otherwise

Definition at line 16 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ check_uniform_terms_params()

int check_uniform_terms_params ( int dist_id,
array[]real params )

Check the uniform primary terms are valid for the delay parameters

The Inverse gamma terms need a finite mean, alpha > 1, and the Inverse chi-square (19) and Scaled inverse chi-square (22) need nu > 2. Otherwise the numerical path is used.

Parameters
dist_idDistribution identifier for the delay distribution
paramsArray of distribution parameters
Returns
1 if the uniform primary terms are valid for the parameters, 0 otherwise

Definition at line 37 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ log_weibull_g()

real log_weibull_g ( real t,
real shape,
real scale )

Compute the log of the lower incomplete gamma function

This function is used in the analytical solution for the primary censored Weibull distribution with uniform primary censoring. It corresponds to the g(t; λ, k) function described in the analytic solutions document.

Parameters
tUpper bound of integration
shapeShape parameter (k) of the Weibull distribution
scaleScale parameter (λ) of the Weibull distribution
Returns
Log of g(t; λ, k) = γ(1 + 1/k, (t/λ)^k)

Definition at line 190 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_beta_uniform_terms()

vector primarycensored_beta_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for a Beta delay

The mean is E = a / (a + b) and the partial expectation distribution is the Beta with shape1 a + 1. For t >= 1 both CDFs are 1.

Parameters
tTime (d or q)
paramsArray of Beta distribution parameters [a, b]
Returns
Vector [log(t * F_T(t)), log(E * tilde F_T(t))], both -inf for t <= 0

Definition at line 341 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_exponential_uniform_terms()

vector primarycensored_exponential_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for an Exponential delay

The antiderivative of F_T is G(t) = t - 1 / rate + exp(-rate * t) / rate, so the terms are [log G(t), -inf]. A series is used below rate * t = 0.1 where the difference cancels.

Parameters
tTime (d or q)
paramsArray of Exponential distribution parameters [rate]
Returns
Vector [log G(t), -inf], both -inf for t <= 0

Definition at line 271 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_gamma_uniform_terms()

vector primarycensored_gamma_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for a Gamma delay

F_T(t; k) comes from F_T(t; k + 1) and the recursion P(k, y) = P(k + 1, y) + y^k e^{-y} / Gamma(k + 1), with y = rate * t, which adds terms so stays accurate in the lower tail. Rejects a rate that is not positive and finite.

Parameters
tTime (d or q)
paramsArray of Gamma distribution parameters [shape, rate]
Returns
Vector [log(t * F_T(t; k)), log(E * F_T(t; k + 1))], both -inf for t <= 0

Definition at line 126 of file primarycensored_analytical_cdf.stan.

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

◆ primarycensored_gengamma_uniform_terms()

vector primarycensored_gengamma_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for a generalised gamma delay

Uses the Stacy parameterisation of flexsurv::pgengamma.orig(), see gengamma_lcdf. The mean is E = scale * Gamma(k + 1/shape) / Gamma(k) and the partial expectation distribution is the generalised gamma with k replaced by k + 1/shape, so this generalises the Gamma (shape = 1) and Weibull (k = 1) solutions.

Parameters
tTime (d or q)
paramsArray of generalised gamma distribution parameters [shape, scale, k]
Returns
Vector [log(t * F_T(t)), log(E * tilde F_T(t))], both -inf for t <= 0

Definition at line 242 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_invgamma_uniform_terms()

vector primarycensored_invgamma_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for an Inverse gamma delay

The mean is E = beta / (alpha - 1) and the partial expectation distribution is the Inverse gamma with shape alpha - 1, so alpha > 1 is required. This is not checked here, so callers must first apply check_uniform_terms_params().

Parameters
tTime (d or q)
paramsArray of Inverse gamma distribution parameters [alpha, beta]
Returns
Vector [log(t * F_T(t)), log(E * tilde F_T(t))], both -inf for t <= 0

Definition at line 441 of file primarycensored_analytical_cdf.stan.

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

◆ primarycensored_lognormal_uniform_terms()

vector primarycensored_lognormal_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for a Lognormal delay

Each term is formed whole and dropped whole. Adding a -inf log CDF to the parameter-dependent log(t) or log_E first would leave an edge back to the parameters that log_sum_exp differentiates to exp(-inf - -inf). t <= 0 underflows on the same test.

Parameters
tTime (d or q)
paramsArray of Lognormal distribution parameters [mu, sigma]
Returns
Vector [log(t * F_T(t)), log(E * tilde F_T(t))]

Definition at line 160 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_normal_uniform_terms()

vector primarycensored_normal_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for a Normal delay

The positive antiderivative of F_T is G(t) = sigma * (z * Phi(z) + phi(z)) with z = (t - mu) / sigma.

Parameters
tTime (d or q)
paramsArray of Normal distribution parameters [mu, sigma]
Returns
Vector [log G(t), -inf]

Definition at line 306 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_pareto_uniform_terms()

vector primarycensored_pareto_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for a Pareto delay

The antiderivative of F_T from y_min is G(t) = y_min * (delta + expm1(-(alpha - 1) * L) / (alpha - 1)), with delta = t / y_min - 1 and L = log(t / y_min). It holds for every alpha > 0. A series in L is used when L * max(1, |alpha - 1|) < 0.1 where the terms cancel.

Parameters
tTime (d or q)
paramsArray of Pareto distribution parameters [y_min, alpha]
Returns
Vector [log G(t), -inf], both -inf for t <= y_min

Definition at line 469 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_uniform_lcdf_from_terms()

real primarycensored_uniform_lcdf_from_terms ( vector terms_d,
vector terms_q,
data real pwindow )

Combine the uniform primary terms at d and q into the censored log CDF

For a delay T with mean E and a uniform primary over a window of width w_P, the primary event censored CDF at d is F_{S+}(d) = (A - B) / w_P, with A = d * F_T(d) + E * tilde F_T(q), B = q * F_T(q) + E * tilde F_T(d), where q = max(d - w_P, 0) and tilde F_T is the CDF of the partial expectation distribution. Each of A and B is a sum of one term at d and one at q, and those terms depend on d or q alone (see primarycensored_uniform_terms()). Ordering A >= B is guaranteed by F_{S+}(d) >= 0.

Delays with support on the reals use q = d - w_P. Delays with one positive antiderivative G of F_T have terms [log G(t), -inf].

Parameters
terms_dTerms at d from primarycensored_uniform_terms()
terms_qTerms at q from primarycensored_uniform_terms()
pwindowPrimary event window
Returns
Log of the primary event censored CDF at d

Definition at line 95 of file primarycensored_analytical_cdf.stan.

Here is the caller graph for this function:

◆ primarycensored_uniform_terms()

vector primarycensored_uniform_terms ( real t,
data int dist_id,
array[]real params )

Compute the uniform primary terms at t for a delay distribution

Parameters
tTime (d or q)
dist_idDistribution identifier (1: Lognormal, 2: Gamma, 3: Weibull, 4: Exponential, 5: Generalised gamma, 9: Beta, 13: Chi-square, 16: Inverse gamma, 18: Normal, 19: Inverse chi-square, 21: Pareto, 22: Scaled inverse chi-square), see check_for_uniform_terms()
paramsArray of distribution parameters
Returns
Vector of the two terms at t, see primarycensored_uniform_lcdf_from_terms()

Definition at line 514 of file primarycensored_analytical_cdf.stan.

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

◆ primarycensored_weibull_uniform_terms()

vector primarycensored_weibull_uniform_terms ( real t,
array[]real params )

Compute the uniform primary terms at t for a Weibull delay

For Weibull, E = scale (lambda) and tilde F_T(t) = g(t; lambda, k).

Parameters
tTime (d or q)
paramsArray of Weibull distribution parameters [shape, scale]
Returns
Vector [log(t * F_T(t)), log(scale * g(t; lambda, k))], both -inf for t <= 0

Definition at line 212 of file primarycensored_analytical_cdf.stan.

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