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§
- Kaplan
Meier - The Kaplan–Meier product-limit estimate of a survival function.
- Life
Table Row - 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_intervalbuilds.
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
kgroups share one survival function. At each distinct event timetwithnat risk in all groups anddevents, groupgwithn_gat risk expectse_g = d·n_g/nevents; the statistic is(O − E)ᵀ V⁻¹ (O − E)overk − 1groups with the hypergeometric covarianceV_{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
Distributionas an expression:S(t) = 1 − F(t), using the family’s closed-form CDF on the support when it has one (soExponential(λ)givese^{−λt}), else the whole-line CDF.