Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-172

Simpson's Paradox Reversal Check

Problem

Two 2x2 tables have the form [[successes_a, total_a], [successes_b, total_b]]. Return True when both tables favor the same group by success rate but the pooled table favors the other group, and False otherwise (including ties and degenerate tables).

Hint

Compare the within-table rate differences against the pooled rate difference.

Test cases

case 1
in: [[[81,87],[234,270]],[[192,263],[55,80]]]
expected: true
case 2
in: [[[60,100],[10,50]],[[60,100],[10,50]]]
expected: false
case 3
in: [[[60,100],[10,50]],[[3,10],[8,20]]]
expected: false
case 4
in: [[[0,0],[0,0]],[[0,0],[0,0]]]
expected: false
Starter codePython
def simpson_reversal_check(table1, table2):
    # Your code here
    pass

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