Log-Rank Test Calculator
Inputs
- Inputs: group 1 observed 28 vs expected 38.4 events; group 2 observed 45 vs expected 34.6.
- Chi-square = (28 - 38.4)^2 / 38.4 + (45 - 34.6)^2 / 34.6 = 5.94 on 1 degree of freedom.
- p = 0.0148; the Mantel hazard-ratio estimate is (O1/E1) / (O2/E2) = 0.561.
- The survival curves differ significantly; a hazard ratio below 1 means group 1 events ran below expectation relative to group 2.
The log-rank test is the workhorse comparison of two survival curves: at every event time it asks whether the events fell between the groups as their numbers at risk would predict, and it accumulates the answer into one chi-square statistic. This calculator takes the summarised inputs - observed and expected events in each group - and returns the statistic, its p-value and the Mantel hazard-ratio estimate, the three numbers that headline most trial reports with time-to-event endpoints.
Worked examples
Significant separation
(28 · 38.4 · 45 · 34.6)
| Log-rank chi-square | 5.94 |
| p-value | 0.0148 |
| Hazard ratio (group 1 vs 2) | 0.561 |
| Total events | 73 |
No separation
(52 · 50.1 · 49 · 50.9)
| Log-rank chi-square | 0.14 |
| p-value | 0.7053 |
| Hazard ratio (group 1 vs 2) | 1.078 |
| Total events | 101 |
Strong separation
(15 · 26.8 · 38 · 26.2)
| Log-rank chi-square | 10.51 |
| p-value | 0.0012 |
| Hazard ratio (group 1 vs 2) | 0.386 |
| Total events | 53 |
Observed vs expected, event time by event time
Behind the four inputs sits a table with one row per distinct event time. At each, the group sizes at risk determine how the events that occurred should split if both groups shared one hazard; the differences between observed and expected are summed over the whole follow-up. The classic summary statistic (O1 - E1)^2/E1 + (O2 - E2)^2/E2 compresses that accumulation into a chi-square on 1 degree of freedom - the form this calculator implements, standard in textbooks and close to the variance-weighted version in large samples.
Censoring is handled inside the expected counts: a patient censored early simply stops contributing to the risk sets, which is why the test - unlike a comparison of raw event proportions - uses the follow-up information honestly. The inputs already embody that bookkeeping; whoever computed E1 and E2 from the risk sets has done the survival-specific work, and the statistic itself is elementary.
- Chi-square = (O1 - E1)^2/E1 + (O2 - E2)^2/E2, on 1 df
- Expected counts come from the pooled risk sets at each event time
- Hazard ratio estimate: (O1/E1) / (O2/E2)
- Most powerful when the hazard ratio is constant over time
The Mantel hazard ratio
The test's companion estimate, (O1/E1)/(O2/E2), reads each group's observed events against its expectation and ratios the two. In the first worked example group 1 recorded 28 events against 38.4 expected while group 2 recorded 45 against 34.6: the ratio is (28/38.4)/(45/34.6) = 0.561, so group 1's hazard ran at a little over half of group 2's, and the chi-square of 5.94 (p = 0.0148) says the difference is significant. The estimate is Mantel's, and it tracks the Cox model's hazard ratio closely when hazards are proportional.
The second example is the null in action - 52 against 50.1 expected and 49 against 50.9, hazard ratio 1.078, chi-square 0.14, p = 0.7053 - while the third shows a strong separation: 15 events against 26.8 expected in group 1, hazard ratio 0.386, chi-square 10.51, p = 0.0012. Note in the third example that the groups' expected counts are nearly equal while the observed counts diverge - the signature of a treatment that prevents events rather than of unequal follow-up.
| Example | O1 vs E1 | O2 vs E2 | Chi-square | HR | p |
|---|---|---|---|---|---|
| 1 | 28 vs 38.4 | 45 vs 34.6 | 5.94 | 0.561 | 0.0148 |
| 2 | 52 vs 50.1 | 49 vs 50.9 | 0.14 | 1.078 | 0.7053 |
| 3 | 15 vs 26.8 | 38 vs 26.2 | 10.51 | 0.386 | 0.0012 |
Worked examples
Example 1: Observed events, group 1 28; Expected events, group 1 38.4; Observed events, group 2 45; Expected events, group 2 34.6. Log-rank chi-square = 5.94. Supporting values: p-value 0.0148; Hazard ratio (group 1 vs 2) 0.561; Total events 73. Inputs: group 1 observed 28 vs expected 38.4 events; group 2 observed 45 vs expected 34.6. Chi-square = (28 - 38.4)^2 / 38.4 + (45 - 34.6)^2 / 34.6 = 5.94 on 1 degree of freedom. p = 0.0148; the Mantel hazard-ratio estimate is (O1/E1) / (O2/E2) = 0.561. The survival curves differ significantly; a hazard ratio below 1 means group 1 events ran below expectation relative to group 2.
Example 2: Observed events, group 1 52; Expected events, group 1 50.1; Observed events, group 2 49; Expected events, group 2 50.9. Log-rank chi-square = 0.14. Supporting values: p-value 0.7053; Hazard ratio (group 1 vs 2) 1.078; Total events 101. Inputs: group 1 observed 52 vs expected 50.1 events; group 2 observed 49 vs expected 50.9. Chi-square = (52 - 50.1)^2 / 50.1 + (49 - 50.9)^2 / 50.9 = 0.14 on 1 degree of freedom. p = 0.7053; the Mantel hazard-ratio estimate is (O1/E1) / (O2/E2) = 1.078. No significant survival difference at the 5% level; a hazard ratio below 1 means group 1 events ran below expectation relative to group 2.
Example 3: Observed events, group 1 15; Expected events, group 1 26.8; Observed events, group 2 38; Expected events, group 2 26.2. Log-rank chi-square = 10.51. Supporting values: p-value 0.0012; Hazard ratio (group 1 vs 2) 0.386; Total events 53. Inputs: group 1 observed 15 vs expected 26.8 events; group 2 observed 38 vs expected 26.2. Chi-square = (15 - 26.8)^2 / 26.8 + (38 - 26.2)^2 / 26.2 = 10.51 on 1 degree of freedom. p = 0.0012; the Mantel hazard-ratio estimate is (O1/E1) / (O2/E2) = 0.386. The survival curves differ significantly; a hazard ratio below 1 means group 1 events ran below expectation relative to group 2.
When proportional hazards fail
The log-rank test weights every event time equally, which makes it the most powerful rank test when the hazard ratio is constant - and progressively less suitable as that assumption fails. If the curves cross, early harm and late benefit cancel in the sum and the test can return a shrug at two dramatically different survival experiences. Weighted variants redistribute the emphasis: Wilcoxon-Gehan weights early times, Fleming-Harrington weights can target late separation, and the Renyi test targets the maximum divergence.
Choosing among them after inspecting the curves is a quiet form of p-hacking; the choice belongs in the analysis plan. What the log-rank's dominance really reflects is that proportional hazards is a good first approximation for many treatments - and when it is not, the honest report is the curves themselves plus a summary like restricted mean survival, not a hunt for the weighting that yields significance.
Log-rank vs Cox regression
The Cox model generalises the log-rank test: its score test for a single binary covariate is (in its variance-weighted form) the log-rank test, and it adds covariate adjustment, continuous predictors and multiple arms. Trials therefore often report both - the log-rank p-value for the unadjusted comparison and the Cox hazard ratio for the adjusted one - and the two usually agree closely, as the Mantel estimate on this page foreshadows.
Where they part company is interpretation. The log-rank test is purely a test: it says whether the curves differ, with the Mantel ratio as a descriptive companion. The Cox model commits to a proportional-hazards structure and returns an estimand. When a report needs a number for a label or a reimbursement dossier, the Cox estimate carries that weight; the log-rank remains the gatekeeper that says a difference exists at all.
Practical notes
The expected counts must come from the same risk-set computation as the observed ones, over the same follow-up and the same censoring rules; mixing expected counts from one analysis with observed counts from another is a real and recurring error in secondary publications. The totals need not be integers - expected counts rarely are - but observed counts always are, and the calculator's total-events output (73 in the first example) is a quick checksum on the inputs.
Finally, the chi-square here is the textbook (O - E)^2/E form. Software such as R's survdiff uses the variance of (O - E) under the hypergeometric null, which gives slightly different values in small samples; in samples of the size in the worked examples the two agree to reporting precision, and any discrepancy at small event counts should be resolved in favour of the variance form.
Stratification is the log-rank test's standard refinement and follows its logic exactly: compute observed and expected within each stratum - centre, age band, disease stage - and pool the differences, so that a treatment compared across unbalanced strata is judged within comparable groups. The stratified version is the primary analysis of most multi-centre trials, and its arithmetic is this page's arithmetic repeated and added. What stratification cannot fix is a covariate that is itself affected by treatment; the strata must be baseline facts, a discipline the test shares with every randomisation-based method.
Sample-size planning for survival trials is driven by events, not patients, and the log-rank arithmetic shows why: the statistic's information content is the event count, so a trial is sized by the number of events it must observe - the first worked example's 73 events carry a certain weight of evidence regardless of how many patients were followed to produce them. Recruitment targets are then back-solved from expected event rates and follow-up, which is why trial protocols speak of event-driven analysis timing: the calendar date of the analysis is set by the accumulating O and E, not by the clock.
Ties and discrete event times deserve a footnote, because trial data record events by day or week, not by instant. When several events share a recorded time, the risk-set bookkeeping behind E1 and E2 must decide how to order them against the censorings at the same time; conventions differ slightly between packages and the statistic moves in the third decimal, not the first. In samples of the worked examples' size the choice is immaterial to any conclusion, but in small trials with coarse time recording it is one more reason to report the method alongside the number.
FAQs
What chi-square does the first example give?
Chi-square = (28 - 38.4)^2/38.4 + (45 - 34.6)^2/34.6 = 5.94 on 1 degree of freedom.
What is its p-value?
The p-value is 0.0148, so the survival curves differ significantly at the 5% level.
What hazard ratio does the first example estimate?
The Mantel estimate is 0.561: group 1's hazard ran at a little over half of group 2's.
What chi-square does the balanced second example give?
It gives 0.14 with p = 0.7053 - observed and expected events nearly coincide in both groups.
What chi-square does the third example give?
It gives 10.51 with p = 0.0012 and a hazard ratio of 0.386 - a strong survival advantage for group 1.
How many events are there in total in the first example?
There are 73 events in total: 28 in group 1 and 45 in group 2.