Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-212

Log-Rank Statistic

Problem

Compute a single-time-point log-rank statistic for two groups. With N = n1 + n2, expected = d * n1 / N and variance = n1*n2*d*(N - d) / (N^2*(N - 1)), return (d1 - expected)^2 / variance.

Return 0.0 when the variance is 0.

Hint

Compare observed events in group 1 against the number expected under equal risk.

Test cases

case 1
in: [100,100,20,40]
expected: 0
case 2
in: [100,100,30,40]
expected: 12.437500000000002
case 3
in: [50,50,5,20]
expected: 6.1875
case 4
in: [10,10,0,0]
expected: 0
Starter codePython
def log_rank_statistic(n1, n2, d1, d):
    # Your code here
    pass

4 test cases · run your code against them in the editor