Censoring, Kaplan–Meier, and Risk Sets
Upon completing this topic
You will be able to distinguish event time from censoring in survival data and explain what a risk set at a given time point is. You will read the Kaplan–Meier estimator as a summary of the survival function and reflect in the data structure and code that observation termination does not necessarily mean an event has occurred.
What it means for an event to be unobserved
A row in survival analysis can contain the time from the start of observation to the event or the end of observation, along with whether the event was observed. Set event_observed=1 when the event is observed. If the study ends or follow-up is lost before the event is observed, the observation can be marked as right-censored. Censoring is not synonymous with observing that the event did not occur.
duration: 관찰된 시간
event_observed: 사건 관찰 여부
entry: 관찰에 들어온 시점(사용하는 경우)Risk set
At time t, the risk set is the collection of units that have not yet experienced an event and are observable up to just before that time point. As time progresses, units that have experienced an event or have been censored drop out of the risk set. Therefore, one should not assume that everyone remains in the same denominator throughout the entire follow-up period.
Kaplan–Meier and Python
from lifelines import KaplanMeierFitter
km = KaplanMeierFitter(label="synthetic")km.fit(durations, event_observed=event_observed)survival = km.survival_function_ci = km.confidence_interval_print(survival.head())This code was verified for execution on the lifelines==0.29.0 survival overlay. The official lifelines API KaplanMeierFitter.fit accepts duration and event observation status to provide the survival function and confidence interval in the result object. The resulting survival function is an estimate from synthetic data and does not imply a clinical prognosis for an actual study.
Returning to the research question for interpretation
The Kaplan–Meier curve shows the estimated trajectory of the event-free proportion over time. Median survival may not be calculable in some cases, so one must check the number and timing of censorings alongside the risk set size. One should not confirm causal or treatment effects solely because the curve is high.
Common failures
- Do not code censoring as no event.
- Do not assume all units were observed until the end.
- Do not hide the start point and unit of duration.
- Do not extend survival curves to infer causal effects or clinical recommendations.
Key takeaways
- Duration and event indicator are distinct fields.
- The risk set changes over time.
- Kaplan–Meier is a survival function estimation procedure that accounts for censoring.
Next topic
The next section covers the hazard ratio and proportional hazards assumption of the Cox model.
References
- lifelines KaplanMeierFitter: https://lifelines.readthedocs.io/en/stable/fitters/univariate/KaplanMeierFitter.html
- lifelines Quickstart: https://lifelines.readthedocs.io/en/stable/Quickstart.html
The duration and event examples in this section are synthetic educational examples independently created by BioStatPy.