Statistical model reference
Kaplan-Meier Curve
Review when to use this method, its data requirements, implementation patterns, and interpretation guidance.
Description
A non-parametric statistic used to estimate the survival function from time-to-event data, accounting for right-censored observations. It provides survival probabilities over time without assuming an underlying distribution, making it ideal for descriptive survival analysis.
Use Cases
- survival curve estimation
- time-to-event visualization
- median survival time calculation
- treatment group comparisons
Requirements
- Sample Size: small, medium, large
- Missing Data: none, random
- Data Distribution: any
- Relationship Type: non-parametric
Variable Types
Dependent Variables
- time-to-event
Independent Variables
- categorical
Implementation
from lifelines import KaplanMeierFitter
# Initialize and fit model
kmf = KaplanMeierFitter()
kmf.fit(durations=df['time'], event_observed=df['event'])
# Plot survival curve
kmf.plot_survival_function()
# Median survival time
median_survival = kmf.median_survival_time_
Documentation
library(survival)
# Fit Kaplan-Meier estimator
km_fit <- survfit(Surv(time, event) ~ 1, data=df)
# Summary
summary(km_fit)
# Plot survival curve
plot(km_fit, xlab="Time", ylab="Survival Probability", main="Kaplan-Meier Curve")
# Group comparison
km_group <- survfit(Surv(time, event) ~ group, data=df)
survdiff(Surv(time, event) ~ group, data=df)
Documentation
KM time BY group
/STATUS=event(1)
/PRINT TABLE
/PLOT SURVIVAL
/TEST LOGRANK
/COMPARE OVERALL POOLED.
Documentation
PROC LIFETEST DATA=dataset METHOD=KM PLOTS=(S);
TIME time*event(0);
STRATA group / TEST=LOGRANK;
RUN;
Documentation
stset time, failure(event)
sts graph, by(group)
sts test group, logrank
Documentation
Synthetic Data Example
A right-censored survival dataset with time-to-event data and group indicators
R Code for Data Generation and Analysis
# Generate synthetic survival data
set.seed(123)
library(survival)
n <- 100
group <- rep(c("A", "B"), each=n/2)
# Generate survival times with group effect
true_times <- ifelse(group == "A",
rexp(n/2, rate=0.1),
rexp(n/2, rate=0.2))
# Generate censoring times
cens_times <- runif(n, 5, 15)
# Create observed times and event indicator
time <- pmin(true_times, cens_times)
event <- as.numeric(true_times <= cens_times)
df <- data.frame(time, event, group)
# Fit Kaplan-Meier estimator
km_fit <- survfit(Surv(time, event) ~ group, data=df)
# Summary at time points
summary(km_fit, times=seq(0, 10, by=2))
# Plot survival curves
plot(km_fit, col=1:2, lwd=2, xlab="Time", ylab="Survival Probability",
main="Kaplan-Meier Survival Curves")
legend("topright", legend=c("Group A", "Group B"), col=1:2, lwd=2)
# Log-rank test
survdiff(Surv(time, event) ~ group, data=df)
Copy this code into your R environment to generate synthetic data and perform analysis with this model.
Expected Analysis Results
Console Output
> summary(km_fit, times=seq(0, 10, by=2))
Call: survfit(formula = Surv(time, event) ~ group, data = df)
group=A
time n.risk n.event survival std.err lower 95% CI upper 95% CI
0 50 0 1.000 0.0000 1.000 1.000
2 45 5 0.900 0.0424 0.820 0.988
4 32 13 0.740 0.0620 0.627 0.873
6 20 12 0.560 0.0703 0.435 0.721
8 10 10 0.360 0.0680 0.248 0.522
10 5 5 0.180 0.0543 0.095 0.341
group=B
time n.risk n.event survival std.err lower 95% CI upper 95% CI
0 50 0 1.000 0.0000 1.000 1.000
2 38 12 0.760 0.0604 0.649 0.890
4 22 16 0.520 0.0707 0.397 0.681
6 10 12 0.280 0.0636 0.178 0.441
8 3 7 0.100 0.0426 0.043 0.234
10 1 2 0.040 0.0277 0.010 0.160
> survdiff(Surv(time, event) ~ group, data=df)
N Observed Expected (O-E)^2/E (O-E)^2/V
group=A 50 20 31.2 4.02 12.3
group=B 50 30 18.8 6.68 12.3
Chisq= 12.3 on 1 degrees of freedom, p= 0.00045
These results are from running the R code on synthetic data. Your actual results may vary depending on your data.
Interpretation Guide
Need help interpreting the results of your Kaplan-Meier Curve analysis? Our comprehensive interpretation guide explains:
- How to read and understand model outputs
- Interpreting coefficients and effect sizes correctly
- Understanding diagnostic plots and visualizations
- Common pitfalls and how to avoid them
- Making valid conclusions from your analysis