Back to List

Censoring, Kaplan–Meier, and Risk Sets

Learn the core concepts and study-design considerations of Censoring, Kaplan–Meier, and Risk Sets in Python-based biostatistics.

Intermediate
|
35min
|
Verified (2026-08-07)
BioStatPybiostatisticsPythonstudy design
Progress0/33 (0%)

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.

text
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

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

The duration and event examples in this section are synthetic educational examples independently created by BioStatPy.

💬 Questions & Comments

0 comments

You can post without signing in. Guest comments cannot be edited or deleted by their author.

0/2000

Loading...