All problems
McNemar Statistic
Problem
Return the McNemar statistic (b - c)^2 / (b + c) for a paired 2x2 table, where b and c are the two discordant cell counts. Return 0.0 when b + c is zero.
Hint
Only the off-diagonal cells matter.
Test cases
case 1
in: [10,2]
expected: 5.333333333333333
case 2
in: [5,5]
expected: 0
case 3
in: [0,5]
expected: 5
case 4
in: [0,0]
expected: 0
case 5
in: [20,8]
expected: 5.142857142857143
Starter codePython
def mcnemar_statistic(b, c):
# Your code here
pass5 test cases · run your code against them in the editor