Non-parametric survival_curve estimators (Kaplan-Meier and Nelson-Aalen).
Classes
Kaplan-Meier product-limit estimator of the survival function.
The non_parametric maximum-likelihood estimate of S(t) = P(T > t) under right-censoring. No covariates: it describes the population as a whole, so it is a baseline every covariate model must beat rather than a per-sample risk model.
Constructor
__init__( self, )
Overview
- Sort the observed times and keep only the times at which an event
timeline_).
- At each event time t_j, compute d_j (events at
- Multiply the survival factors (1 - d_j / n_j) to form the
Theory
The product-limit estimator is
\hat{S}(t) = \prod_{j: t_j \leq t} \left(1 - \frac{d_j}{n_j}\right)
and the corresponding Nelson-Aalen cumulative hazard is
\hat{H}(t) = \sum_{j: t_j \leq t} \frac{d_j}{n_j}.
Censored observations contribute to n_j while they are still at risk, but never contribute an event, which is how the estimator respects partial information.
Parameters
This estimator takes no hyperparameters.
Attributes
timeline_
np.ndarray of shape (n_events,)
Sorted unique event times.
survival_
np.ndarray of shape (n_events,)
Product-limit survival at each
timeline_ entry.
cumulative_hazard_
np.ndarray of shape (n_events,)
Nelson-Aalen cumulative hazard at each
timeline_ entry.
n_risk_
np.ndarray of shape (n_events,)
Number of subjects at risk just before each event time.
n_events_
np.ndarray of shape (n_events,)
Number of events at each event time.
total_cumulative_hazard_
float
Cumulative hazard at the final event time; the constant risk score.
Notes
Complexity:
- Fitting: O(n \log n) (sorting dominates).
- Prediction: O(\log n) per query via binary search.
- As a descriptive summary of a single population's survival curve.
- As the baseline against which covariate models are compared.
- The survival function is only defined up to the last event time; beyond
References
Kaplan1958
Kaplan, E.L. and Meier, P. (1958).
Nonparametric Estimation from Incomplete Observations.
Journal of the American Statistical Association, 53(282), 457-481.
DOI: 10.1080/01621459.1958.10501452
python
>>> from tuiml.algorithms.survival import KaplanMeierEstimator
>>> import numpy as np
>>> km = KaplanMeierEstimator().fit([2, 3, 4, 5], [1, 1, 0, 1])
>>> km.timeline_.tolist()
[2.0, 3.0, 5.0]
>>> np.round(km.survival_, 4).tolist()
[0.75, 0.5, 0.0]
>>> np.round(km.predict_survival_function([1, 2, 3, 4, 5, 6]), 6).tolist()
[1.0, 0.75, 0.5, 0.5, 0.0, 0.0]
Methods
fit
(self, time, event) -> 'KaplanMeierEstimator'
fit
(self, time, event) -> 'KaplanMeierEstimator'
Fit the product-limit estimator.
Parameters
time
array-like of shape (n_samples,)
Observed time (event or censoring).
event
array-like of shape (n_samples,)
Event indicator (1 = event observed, 0 = right-censored).
Returns
self
KaplanMeierEstimator
Fitted estimator.
Nelson-Aalen estimator of the cumulative hazard function.
The non_parametric estimate of the cumulative hazard H(t) = -\log S(t), from which a survival curve \hat{S}(t) = e^{-\hat{H}(t)} follows. Like Kaplan-Meier it is a population-level baseline with no covariates.
Constructor
__init__( self, )
Overview
-
Keep only the event times (
timeline_). - Accumulate the increments d_j / n_j into the cumulative hazard.
- Expose the survival function as \exp(-\hat{H}(t)).
Theory
\hat{H}(t) = \sum_{j: t_j \leq t} \frac{d_j}{n_j}, \qquad \hat{S}(t) = \exp\!\left(-\hat{H}(t)\right).
The Nelson-Aalen estimator has slightly lower finite-sample bias than the Kaplan-Meier estimate of the same quantity and is the canonical input for leaf-hazard conventions in survival ensembles.
Parameters
This estimator takes no hyperparameters.
Attributes
timeline_
np.ndarray of shape (n_events,)
Sorted unique event times.
cumulative_hazard_
np.ndarray of shape (n_events,)
Nelson-Aalen cumulative hazard at each
timeline_ entry.
survival_
np.ndarray of shape (n_events,)
Exponential survival :math:`\exp(-\hat{H}(t))` at each entry.
n_risk_
np.ndarray of shape (n_events,)
Number of subjects at risk just before each event time.
n_events_
np.ndarray of shape (n_events,)
Number of events at each event time.
total_cumulative_hazard_
float
Cumulative hazard at the final event time; the constant risk score.
Notes
Complexity:
- Fitting: O(n \log n) (sorting dominates).
- Prediction: O(\log n) per query via binary search.
References
Nelson1969
Nelson, W. (1969). Hazard Plotting for Incomplete Failure
Data. Journal of Quality Technology, 1(1), 27-52.
Aalen1978
Aalen, O. (1978). Nonparametric Inference for a Family of
Counting Processes. The Annals of Statistics, 6(4), 701-726.
python
>>> from tuiml.algorithms.survival import NelsonAalenEstimator
>>> import numpy as np
>>> na = NelsonAalenEstimator().fit([2, 3, 4, 5], [1, 1, 0, 1])
>>> np.round(na.cumulative_hazard_, 4).tolist()
[0.25, 0.5833, 1.5833]
>>> np.round(na.predict_cumulative_hazard([1, 2, 3, 5]), 4).tolist()
[0.0, 0.25, 0.5833, 1.5833]
Methods
fit
(self, time, event) -> 'NelsonAalenEstimator'
fit
(self, time, event) -> 'NelsonAalenEstimator'
Fit the cumulative-hazard estimator.
Parameters
time
array-like of shape (n_samples,)
Observed time (event or censoring).
event
array-like of shape (n_samples,)
Event indicator (1 = event observed, 0 = right-censored).
Returns
self
NelsonAalenEstimator
Fitted estimator.