The log-rank test — the gap between two curves as one number
observed − expected, and z
At every moment a death occurred, work out “how many would it have been if things were fair” and pile it up. That sum is the test statistic.
How do you decide whether two survival curves differ?
You want to measure something like "the area between the curves", but censoring makes that awkward.
The log-rank test takes a different route.
At every time a death happened it asks —
"A hundred people were alive at this moment and 40 of them were in group A.
Then one died. If the two groups were no different, the expected number of deaths
in group A would be 0.4. Did the death actually happen in A, or in B?"
Pile up that observed − expected over every death time.
The further the total is from zero, the more the two groups differ.
73 people died in the high-infiltration group, where 102.5 would have been expected. About 30 fewer deaths than chance.
PythonRuns in your browser
Three of the 12 cancer types come in under p < 0.05. Most z values are negative, but two are positive.
PythonRuns in your browser
Bar length is |z|. Green means "more infiltration, longer life"; red is the opposite.
Loading…
Read the result honestly.
SKCM (melanoma) — z = −4.38, p = 1.2×10⁻⁵. Strong.
That TIL is a prognostic factor in melanoma has been known for a long time, and this data says so too.
CESC and BRCA — p of 0.004 and 0.017, in the same direction.
The other nine — p between 0.2 and 0.87. They say nothing.
PRAD, PAAD and UCEC — z is positive. The direction is reversed.
UVM (uveal melanoma) is not in the table at all.
More than half its infiltration rates are zero, so it cannot be split in two at the median.
Some data cannot be cut.
We must not stop here. We just ran 12 tests.
What "three are significant" actually means has to be settled in lesson 16.
🤔 Check yourself
Under what assumption is the 'expected number of deaths' computed in a log-rank test?
Answer Under the null hypothesis (the groups do not differ), whoever dies at that moment should fall into the groups in proportion to the risk set. That is the expectation.
🤔 Check yourself
How do you correctly read z = −4.38 (with high infiltration as group 1)?
Answer z = (observed − expected)/√variance, so a negative value means observed fell below expected. Fewer deaths in group 1 (high infiltration) — that is, they lived longer.