
Kaplan-Meier Curve, Log-rank Test & Cox Regression Guide
How to read a Kaplan-Meier curve, run a log-rank test and interpret Cox regression hazard ratios, with data format, censoring and number-at-risk tips.
Your study compares outcomes between two groups of patients, and the endpoint is "time from surgery to recurrence." Some patients relapsed, some were still recurrence-free at the last follow-up, and some were lost to follow-up. You cannot simply use a t-test to compare average times between groups — because for the patients who did not relapse, you do not know what their true recurrence time would have been.
This is why you need survival analysis. Below we walk through data setup, Kaplan-Meier curves, the log-rank test, and Cox regression (if your clinical spreadsheet is already prepared, see how Data2Paper runs this pipeline below).
What is survival analysis?
Survival analysis is a family of statistical methods designed to handle time-to-event data. The "event" does not have to be death — it can be any outcome of interest:
- Tumor recurrence
- Disease progression
- Postoperative complication
- Graft failure
- Patient death
The core advantage of survival analysis is that it correctly handles censored data — individuals who have not yet experienced the event by the end of the observation period. If you exclude these patients, you introduce serious bias. If you treat their follow-up time as an event time, your results are equally wrong. Survival analysis provides a mathematical framework to make proper use of this incomplete information.
What format does your data need?
For survival analysis, each patient needs at least two variables:
- Time variable: Duration from the starting point to event occurrence or censoring. The starting point is typically the date of diagnosis, surgery, or enrollment. Units can be days, months, or years, but must be consistent
- Status variable (event indicator): Marks whether the patient experienced the event. Typically coded as 1 = event occurred, 0 = censored
For example:
| Patient ID | Follow-up (months) | Event status | Group |
|---|---|---|---|
| 001 | 24 | 1 (recurrence) | Treatment |
| 002 | 36 | 0 (censored) | Control |
| 003 | 12 | 1 (recurrence) | Treatment |
| 004 | 30 | 0 (censored) | Treatment |
What counts as censoring?
- The patient has not experienced the event by the end of the study
- The patient was lost to follow-up
- The patient withdrew for reasons unrelated to the study event (e.g., relocation, refusal to continue)
The most common data preparation errors are inconsistent time calculations (some measured from diagnosis, others from surgery) and inaccurate censoring status. Verify carefully before starting analysis.
The Kaplan-Meier method
The Kaplan-Meier (KM) method is the most fundamental and widely used survival analysis tool. It estimates the survival function — the probability that a patient has not yet experienced the event at any given time point t.
How to read a KM curve
The x-axis of a KM curve is time, and the y-axis is survival probability (0 to 1, or 0% to 100%):
- The curve starts at 1.0 (100%) in the upper left
- Each time a patient experiences an event, the curve drops by a step
- Censored observations are typically marked with small tick marks or plus signs on the curve — the curve does not drop at these points, but the number at risk decreases
- A flatter curve indicates a lower event rate and better prognosis
- Greater separation between two curves indicates a larger difference between groups
Median survival time
The median survival time is the time value where the KM curve crosses the 50% survival probability line. It means that half of the patients experienced the event before this time point.
If the curve stays above 50% throughout (meaning more than half of patients did not experience the event during observation), the median survival time cannot be calculated — this is common in studies with favorable prognosis.
Number at risk table
A properly formatted KM plot includes a risk table below the curve showing how many patients remain "at risk" at each time point. This table matters because estimates in the later portion of the curve are often based on very few patients and have low precision. If only 5 patients remain at a given time point, fluctuations in the curve are not reliable.
The Log-rank test
KM curves show visual differences, but you need a statistical test to determine whether the difference between groups is statistically significant.
The Log-rank test is the standard method. It works by comparing the observed versus expected number of events at each event time point across groups.
- Null hypothesis: The survival curves of the two groups are identical
- Output: A chi-square statistic and p-value
- Assumption: The hazard ratio between groups is approximately constant over the follow-up period (i.e., the KM curves do not cross)
If the KM curves cross (for example, one treatment works better short-term but worse long-term), the Log-rank test loses power. In such cases, consider alternative tests (e.g., Wilcoxon test or piecewise analysis).
Cox proportional hazards regression
The Log-rank test tells you whether two groups differ but not how large the difference is, and it cannot adjust for confounders. That is where Cox regression comes in.
Cox proportional hazards regression is the most important multivariable method in survival analysis (our Cox regression guide covers it step by step). Its output is the hazard ratio (HR):
- HR = 1: Equal risk in both groups
- HR > 1: The factor increases event risk (worse prognosis)
- HR < 1: The factor decreases event risk (better prognosis)
For example, "HR for the treatment group versus control = 0.62 (95% CI: 0.45–0.85, p = 0.003)" means that after adjusting for other variables, the treatment group had a 38% lower hazard of the event compared to controls. For more on interpretation, see hazard ratio explained.
The proportional hazards assumption
The key assumption of Cox regression is the proportional hazards assumption: the hazard ratio between groups remains constant throughout the follow-up period.
Methods for checking this include:
- Schoenfeld residual test: A significant p-value indicates violation of the proportional hazards assumption
- Visual inspection of KM curves: If curves cross, the assumption is likely violated
If the assumption does not hold, consider stratifying by time or using a time-dependent Cox model.
Multivariable Cox regression
In practice, Cox regression is typically reported in two stages:
- Univariable analysis: Test each variable individually against the outcome and select significant ones (usually p < 0.1 or p < 0.2 as inclusion criteria)
- Multivariable analysis: Enter all selected variables simultaneously to obtain adjusted HRs
Multivariable Cox regression results are usually presented as forest plots with HR on the x-axis (log scale) and a reference line at HR = 1. This is one of the most common result presentations in clinical papers.
Common pitfalls
1. Inconsistent starting points
Some patients are measured from diagnosis date, others from surgery date. The starting point must be clearly defined in the study design and strictly consistent in the data.
2. Informative censoring
If a patient is lost to follow-up because their condition worsened and they transferred to another hospital, this censoring is related to the event itself, violating the fundamental assumption of survival analysis. The impact of this bias should be discussed in the paper. Censoring and follow-up problems are especially common in chart-review data; see our guide to the retrospective study design.
3. Insufficient sample size
Cox regression typically requires at least 10–20 events per predictor variable. If you have only 30 events total, you can include at most 2–3 variables. Including too many variables leads to model overfitting.
4. Reporting p-values without HRs
Many novice researchers write "the difference was statistically significant (p < 0.05)" without reporting the HR and 95% CI. Reviewers will almost certainly request this information.
The manual workflow problem
Running survival analysis in SPSS requires manually setting time and event variables, iteratively building models, and manually formatting KM plots. R is more flexible but has a steeper learning curve — the parameters for the survival and survminer packages alone take time to master.
The presentation of survival analysis results also involves many details: KM plots need risk tables, Cox regression needs forest plots, and you need to report proportional hazards assumption tests. Each detail requires additional code and formatting work.
FAQ
What does "number at risk" mean on a Kaplan-Meier curve?
It is the count of patients still under observation, with no event and not yet censored, at each time point. It is shown in a table below the curve. When the number at risk gets small, the right-hand end of the curve rests on very few patients and should be read with caution.
What is the difference between Kaplan-Meier and a life table?
Both estimate survival over time. The Kaplan-Meier method recalculates survival at every exact event time, so it suits individual patient data. The actuarial life table groups follow-up into fixed intervals (for example, yearly), which suits large cohorts or data that is only available in intervals.
Kaplan-Meier vs Cox regression: what is the difference and when should I use each?
Kaplan-Meier is a non-parametric method that estimates and plots survival probabilities over time for one or more groups (paired with a log-rank test to ask whether the survival curves differ), whereas Cox regression is a multivariable model used when you need the size of the effect (a hazard ratio) or need to adjust for covariates such as age or stage. Most clinical papers report both together—and if your dataset has time-to-event and censoring columns, Data2Paper's Generate Paper workflow can run Kaplan-Meier curves and Cox models in a single pass.
Can I calculate median survival if the curve never drops below 50%?
No. If more than half of the patients have not had the event by the end of follow-up, the median is not reached. Report it as "not reached" and give survival rates at fixed time points (for example, 1-year and 3-year survival) instead.
How Data2Paper fits into this workflow
Data2Paper does not have a fixed, menu-style survival module. When you choose the Medical Research analysis type, an AI agent writes and runs Python on your uploaded file. If the data has a clear time-to-event column and an event status column (plus a group variable or covariates), it can run Kaplan-Meier curves, log-rank tests and Cox regression and draft the Methods and Results with tables, figures and interpretation text.
What you get depends on your data: if the time or event columns are missing, ambiguous or coded inconsistently, the analysis may differ from what is described in this guide. Upload a CSV, XLSX or XLS file (up to 10MB) and describe your research question so the agent knows which outcome and groups to analyze.
Every job is generated free, so you can preview the first half of the draft before deciding to unlock the full paper for a one-time $19.90. It is an AI-generated draft without expert review: check the time and event coding and the model results against your own data.
Author

Categories
More Posts

Hazard Ratio: Meaning, Interpretation, and Reporting
What a hazard ratio means, how to read it with its 95% CI, how it differs from relative risk and odds ratio, and how to report it in APA 7.


Response to Reviewers Template (With Examples)
A copyable response to reviewers template with point-by-point structure, tone tips, and polite ways to disagree with a reviewer comment.


Content Validity: How to Calculate CVI and CVR
Learn how to assess content validity with an expert panel: I-CVI, S-CVI/Ave, S-CVI/UA, and Lawshe's CVR, with a worked example and APA reporting.

Newsletter
Join the community
Subscribe to our newsletter for the latest news and updates