relife.nonparametric.KaplanMeier
relife.nonparametric.KaplanMeier¶
- class relife.nonparametric.KaplanMeier[source]¶
Bases:
object
Kaplan-Meier Estimator.
Compute the non-parametric Kaplan-Meier estimator (also known as the product limit estimator) of the survival function from lifetime data.
Notes
For a given time instant \(t\) and \(n\) total observations, this estimator is defined as:
\[\hat{S}(t) = \prod_{i: t_i \leq t} \left( 1 - \frac{d_i}{n_i}\right)\]where \(d_i\) is the number of failures until \(t_i\) and \(n_i\) is the number of assets at risk just prior to \(t_i\).
The variance estimation is obtained by:
\[\widehat{Var}[\hat{S}(t)] = \hat{S}(t)^2 \sum_{i: t_i \leq t} \frac{d_i}{n_i(n_i - d_i)}\]which is often referred to as Greenwood’s formula.
References
- 1
Lawless, J. F. (2011). Statistical models and methods for lifetime data. John Wiley & Sons.
- 2
Kaplan, E. L., & Meier, P. (1958). Nonparametric estimation from incomplete observations. Journal of the American statistical association, 53(282), 457-481.
Methods
Fit the Kaplan-Meier estimator to a time, event and entry arrays.
Plot the Kaplan-Meier estimator of the survival function.
- fit(time: numpy.ndarray, event: Optional[numpy.ndarray] = None, entry: Optional[numpy.ndarray] = None) relife.nonparametric.KaplanMeier [source]¶
Fit the Kaplan-Meier estimator to a time, event and entry arrays.
- Parameters
time (1D array) – Array of time-to-event or durations.
event (1D array, optional) –
Array of event types coded as follows:
0 if observation ends before the event has occurred (right censoring)
1 if the event has occured
2 if observation starts after the event has occurred (left censoring)
by default the event has occured for each asset.
entry (1D array, optional) – Array of delayed entry times (left truncation), by default None.
- Returns
Return the fitted Kaplan-Meier estimator as the current object.
- Return type
- plot(alpha_ci: float = 0.05, **kwargs) None [source]¶
Plot the Kaplan-Meier estimator of the survival function.
- Parameters
alpha_ci (float, optional) – \(\alpha\)-value to define the \(100(1-\alpha)\%\) confidence interval, by default 0.05 corresponding to the 95% confidence interval. If set to None or if the model has not been fitted, no confidence interval is plotted.
**kwargs – Extra arguments to specify the plot properties (see matplotlib.pyplot.plot documentation).