Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-282

Simpson Reversal Check

Problem

Each stratum is [n_treated, treated_mean, n_control, control_mean]. Return True when every within-stratum treated-minus-control difference has the same strict sign while the pooled difference, computed from the aggregated group means, has the opposite strict sign. Return False for empty or invalid input.

Hint

Aggregate all treated units into one mean and all controls into another.

Test cases

case 1
in: [[[10,55,90,50],[90,25,10,20]]]
expected: true
case 2
in: [[[50,55,50,50],[50,25,50,20]]]
expected: false
case 3
in: [[[90,45,10,50],[10,15,90,20]]]
expected: true
case 4
in: [[[50,55,50,50],[50,20,50,25]]]
expected: false
case 5
in: [[]]
expected: false
Starter codePython
def simpson_reversal_check(strata):
    # Your code here
    pass

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