Log-Rank Test

Introduction
The Log-Rank Test checks whether two or more groups have a genuinely different survival experience over time-whether their Kaplan-Meier survival curves are truly different, not just different by chance-while correctly handling censored subjects, the ones who hadn't experienced the event by the time the study ended. If you've ever needed to know whether a new treatment keeps patients alive longer than the standard of care, or whether one machine model fails later than another, this is usually the first test you reach for.
By the end of this article you will be able to state exactly when a Log-Rank Test applies, compute the observed-versus-expected statistic completely by hand on two contrasting worked examples, understand why the test can miss a real difference when survival curves cross, know when to reach for a weighted variant or the Cox Proportional Hazards Model instead, and run the same test in one line of Python with lifelines.
What Is the Log-Rank Test?
Developed independently by Nathan Mantel and by Richard and Julia Peto in the 1960s and 70s, the Log-Rank Test is the standard non-parametric way to compare survival between groups. Rather than assuming survival times follow any particular distribution, it works directly with the sequence of observed event times across all groups combined, comparing how many events actually occurred in each group against how many would be expected if every group truly shared the same survival experience.
At each distinct event time, everyone still under observation forms the "risk set." If the groups genuinely have identical survival, the events happening at that moment should split across the groups in proportion to each group's share of the risk set. The Log-Rank Test sums up how far the actual split deviates from that expectation, across every event time in the study, into a single chi-square statistic.
When to Use It
Use a Log-Rank Test whenever your outcome is time until an event, some subjects may be censored, and you want to compare survival between a small number of discrete groups-without needing to adjust for continuous covariates, in which case the Cox Proportional Hazards Model is the more appropriate tool.
| Scenario | Groups Compared | What's Being Checked |
|---|---|---|
| Clinical trials | Treatment vs control | Whether the treatment arm survives significantly longer |
| Oncology research | Tumor stage groups | Whether time-to-progression differs across disease stages |
| Reliability engineering | Manufacturing batch A vs B | Whether time-to-failure differs between production batches |
| Customer analytics | Pricing plan groups | Whether time-to-cancellation differs by plan type |
| Public health | Vaccinated vs unvaccinated | Whether time-to-infection differs between the two groups |
The key requirement: a time-to-event outcome, at least some censored observations, and a small, fixed number of groups you want to compare directly-if you also need to adjust for continuous covariates, see the Cox Proportional Hazards Test instead.
Key Assumptions
- Non-informative censoring. Censoring must be unrelated to a subject's underlying risk of the event-a subject shouldn't be more or less likely to drop out precisely because their risk is unusually high or low.
- Independence of observations. Subjects' event times are assumed independent of one another, which can be violated by clustered data such as patients within the same hospital.
- Groups are pre-specified, not derived from the data. Comparing groups that were formed by first looking at outcomes (rather than defined in advance) invalidates the test's p-value.
- Reasonably proportional hazards between groups. The standard test is most powerful when one group's risk stays consistently higher or lower than another's throughout follow-up; it loses power when survival curves cross, as discussed in Weighted Variants.
- Random or representative sampling. As with most inferential tests, the groups should reasonably represent the populations you intend to generalize the conclusion to.
Hypotheses
For comparing survival between \( k \) groups:
- Null Hypothesis (\( H_0 \)): all \( k \) groups share the same underlying survival function-there is no difference in survival between groups at any point in time.
- Alternative Hypothesis (\( H_1 \)): at least one group has a different survival function from the others.
(For the common two-group case, \( H_1 \) simplifies to: the survival function of group 1 differs from the survival function of group 2. A significant result identifies that a difference exists but, on its own, does not say at which specific time points the curves diverge most.)
The Formula, Explained
Let \( t_1 < t_2 < \cdots < t_m \) be the distinct event times across both groups combined. At each event time \( t_j \), define:
- \( n_{1j}, n_{2j} \): number of subjects at risk in group 1 and group 2 just before \( t_j \)
- \( n_j = n_{1j} + n_{2j} \): total number at risk
- \( d_{1j}, d_{2j} \): number of observed events in group 1 and group 2 at \( t_j \)
- \( d_j = d_{1j} + d_{2j} \): total events at \( t_j \)
Under \( H_0 \), the expected number of events in group 1 at \( t_j \), given the total events observed and each group's share of the risk set, is:
\[ E_{1j} = d_j \cdot \frac{n_{1j}}{n_j} \]The variance of the observed count at each event time, from the hypergeometric distribution, is:
\[ V_j = \frac{n_{1j} n_{2j} d_j (n_j - d_j)}{n_j^2 (n_j - 1)} \]Summing across all event times gives the Log-Rank statistic:
\[ \chi^2 = \frac{\left( \sum_{j=1}^{m} (d_{1j} - E_{1j}) \right)^2}{\sum_{j=1}^{m} V_j} \]Under \( H_0 \), this statistic follows approximately a chi-square distribution with 1 degree of freedom for a two-group comparison (or \( k - 1 \) degrees of freedom for \( k \) groups). A large statistic-meaning the observed event counts consistently deviated from what was expected-produces a small p-value.
Worked Example 1: A Small Two-Group Comparison
Suppose 8 patients are followed in a small trial, 4 in Group A (new treatment) and 4 in Group B (standard care). A + marks a censored observation:
| Group A (time) | Group B (time) |
|---|---|
| 6 | 3 |
| 9+ | 5 |
| 10 | 7 |
| 14 | 8+ |
The distinct event times (excluding censored observations) combined across both groups, in order, are: \( t = 3, 5, 6, 7, 10, 14 \). Build the observed/expected table at each event time:
| \( t_j \) | \( n_{1j} \) (A at risk) | \( n_{2j} \) (B at risk) | \( d_{1j} \) | \( d_{2j} \) | \( E_{1j} \) | \( V_j \) |
|---|---|---|---|---|---|---|
| 3 | 4 | 4 | 0 | 1 | 0.500 | 0.250 |
| 5 | 4 | 3 | 0 | 1 | 0.571 | 0.245 |
| 6 | 4 | 2 | 1 | 0 | 0.667 | 0.222 |
| 7 | 3 | 2 | 0 | 1 | 0.600 | 0.240 |
| 10 | 2 | 0 | 1 | 0 | 1.000 | 0.000 |
| 14 | 1 | 0 | 1 | 0 | 1.000 | 0.000 |
Note that by \( t = 10 \), patient B8 has already been censored (at time 8), so Group B's risk set is empty from that point on-only Group A patients remain to contribute events at \( t = 10 \) and \( t = 14 \). Summing: \( \sum d_{1j} = 0+0+1+0+1+1 = 3 \), \( \sum E_{1j} = 0.500+0.571+0.667+0.600+1.000+1.000 = 4.338 \), \( \sum V_j = 0.250+0.245+0.222+0.240+0.000+0.000 = 0.957 \).
\[ \chi^2 = \frac{(3 - 4.338)^2}{0.957} = \frac{(-1.338)^2}{0.957} = \frac{1.790}{0.957} \approx 1.871 \]With 1 degree of freedom, \( \chi^2 = 1.871 \) gives a p-value of approximately \( 0.171 \). We fail to reject \( H_0 \)-with only 8 patients, there is not enough evidence to conclude the two groups' survival differs, even though Group A visually looks like it survives noticeably longer in this small sample.
Worked Example 2: No Real Difference Between Groups
Now suppose 10 patients per group are drawn from two populations with genuinely identical survival, so any apparent difference is purely due to chance. Summarizing the observed-versus-expected table across all 14 distinct event times (computed the same way as above) gives the totals directly:
| Quantity | Value |
|---|---|
| \( \sum d_{1j} \) (observed events, Group A) | 7 |
| \( \sum E_{1j} \) (expected events, Group A) | 7.25 |
| \( \sum V_j \) (summed variance) | 3.10 |
With 1 degree of freedom, \( \chi^2 = 0.020 \) gives a p-value of approximately \( 0.887 \)-nowhere close to significant. We fail to reject \( H_0 \), correctly matching how the data was generated: two groups with no real difference in survival, where the observed event count landed almost exactly on the expected count.
Python Example
In practice you'll almost never build the observed/expected table by hand. Python's lifelines.statistics.logrank_test computes the full statistic directly from raw durations and event indicators:
import numpy as np
from lifelines.statistics import logrank_test
# Group A: new treatment
duration_A = [6, 9, 10, 14]
event_A = [1, 0, 1, 1] # 1 = event occurred, 0 = censored
# Group B: standard care
duration_B = [3, 5, 7, 8]
event_B = [1, 1, 1, 0]
result = logrank_test(duration_A, duration_B,
event_observed_A=event_A,
event_observed_B=event_B)
print(f"Test statistic: {result.test_statistic:.3f}")
print(f"p-value: {result.p_value:.3f}") Output:
Test statistic: 1.871
p-value: 0.171 This matches Worked Example 1 exactly. For comparing more than two groups at once, lifelines.statistics.multivariate_logrank_test extends the same idea to a chi-square test with \( k - 1 \) degrees of freedom, and pairs naturally with plotting each group's KaplanMeierFitter curve for a visual comparison alongside the p-value.
How to Interpret Results
| Result | Interpretation |
|---|---|
| p-value \( < \) significance level (e.g., 0.05) | Reject \( H_0 \)-survival differs significantly between groups |
| p-value \( \geq \) significance level | Fail to reject \( H_0 \)-no significant evidence of a survival difference |
| Significant overall test, \( k > 2 \) groups | At least one group differs-follow up with pairwise comparisons |
| Curves cross visually but test is non-significant | Consider a weighted variant-see Weighted Variants |
Always pair the p-value with a Kaplan-Meier plot of the survival curves themselves-the Log-Rank Test tells you whether curves differ, not how or when they differ, and the visual curve is usually what makes a result meaningful to a non-technical audience.
Weighted Variants and More Than Two Groups
The standard Log-Rank Test weights every event time equally, which is most powerful when hazards are roughly proportional between groups. When that's not a reasonable expectation, weighted variants adjust which part of follow-up gets emphasized:
| Test | Weighting | Best For |
|---|---|---|
| Standard Log-Rank | Equal weight at every event time | Proportional hazards, differences spread evenly over time |
| Peto-Peto (Gehan-Wilcoxon) | Weighted by number still at risk | Differences concentrated early in follow-up |
| Fleming-Harrington | Tunable weights via parameters \( (p, q) \) | Flexible-can emphasize early or late differences as needed |
| Tarone-Ware | Weighted by square root of risk set size | A compromise between standard and Peto-Peto weighting |
For more than two groups, the multivariate Log-Rank Test extends the same observed-vs-expected logic across all \( k \) groups simultaneously, producing a single chi-square statistic with \( k - 1 \) degrees of freedom that tests the overall null hypothesis that all groups share the same survival function-analogous to how an ANOVA F-test generalizes a two-sample t-test.
Checking Assumptions in Practice
- Plot the Kaplan-Meier curves first. Visual inspection quickly reveals whether curves stay separated throughout follow-up (favoring the standard test) or cross (favoring a weighted variant, see Weighted Variants).
- Check that censoring looks non-informative. Compare the reasons and timing of censoring across groups; if one group is censored much earlier or for systematically different reasons, treat results with caution.
- Confirm groups were defined in advance, not carved out of the data after seeing which split produced a significant result-this is a common and serious source of false positives.
- For more than two groups, run the overall test first, then follow up with pairwise comparisons using a multiple-comparison correction such as Bonferroni, rather than running every pair independently from the start.
Common Pitfalls and How to Avoid Them
- Ignoring crossing survival curves. The most common misuse-applying the standard equal-weighted test when curves visibly cross, which can wash out a real difference into a non-significant result; check for this before trusting the p-value.
- Running many pairwise comparisons without correction. With more than two groups, testing every pair independently at \( \alpha = 0.05 \) inflates the false-positive rate; correct for multiple comparisons.
- Treating a non-significant result as proof of no difference. A large p-value means insufficient evidence was found, not that the groups are provably identical-especially relevant with small samples, as in Worked Example 1.
- Forgetting the test says nothing about effect size. The Log-Rank Test only produces a p-value-if you need a quantified effect size like a hazard ratio, pair it with a Cox Proportional Hazards Model.
- Defining groups after looking at the outcome data. Splitting subjects into groups based on a pattern noticed in their survival times invalidates the test's p-value entirely.
Advantages
- Non-parametric-makes no assumption about the shape of the underlying survival distribution.
- Naturally incorporates censored observations without discarding information.
- Simple to compute, widely implemented, and easy to report alongside a Kaplan-Meier plot.
- Extends cleanly to more than two groups via the multivariate Log-Rank Test.
- Well established as the standard, most-cited method for comparing survival curves in clinical research.
Limitations
- No effect size. The test only produces a p-value, not a hazard ratio or any other quantified measure of how different the groups are-see Comparisons.
- Cannot adjust for covariates. Confounding variables cannot be controlled for within the test itself, unlike the Cox Proportional Hazards Model.
- Loses power when survival curves cross. Equal weighting across all event times can cancel out opposing early and late differences-see Weighted Variants.
- Limited to discrete, pre-specified groups. It cannot directly handle continuous predictors the way regression-based survival models can.
- Sensitive to informative censoring. Biased conclusions can result if censoring is related to the underlying risk of the event within one or more groups.
When NOT to Use It
- When you need to adjust for continuous or multiple covariates simultaneously-use the Cox Proportional Hazards Model instead.
- When survival curves clearly cross and a weighted variant hasn't been considered-see Weighted Variants.
- When you need a quantified effect size (like a hazard ratio) rather than just a significance test.
- When groups were formed by inspecting the outcome data itself rather than defined in advance.
- When censoring is clearly informative and cannot be reasonably assumed independent of the underlying risk.
Log-Rank Test vs Cox Model vs Kaplan-Meier vs t-test
| Aspect | Log-Rank Test | Cox Proportional Hazards | Kaplan-Meier | Two-Sample t-test |
|---|---|---|---|---|
| What it produces | A single p-value for curve difference | Hazard ratios with confidence intervals | Non-parametric survival curve estimate | Difference in group means |
| Handles censoring | Yes, natively | Yes, natively via partial likelihood | Yes, natively | No-cannot use censored observations correctly |
| Covariates | None beyond the grouping variable | Any number, continuous or categorical | None-descriptive only | None beyond the grouping variable |
| Effect size reported | No-significance only | Yes-hazard ratio | N/A-descriptive curve | Yes-mean difference |
| Typical use | Simple group comparison of survival | Covariate-adjusted risk modeling | Visualizing survival experience of a cohort | Comparing means of a non-time-to-event outcome |
Common Misconceptions
- "The Log-Rank Test tells you how much better one group's survival is." It only tests whether the curves differ-see Limitations. For an actual effect size, pair it with a Cox Proportional Hazards Model.
- "A non-significant Log-Rank Test means the treatment doesn't work." It means no significant survival difference was detected at the observed sample size-see Worked Example 1, where a visually promising trend was not statistically significant with only 8 patients.
- "The Log-Rank Test works the same regardless of whether curves cross." Not true-the standard version can lose most of its power when curves cross, as covered in Weighted Variants.
- "Censored subjects should just be dropped before running the test." The opposite is true-censored subjects contribute to every risk set up until their censoring time, and dropping them discards real information and can bias the result.
- "You can define groups after looking at the outcomes and still trust the p-value." Groups must be defined before examining the outcome data; post-hoc group definitions invalidate the test's statistical guarantees.
Interview Questions
- Explain in your own words what the Log-Rank Test compares, and why it uses observed versus expected event counts rather than comparing mean survival times directly.
- Derive the Log-Rank chi-square statistic from the summed observed-minus-expected differences and their variance.
- Why does the standard Log-Rank Test lose power when survival curves cross, and what would you use instead?
- How does the Log-Rank Test use censored observations, and why is dropping them a mistake?
- What is the relationship between the Log-Rank Test and a Cox Proportional Hazards Model with a single binary covariate?
- How would you extend the Log-Rank Test to compare more than two groups, and what follow-up analysis would you run if the overall test is significant?
- What is the difference between the standard Log-Rank Test and the Peto-Peto (Gehan-Wilcoxon) test?
- Why can't the Log-Rank Test adjust for confounding covariates, and what would you use if you needed to?
- Explain why forming comparison groups after inspecting the outcome data invalidates the Log-Rank Test's p-value.
- What does a non-significant Log-Rank Test result actually tell you, and what does it not tell you?
Frequently Asked Questions
- The Log-Rank Test is a non-parametric hypothesis test that checks whether two or more groups have statistically different survival experiences over time-comparing their Kaplan-Meier survival curves directly-while correctly accounting for censored subjects who had not experienced the event by the end of follow-up. It is the standard tool for comparing treatment against control in clinical trials, or any time-to-event outcome split across a small number of groups.
- At every distinct event time across the combined groups, the test computes the observed number of events in each group and the number expected under the null hypothesis of identical survival, based on the size of each group's risk set at that time. Summing (observed minus expected) across all event times for one group, then dividing its square by the total variance of that sum, produces a statistic that follows approximately a chi-square distribution with (number of groups - 1) degrees of freedom.
- A small p-value, conventionally below 0.05, indicates the survival curves differ significantly-there is evidence the groups do not share the same underlying survival experience. A large p-value means the test did not find sufficient evidence of a difference; this does not prove the curves are identical, only that no statistically significant difference was detected given the available data.
- The Log-Rank Test is limited to comparing survival between a small number of discrete groups and cannot incorporate continuous covariates or adjust for confounding variables. The Cox Proportional Hazards Test generalizes this considerably-it can include any number of continuous and categorical covariates simultaneously, quantifies effect size directly through interpretable hazard ratios, and adjusts for multiple predictors at once. In fact, a two-group Log-Rank Test and a Cox model with a single binary covariate produce mathematically very similar results (the score test from the Cox model is closely related to the Log-Rank statistic).
- The test assumes non-informative censoring, meaning censoring is unrelated to a subject's underlying risk of the event, and independence between subjects' event times. Its statistical power is also implicitly built around a proportional hazards scenario, where one group's risk is consistently higher or lower than another's across the whole follow-up period-the test loses power when survival curves cross, since opposing early and late differences can cancel out in the summed statistic.
- The standard (unweighted) Log-Rank Test treats every event time equally, so a crossing pattern-where one group has higher early risk and the other has higher late risk-can produce an oddly non-significant result even though the curves clearly differ. Weighted alternatives such as the Peto-Peto test (which emphasizes early differences) or the Fleming-Harrington family of tests (which can be tuned to emphasize early or late differences) are generally more appropriate in that situation, alongside a formal check for non-proportional hazards.
- Yes. The test generalizes naturally to any number of groups-the statistic becomes a chi-square test with (k - 1) degrees of freedom for k groups, testing the overall null hypothesis that all groups share the same survival curve. A significant overall result is typically followed by pairwise Log-Rank comparisons with a multiple-comparison correction to identify which specific groups differ.
Key Takeaways
- The Log-Rank Test compares survival between groups by summing, across every observed event time, how far the observed number of events in each group deviates from the number expected if all groups shared identical survival.
- The statistic \( \chi^2 = \frac{(\sum(d_{1j}-E_{1j}))^2}{\sum V_j} \) follows a chi-square distribution with \( k-1 \) degrees of freedom for \( k \) groups.
- The test is non-parametric and handles censored observations natively, but produces only a p-value-no quantified effect size like a hazard ratio.
- It assumes non-informative censoring and is most powerful when hazards are roughly proportional between groups; it loses power when survival curves cross, as covered in Weighted Variants.
- In Python,
lifelines.statistics.logrank_testcomputes the two-group statistic directly, andmultivariate_logrank_testextends it to more than two groups. - If you need to adjust for continuous covariates or quantify effect size, pair the Log-Rank Test with a Cox Proportional Hazards Model-the two are closely related mathematically for a single binary covariate.
- Always plot the Kaplan-Meier curves alongside the test result; the p-value alone doesn't show how or when the groups' survival diverges.
The Log-Rank Test remains the default first step in comparing survival between groups because the question it answers-do these groups genuinely experience the event at different rates over time-is central to clinical trials, reliability studies, and any other time-to-event comparison, and it answers that question without requiring any assumption about the shape of the underlying survival distribution. Its simplicity is also its main limitation: a single p-value tells you whether curves differ, but not by how much, and not adjusted for anything else going on in the data.
The two worked examples above show how directly the test reads from the data-summing observed-versus-expected event counts at each distinct event time into a single chi-square statistic, whether the underlying groups truly differ or not. Plot the Kaplan-Meier curves first, check whether they cross before trusting the standard test, and follow up with a Cox Proportional Hazards Model whenever you need a quantified effect size or covariate adjustment-together, these two tests cover the vast majority of real-world survival analysis questions.