Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-129

McNemar Confidence Interval

Problem

Return the confidence interval for the paired proportion difference (b - c)/n_pairs with variance ((b+c) - (b-c)^2/n_pairs)/n_pairs^2, using the supplied critical value. Return [0.0, 0.0] when n_pairs <= 0 or b + c exceeds the number of pairs.

Hint

Only the discordant pairs drive the estimate.

Test cases

case 1
in: [10,2,50,1.96]
expected: [0.03165366853703999,0.28834633146296]
case 2
in: [5,5,20,1.96]
expected: [-0.3099032106965012,0.3099032106965012]
case 3
in: [0,0,10,1.96]
expected: [0,0]
case 4
in: [3,1,10,2]
expected: [-0.17947331922020554,0.5794733192202055]
case 5
in: [20,8,100,1.645]
expected: [0.03522263037814867,0.20477736962185134]
Starter codePython
def mcnemar_ci(b, c, n_pairs, z_crit):
    # Your code here
    pass

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