sksurv.nonparametric.kaplan_meier_estimator(event, time_exit, time_enter=None, time_min=None, reverse=False, conf_level=0.95, conf_type=None)[source]#

Kaplan-Meier estimator of survival function.

See [1] for further description.

  • event (array-like, shape = (n_samples,)) – Contains binary event indicators.

  • time_exit (array-like, shape = (n_samples,)) – Contains event/censoring times.

  • time_enter (array-like, shape = (n_samples,), optional) – Contains time when each individual entered the study for left truncated survival data.

  • time_min (float, optional) – Compute estimator conditional on survival at least up to the specified time.

  • reverse (bool, optional, default: False) – Whether to estimate the censoring distribution. When there are ties between times at which events are observed, then events come first and are subtracted from the denominator. Only available for right-censored data, i.e. time_enter must be None.

  • conf_level (float, optional, default: 0.95) – The level for a two-sided confidence interval on the survival curves.

  • conf_type (None or {'log-log'}, optional, default: None.) – The type of confidence intervals to estimate. If None, no confidence intervals are estimated. If “log-log”, estimate confidence intervals using the log hazard or \(log(-log(S(t)))\) as described in [2].


  • time (array, shape = (n_times,)) – Unique times.

  • prob_survival (array, shape = (n_times,)) – Survival probability at each unique time point. If time_enter is provided, estimates are conditional probabilities.

  • conf_int (array, shape = (2, n_times)) – Pointwise confidence interval of the Kaplan-Meier estimator at each unique time point. Only provided if conf_type is not None.


Creating a Kaplan-Meier curve:

>>> x, y, conf_int = kaplan_meier_estimator(event, time, conf_type="log-log")
>>> plt.step(x, y, where="post")
>>> plt.fill_between(x, conf_int[0], conf_int[1], alpha=0.25, step="post")
>>> plt.ylim(0, 1)

See also


Estimator API of the Kaplan-Meier estimator.