Skip to main content

Module survival

Module survival 

Source
Expand description

Time-to-event analysis with right censoring, exactly: how long until a respondent completes (or abandons) a task, how long a worker stays active, how long an item takes to reach agreement.

Each observation is a (time, event) pair: event = true means the event happened at time, false that the subject was only observed until time (censored). The Kaplan–Meier estimator of the survival function S(t) = P(T > t) is a step function whose steps are exact rationals, as are Greenwood’s variance and the Nelson–Aalen cumulative hazard; the log-rank test compares the survival of groups with an exact χ² statistic. statsmodels.duration.survfunc.{SurvfuncRight, survdiff} are the references named in the tests.

use symplex::linprog::q;
use symplex::stats::survival::{KaplanMeier, Observation};

let obs = Observation::from_i64(&[3, 5, 6, 7, 8, 10, 12, 12], &[true, false, true, true, false, true, true, false]);
let km = KaplanMeier::fit(&obs)?;
// statsmodels SurvfuncRight: S(3) = 0.875, S(6) = 0.7291666…, S(7) = 0.5833…
assert_eq!(km.survival_at(&q(3, 1)), q(7, 8));
assert_eq!(km.survival_at(&q(6, 1)), q(35, 48));
assert_eq!(km.median(), Some(q(10, 1)));

Structs§

KaplanMeier
The Kaplan–Meier product-limit estimate of a survival function.
LifeTableRow
One distinct event time in a life table.
Observation
One subject: the time observed and whether the event occurred then (true) or the observation was censored (false).

Enums§

CiMethod
Which pointwise confidence interval KaplanMeier::confidence_interval builds.

Functions§

exponential_rate
The exponential hazard rate estimate λ̂ = events / total time at risk (the MLE under right censoring), exactly, with the number of events.
hazard_function
The hazard function of a continuous Distribution: h(t) = f(t) / S(t), as an expression valid on the support.
log_rank_test
The log-rank (Mantel–Cox) test that k groups share one survival function. At each distinct event time t with n at risk in all groups and d events, group g with n_g at risk expects e_g = d·n_g/n events; the statistic is (O − E)ᵀ V⁻¹ (O − E) over k − 1 groups with the hypergeometric covariance V_{gh} = Σ_t d (n − d) / (n − 1) · (n_g/n) (δ_{gh} − n_h/n), an exact rational, referred to χ²(k − 1). statsmodels.duration.survfunc.survdiff.
mean_event_time
The mean of the uncensored event times (a naive summary; biased under censoring — prefer KaplanMeier::restricted_mean).
survival_function
The survival function of a Distribution as an expression: S(t) = 1 − F(t), using the family’s closed-form CDF on the support when it has one (so Exponential(λ) gives e^{−λt}), else the whole-line CDF.