Skip to content
DeepForgeby svx
All problems
HardStatisticsst-196

Woolf CI for OR (Haldane Correction)

Problem

Return Woolf's logit confidence interval for the odds ratio, adding 0.5 to every cell when any cell of the 2x2 table is zero (Haldane-Anscombe correction). The interval is exp(ln(OR) +/- z*sqrt(1/a + 1/b + 1/c + 1/d)). Return [0.0, 0.0] for negative counts or an all-zero table.

Hint

The continuity correction keeps the log odds ratio finite when a cell is empty.

Test cases

case 1
in: [5,0,1,1,1.96]
expected: [0.2789124783286126,433.82784709057984]
case 2
in: [10,0,0,10,1.96]
expected: [7.978871298830418,24374.500191337585]
case 3
in: [20,80,10,90,1.96]
expected: [0.994279971565182,5.091624235405931]
case 4
in: [0,0,0,0,1.96]
expected: [0,0]
case 5
in: [1,0,0,1,1.96]
expected: [0.09737346554575602,831.8487952134959]
Starter codePython
import math
def woolf_or_ci_haldane(a, b, c, d, z_crit):
    # Your code here
    pass

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