Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-070

Chi-Square Independence 2x2 with Yates Correction

Problem

Return the Yates-corrected chi-square statistic for a 2x2 table: sum((max(0, |o - e| - 0.5))^2 / e) with e = row_total*col_total/total. Return 0.0 when the shape is not 2x2, the total is zero, or any expected count is zero.

Hint

Subtract 0.5 from each absolute deviation before squaring.

Test cases

case 1
in: [[[10,20],[30,40]]]
expected: 0.4464285714285714
case 2
in: [[[5,5],[5,5]]]
expected: 0
case 3
in: [[[10,0],[0,10]]]
expected: 16.2
case 4
in: [[[1,2],[3,4]]]
expected: 0
case 5
in: [[[1,2,3],[3,2,1]]]
expected: 0
Starter codePython
def chi_square_yates(observed):
    # Your code here
    pass

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