Bell Statistics

What is the log-rank test?

The log-rank test compares how quickly an event happens in two groups, using everyone's data including those who have not experienced it yet. It accumulates evidence at each point in time where an event occurs, rather than comparing outcomes at one fixed moment.

Also called
mantel-cox test, survival curve comparison, time-to-event test
Allon Korem

Written by Allon Korem

Chief Executive Officer

Last updated

In plain English

Some questions are not about whether something happened but how quickly. Did the new onboarding get people to their first successful action sooner? Do accounts on the annual plan churn later than monthly ones? Reducing those to a binary — converted within 30 days, yes or no — throws away most of what you measured and makes the answer depend entirely on where you drew the line. The log-rank test compares the whole timeline instead.

Its central problem is censoring, and censoring is why an ordinary z-test is not merely less efficient here but actively misleading. At any analysis date, some users have converted and others have not converted *yet* — and the second group is not the same as never converting. A user who signed up three days ago and has not converted carries very different information from one who signed up eight months ago and has not. Dropping them biases the result, and counting them as failures biases it the other way. The log-rank test uses each subject for exactly as long as they were observed and then stops.

The mechanism is a sequence of small comparisons. At each moment an event occurs, the test looks at everyone still at risk, works out how many events would be expected in each group if the groups were identical — proportional to how many are still at risk in each — and records the gap between expected and observed. Those gaps are accumulated across every event time and the total is compared against a chi-square distribution. It is closer in spirit to a running tally than to a single snapshot comparison.

What it assumes is proportional hazards: that one group's instantaneous risk of the event stays a roughly constant multiple of the other's over the whole period. That assumption fails in a specific and common way — when the survival curves cross. A change that speeds up early conversions but produces more churn later can look like nothing at all, because the early advantage and the late disadvantage cancel in the accumulated statistic. Plotting the two Kaplan-Meier curves before running the test is not optional; it is how you find out whether the test is answering your question.

It also tells you only that the curves differ, not by how much. For a magnitude you want a hazard ratio from a Cox proportional hazards model, or something concrete like median time to event in each group. "Churn is significantly later on the annual plan" is not a number anyone can plan around; "median tenure is 14.2 months against 9.6" is.

The formula

One expected-versus-observed comparison at every distinct event time, accumulated. The censoring handling is implicit in who remains in the risk set.

Expected events at time t
E₁ⱼ = dⱼ · ( n₁ⱼ / nⱼ )

dⱼ events happen at time j; n₁ⱼ of the nⱼ still at risk are in group 1. Under the null, events split in proportion to who is exposed.

The statistic
χ² = ( Σⱼ ( O₁ⱼ − E₁ⱼ ) )² / Σⱼ Vⱼ

Accumulated across every event time, then compared on one degree of freedom — see the log-rank calculator.

Variance at each time
Vⱼ = dⱼ ( n₁ⱼ / nⱼ )( n₂ⱼ / nⱼ )( nⱼ − dⱼ ) / ( nⱼ − 1 )

The hypergeometric variance of the split at that instant. Small risk sets late in the study contribute little.

What it assumes
h₁(t) / h₂(t) = constant, for all t

Proportional hazards. Crossing survival curves violate it, and the test can then return no difference when the curves plainly differ.

Worked example

A subscription business tests a new activation flow on time-to-first-purchase, tracking 3,000 signups per arm over 90 days. At the analysis date 1,340 control users and 1,505 variant users have purchased; the rest are censored, most of them recent signups who simply have not had long enough.

Control purchases
1,340 / 3,000 (44.7%)
Variant purchases
1,505 / 3,000 (50.2%)
Censored
2,155 users still within their window
Median time to purchase
control 38 days, variant 29 days
Log-rank statistic
χ² = 18.4 on 1 df
Hazard ratio (Cox)
1.19, 95% CI 1.10 to 1.29

p = 0.000018. The variant reaches first purchase faster, with a 19% higher instantaneous rate of purchasing at any given moment.

The headline conversion difference — 44.7% against 50.2% — understates what happened, because both figures are cut off at an arbitrary analysis date with two thousand users still inside their window. The timing is where the effect really shows: nine days off the median, which for a subscription business compounds into earlier revenue and a shorter payback period. Two things to check before acting. Confirm the Kaplan-Meier curves do not cross — an activation flow that pulls purchases forward without increasing the eventual total would show a large early gap that closes, and the log-rank test would still report significance while the business case evaporated. And confirm censoring is unrelated to treatment: if the variant also increased account deletions, those users leave the risk set for a reason connected to the treatment, which is informative censoring and biases everything here.

Common misconceptions

You can just measure conversion at 30 days and run a z-test.
You can, and it discards the timing information along with everyone whose window is not yet complete. The answer then depends on the cut-off you picked: a variant that converts people faster but not more can look identical at 90 days and dramatically better at 14. If the question is about speed, a fixed-horizon binary comparison cannot answer it.
Censored subjects are the ones who did not convert.
They are the ones who had not converted yet when you looked. A user observed for three days and one observed for eight months are both unconverted and carry completely different information. Treating censoring as failure understates the event rate and biases towards whichever group has been in the study longer.
A significant log-rank test tells you how much better the variant is.
It tells you the curves differ, and nothing about magnitude — the statistic grows with sample size like any other. For a number worth acting on, fit a Cox model for the hazard ratio or report the median time to event in each group. A hazard ratio of 1.19 is a claim someone can plan around; a chi-square of 18.4 is not.

Frequently asked questions

When should I use the log-rank test in a product experiment?
Whenever the outcome is time-to-something and users entered the experiment at different dates — time to first purchase, time to churn, time to reach an activation milestone. Those are exactly the cases where a fixed-horizon binary metric wastes information and where the answer would otherwise depend on an arbitrary cut-off. If every user has been observed for the same complete period and you only care whether the event happened, a simple proportion test is fine.
What happens if the two survival curves cross?
The proportional hazards assumption is violated and the test loses much of its power, because an early advantage in one group and a late advantage in the other cancel out in the accumulated statistic. It can report no significant difference on curves that visibly diverge. Plot the Kaplan-Meier curves first; if they cross, report the difference at specific meaningful horizons instead, or use a test weighted towards the period you care about.
What is a hazard ratio and how should I read one?
It is the ratio of the instantaneous event rates between two groups, so 1.19 means that at any given moment a variant user is 19% more likely to convert than a control user who has survived equally long. It is not a ratio of totals and it is not a relative lift in conversion rate. Report it with its confidence interval, and alongside something concrete like the difference in medians, which stakeholders can act on more directly.
What is informative censoring and why does it matter here?
It is when the reason someone leaves the study is related to the outcome — a user who deletes their account because they were about to churn, for instance. The log-rank test assumes censoring is uninformative, meaning a censored user represents everyone still at risk at that moment. When that fails the estimates are biased in a direction that depends on the mechanism, and no amount of extra data fixes it, because more data means more of the same bias.

Related terms

  • Bootstrap

    Resample your own data ten thousand times and watch the answer wobble — uncertainty for statistics with no formula.

  • Chi-square test

    The test for counts in a table — the standard SRM check, and the reason expected counts matter more than sample size.

  • Fisher's exact test

    Counts the possible tables instead of approximating them — the right test when a cell expects fewer than five.

  • Sample size

    Four inputs, one number, fixed before the test runs — and the square law that makes small effects expensive.

Calculate it

  • Log-rank test

    Compare two survival, retention or churn curves — events needed to plan, chi-square and p-value to analyse.

Knowing the term is the easy part

Applying it to a live measurement problem is the part that goes wrong. If you are designing an experiment, reading a result you do not trust, or trying to work out what your marketing actually caused, that is the work we do.