![]() |
primarycensored
|
Helper functions for analytical solutions. More...

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) |
Helper functions for analytical solutions.
| 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.
| dist_id | Distribution identifier for the delay distribution |
| primary_id | Distribution identifier for the primary distribution |
Definition at line 60 of file primarycensored_analytical_cdf.stan.


| 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.
| dist_id | Distribution identifier for the delay distribution |
| primary_id | Distribution identifier for the primary distribution |
| pwindow | Primary event window |
Definition at line 766 of file primarycensored_analytical_cdf.stan.


| 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().
| dist_id | Distribution identifier for the delay distribution |
| primary_id | Distribution identifier for the primary distribution |
Definition at line 16 of file primarycensored_analytical_cdf.stan.

| 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.
| dist_id | Distribution identifier for the delay distribution |
| params | Array of distribution parameters |
Definition at line 37 of file primarycensored_analytical_cdf.stan.

| 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.
| t | Upper bound of integration |
| shape | Shape parameter (k) of the Weibull distribution |
| scale | Scale parameter (λ) of the Weibull distribution |
Definition at line 190 of file primarycensored_analytical_cdf.stan.

| 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.
| t | Time (d or q) |
| params | Array of Beta distribution parameters [a, b] |
-inf for t <= 0 Definition at line 341 of file primarycensored_analytical_cdf.stan.

| 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.
| t | Time (d or q) |
| params | Array of Exponential distribution parameters [rate] |
-inf for t <= 0 Definition at line 271 of file primarycensored_analytical_cdf.stan.

| 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.
| t | Time (d or q) |
| params | Array of Gamma distribution parameters [shape, rate] |
-inf for t <= 0 Definition at line 126 of file primarycensored_analytical_cdf.stan.


| 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.
| t | Time (d or q) |
| params | Array of generalised gamma distribution parameters [shape, scale, k] |
-inf for t <= 0 Definition at line 242 of file primarycensored_analytical_cdf.stan.

| 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().
| t | Time (d or q) |
| params | Array of Inverse gamma distribution parameters [alpha, beta] |
-inf for t <= 0 Definition at line 441 of file primarycensored_analytical_cdf.stan.


| 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.
| t | Time (d or q) |
| params | Array of Lognormal distribution parameters [mu, sigma] |
Definition at line 160 of file primarycensored_analytical_cdf.stan.

| 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.
| t | Time (d or q) |
| params | Array of Normal distribution parameters [mu, sigma] |
Definition at line 306 of file primarycensored_analytical_cdf.stan.

| 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.
| t | Time (d or q) |
| params | Array of Pareto distribution parameters [y_min, alpha] |
-inf for t <= y_min Definition at line 469 of file primarycensored_analytical_cdf.stan.

| 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].
| terms_d | Terms at d from primarycensored_uniform_terms() |
| terms_q | Terms at q from primarycensored_uniform_terms() |
| pwindow | Primary event window |
Definition at line 95 of file primarycensored_analytical_cdf.stan.

| vector primarycensored_uniform_terms | ( | real | t, |
| data int | dist_id, | ||
| array[]real | params ) |
Compute the uniform primary terms at t for a delay distribution
| t | Time (d or q) |
| dist_id | Distribution 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() |
| params | Array of distribution parameters |
Definition at line 514 of file primarycensored_analytical_cdf.stan.


| 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).
| t | Time (d or q) |
| params | Array of Weibull distribution parameters [shape, scale] |
-inf for t <= 0 Definition at line 212 of file primarycensored_analytical_cdf.stan.

