All problems
Phi Coefficient
Problem
Return the phi coefficient for a 2x2 table: (a*d - b*c) / sqrt((a+b)(c+d)(a+c)(b+d)). Return 0.0 when any margin is zero.
Hint
Phi is the Pearson correlation between two binary variables.
Test cases
case 1
in: [10,20,30,40]
expected: -0.0890870806374748
case 2
in: [10,0,0,10]
expected: 1
case 3
in: [5,5,5,5]
expected: 0
case 4
in: [1,2,3,4]
expected: -0.0890870806374748
case 5
in: [0,0,0,0]
expected: 0
Starter codePython
def phi_coefficient(a, b, c, d):
# Your code here
pass5 test cases · run your code against them in the editor