All problems
Yates Sample Ratio Mismatch
Problem
Compute the Yates-corrected sample ratio mismatch chi-square. With expected_i = total * ratio_i, add max(0, abs(observed_i - expected_i) - 0.5)^2 / expected_i for positive expected counts. Return 0.0 when the observed total is 0.
Hint
A large mismatch between observed and planned traffic share suggests the randomization is broken.
Test cases
case 1
in: [[45,55],[0.5,0.5]]
expected: 0.81
case 2
in: [[50,50],[0.5,0.5]]
expected: 0
case 3
in: [[30,70],[0.5,0.5]]
expected: 15.21
case 4
in: [[],[]]
expected: 0
case 5
in: [[10],[1]]
expected: 0
Starter codePython
def yates_sample_ratio_mismatch(observed, expected_ratios):
# Your code here
pass5 test cases · run your code against them in the editor