mixle.ppl.survival module

Censored and truncated maximum-likelihood fitting for the mixle PPL.

Survival / reliability / detection-limit data are partially observed: a subject still alive at the end of a study, a component that had not failed, or a measurement below an instrument’s threshold are all right-censored – we know only that the value exceeds some bound. Truncation is the dual: the sample is drawn conditionally on lying in a window (values outside it are never seen). The ordinary likelihood is wrong for both; this module fits a distribution’s free parameters under the correct one, using each distribution’s cdf. It closes the censored-leaf gap (a capability Stan has and most PPLs lack a clean surface for).

censored_loglik(dist, time, *, event=None, lower=None, upper=None)[source]

Total log-likelihood of right-censored and/or truncated time under a fitted dist.

event[i] true (default all true) means time[i] is an observed event contributing log f(time[i]); false means it is right-censored, contributing the log-survival log(1 - F(time[i])). lower/upper truncate the support: every point then also subtracts log(F(upper) - F(lower)) (use None for an open end). Requires dist.cdf.

Parameters:

time (Sequence[float])

Return type:

float

fit_censored(model, time, *, event=None, lower=None, upper=None, seed=0)[source]

Fit a distribution’s free parameters to right-censored and/or truncated data by ML.

model is a flat PPL distribution with free parameter slots, e.g. Weibull(free, free) or Exponential(free). time are the (possibly censored) values; event flags which are observed events vs right-censored (default all observed); lower/upper mark truncation of the sampling window. Maximizes censored_loglik() over the free slots (Nelder-Mead in the unconstrained space, respecting each slot’s positivity/unit support) and returns the fitted model as a bound RandomVariable (with .summary()).

Parameters:
Return type:

RandomVariable

kaplan_meier(time, event=None)[source]

Kaplan-Meier nonparametric survival estimate S(t) from right-censored data.

Returns {'time', 'survival', 'at_risk', 'events'} over the distinct event times – the standard model-free survival curve to plot against, or compare a fitted parametric model to.

Parameters:
Return type:

dict[str, ndarray]