Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-174

Goodman-Kruskal Gamma

Problem

Return Goodman and Kruskal's gamma (P - Q)/(P + Q) for a 2D table, where P counts concordant pairs and Q discordant pairs, each cell pair weighted by its counts. Return 0.0 when there is no concordant or discordant pair.

Hint

Gamma ignores ties entirely and ranges from -1 to 1.

Test cases

case 1
in: [[[10,20],[30,40]]]
expected: -0.2
case 2
in: [[[30,10],[10,30]]]
expected: 0.8
case 3
in: [[[5,5],[5,5]]]
expected: 0
case 4
in: [[[1,2,3],[3,2,1]]]
expected: -0.6153846153846154
case 5
in: [[[10,20,30]]]
expected: 0
Starter codePython
def goodman_kruskal_gamma(observed):
    # Your code here
    pass

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