AI Glossary / Statistics and probability / Intermediate
Logrank test
Definition
The logrank test compares time-to-event distributions between groups while allowing right-censored observations. It repeatedly contrasts the events observed in each group with the events expected from that group's share of the people or items still at risk. These differences are combined into a test statistic. It is widely used in survival analysis, where the event can be equipment failure, customer departure, or another clearly defined occurrence, not only death.
What it means
The test uses both event timing and the changing population at risk. Someone who has not experienced the event by the end of observation contributes information up to that point. Their record is censored; it is neither an observed event at the cutoff nor proof that the event will never happen.
The usual null hypothesis is equality of the groups' survival distributions. The test does not directly estimate how many days are gained or the size of a hazard ratio. Those questions need accompanying estimates, curves, or an appropriate model. A small p-value alone cannot describe the practical importance of a difference.
How it works
Record a consistent starting point, follow-up time, event indicator, and group for every independent unit. At each event time, identify the number at risk in each group just before the event and the total events at that time.
Under the null, a group's expected events equal the total events multiplied by its fraction of the risk set. Sum observed-minus-expected contributions and calculate their variance using the risk sets. For two groups, squaring that sum and dividing by its variance gives the usual statistic, compared approximately with a chi-squared distribution with one degree of freedom.
The ordinary test is especially effective against proportional-hazards alternatives. Crossing curves can make opposing contributions cancel. Noninformative censoring, an appropriate independence structure, and sufficient event information matter; proportional hazards is not a universal requirement for validity under the equality null.
Three practical examples
- A manufacturer compares time to first failure for two component designs, including units still functioning when the test ends.
- A subscription business compares time to cancellation between randomized onboarding approaches, retaining customers whose observation periods end before cancellation.
- An engineering team compares time to a predefined system fault across configurations, ensuring that maintenance removals are handled according to their actual meaning.
Think of it this way
Imagine two queues of items still eligible to fail. Each time a failure occurs, ask how many failures each queue would receive if both faced the same event process, given their current sizes. The logrank test adds the departures from those expectations while accounting for how much random variation is possible.
Worked example
Consider an original arithmetic demonstration with three units in each group. Group A has events at times 1, 2, and 3. Group B has events at times 4 and 5, and its remaining unit is right-censored at time 6. There are no tied event times.
At times 1, 2, and 3, the risk-set sizes for A and B are respectively (3,3), (2,3), and (1,3). Each time has one event, so expected A events are 3/6 = 0.5, 2/5 = 0.4, and 1/4 = 0.25. A's observed total is 3, its expected total is 1.15, and its observed-minus-expected sum is 1.85.
With one event at each time, the variance contributions are 0.5 times 0.5 = 0.25, 0.4 times 0.6 = 0.24, and 0.25 times 0.75 = 0.1875. Their sum is 0.6775. Later events contribute no contrast because no A units remain at risk. The resulting statistic is 1.85 squared divided by 0.6775, approximately 5.0517.
This tiny example demonstrates bookkeeping only. Its sparse event information does not justify treating a large-sample reference approximation as reliable evidence for an operational decision. It also illustrates why a simple comparison of final event percentages would discard important timing information.
Illustrative case study
Fictional case: Pine Devices runs a randomized durability comparison of two designs. Some units survive the planned study period, so analysts retain their censored records rather than discarding them. They show Kaplan-Meier curves with numbers at risk and calculate a prespecified logrank comparison.
The curves separate early and later move closer together. The team reports this pattern alongside the test and examines whether a single hazard ratio would hide the time variation. Engineers use the results with failure-mode investigations and uncertainty estimates, avoiding a claim that the design is better at every point in time.
Common misconceptions and mistakes
A logrank test is not a comparison of average observed follow-up times. Censored follow-up times are not complete event times. A nonsignificant result does not establish equal survival, especially with few events or crossing curves.
Do not assume that different censoring rates automatically invalidate the test; the key issue includes whether censoring is informative within the analysis structure. Conversely, apparently similar censoring rates do not prove validity. Repeated events from the same unit, competing events, or time-dependent confounding require methods suited to those circumstances.
Business use
Businesses can use the test to compare reliability or retention when follow-up lengths differ. Planning should focus on event information as well as participant counts. A large study with very few events may provide limited evidence.
Present survival probabilities at relevant horizons or other suitable effect summaries with uncertainty. Define event and censoring rules before examining group differences. When decisions depend on early versus late performance, select an analysis that addresses that question rather than interpreting one overall significance result as a complete performance ranking.
People also ask
Does the test require every event time to be observed?
No; it accommodates right censoring under appropriate assumptions.
Does it estimate a hazard ratio?
No. A separate model or estimate is needed for that effect measure.
Can it compare more than two groups?
Yes; the usual multi-group statistic uses the corresponding variance structure and degrees of freedom.
Check your understanding
1. What is A's expected event count at the first example time?
Answer: 0.5. 2.
Is the unit censored at time 6 recorded as an event then?
Answer: No. 3.
Why inspect survival curves?
Answer: They show timing patterns and crossing that one test result can conceal.
Related terms
- Survival analysis
- Risk set
- Kaplan-Meier estimator
- Hazard ratio
- Proportional hazards
- right censoring
- Cox regression
- competing risks
Learn next
Practice constructing risk sets and Kaplan-Meier curves. Then compare the logrank test with effect estimation and learn how censoring assumptions, crossing curves, and study design change the interpretation.
More in Statistics and probability
- Log likelihood - Log likelihood is the logarithm of a likelihood function, usually using the natural logarithm.
- Log-linear models - Log-linear models describe expected counts by making their logarithms linear combinations of parameters.
- Logistic regression - Logistic regression is a statistical and machine-learning method for modeling the probability of a categorical outcome.
- Long-range dependence - Long-range dependence is persistent statistical dependence across widely separated observations in a time series or another indexed process.
- Longitudinal or serial data - Longitudinal or serial data contain repeated measurements of a response on the same subject or unit over time.
- Longitudinal study - A longitudinal study follows the same subjects or units over time, collecting observations that reveal change, continuity, and the ordering of events.
Sources
Jonathan Taylor, Stanford STATS 305B, “Survival analysis.” https://web.stanford.edu/class/stats305b/notes/Survival_I.html — primary course derivation using risk sets and expected events. R survival package, survdiff documentation. https://stat.ethz.ch/R-manual/R-devel/library/survival/html/survdiff.html — primary implementation reference for logrank and related weighted tests. The worked sample and fictional case are original.
Previous: Logits Next: Lomb-Scargle Periodograms