All problems
Simpson's Paradox in Risk Tables
Problem
Given risk counts for two strata (a_j cases and b_j non-cases in the exposed group, c_j and d_j in the unexposed group), return True when both stratum risk differences have one sign and the pooled risk difference has the opposite sign. Return False otherwise.
Hint
Pooled counts can reverse a trend that holds in every subgroup.
Test cases
case 1
in: [81,6,234,36,192,71,55,25]
expected: true
case 2
in: [30,70,10,90,30,70,10,90]
expected: false
case 3
in: [234,36,81,6,55,25,192,71]
expected: true
case 4
in: [30,70,10,90,10,90,30,70]
expected: false
case 5
in: [1,1,1,1,1,1,1,1]
expected: false
Starter codePython
def simpsons_paradox(a1, b1, c1, d1, a2, b2, c2, d2):
# Your code here
pass5 test cases · run your code against them in the editor