Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-175

Somers' D

Problem

Return Somers' D with the column variable dependent: (P - Q)/(P + Q + T_row), where P and Q count concordant and discordant pairs and T_row counts pairs sharing a row. Return 0.0 when the table is smaller than 2x2 or the denominator is zero.

Hint

Ties on the independent variable are included in the denominator.

Test cases

case 1
in: [[[10,20],[30,40]]]
expected: -0.08333333333333333
case 2
in: [[[30,10],[10,30]]]
expected: 0.5
case 3
in: [[[5,5],[5,5]]]
expected: 0
case 4
in: [[[1,2,3],[3,2,1]]]
expected: -0.3333333333333333
case 5
in: [[[10,20,30]]]
expected: 0
Starter codePython
def somers_d(observed):
    # Your code here
    pass

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