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_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_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 37 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). 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 455 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.

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 15 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 153 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

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 91 of file primarycensored_analytical_cdf.stan.

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 201 of file primarycensored_analytical_cdf.stan.

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 123 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.

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 68 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, 5: Generalised gamma), 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 229 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 171 of file primarycensored_analytical_cdf.stan.

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