Skip to content
DeepForgeby svx
All problems
HardStatisticsst-087

Fisher Exact Probability (Small Table)

Problem

Return the hypergeometric probability of the observed 2x2 table given its margins: C(a+b, a) * C(c+d, c) / C(n, a+c). Return 0.0 when the total is zero.

Hint

Use math.comb for the binomial coefficients.

Test cases

case 1
in: [1,9,9,1]
expected: 0.0005412544112234515
case 2
in: [5,0,0,5]
expected: 0.003968253968253968
case 3
in: [1,1,1,1]
expected: 0.6666666666666666
case 4
in: [0,0,0,0]
expected: 0
case 5
in: [2,3,4,5]
expected: 0.4195804195804196
Starter codePython
import math
def fisher_exact_probability(a, b, c, d):
    # Your code here
    pass

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