Skip to content
DeepForgeby svx
All problems
HardStatisticsst-260

McNemar Exact p-Value

Problem

Return the exact two-sided McNemar p-value for b and c discordant pairs: 2 * P(X <= min(b, c)) for X ~ Binomial(b + c, 0.5), capped at 1.0. Use exact binomial coefficients. Return 1.0 when b + c is zero.

Test cases

case 1
in: [10,2]
expected: 0.03857421875
case 2
in: [5,5]
expected: 1
case 3
in: [0,0]
expected: 1
case 4
in: [20,8]
expected: 0.03569813817739487
Starter codePython
import math
def mcnemar_exact_p(b, c):
    # Your code here
    pass

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