Skip to content
DeepForgeby svx
All problems
HardStatisticsst-179

Bias-Corrected Cramer's V

Problem

Return the bias-corrected Cramer's V: sqrt(max(0, chi2/n - (r-1)(c-1)/(n-1)) / min(r-1, c-1)) for a 2D table, where chi2 uses expected counts row_total*col_total/n. Return 0.0 for tables with fewer than two rows or columns, a total of at most one, or any zero expected count.

Hint

The correction subtracts the association expected by chance.

Test cases

case 1
in: [[[10,20],[30,40]]]
expected: 0
case 2
in: [[[10,0],[0,10]]]
expected: 0.9733285267845753
case 3
in: [[[50,10],[10,50]]]
expected: 0.6603340693163625
case 4
in: [[[5,5],[5,5]]]
expected: 0
case 5
in: [[[10,20,30],[30,20,10]]]
expected: 0.3871174808473405
Starter codePython
def bias_corrected_cramers_v(observed):
    # Your code here
    pass

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