Skip to content
DeepForgeby svx
All problems
HardStatisticsst-180

Kendall's W

Problem

Return Kendall's coefficient of concordance W = 12*S/(m^2*(n^3 - n)) for m raters and n items, where S is the sum of squared deviations of item rank sums from their mean. Ratings are assumed to use complete rankings without ties. Return 0.0 when there are no raters, fewer than two items, inconsistent lengths, or a zero denominator.

Hint

W is 1 for perfect agreement and 0 for no agreement.

Test cases

case 1
in: [[[1,2,3],[1,2,3]]]
expected: 1
case 2
in: [[[1,2,3],[3,2,1]]]
expected: 0
case 3
in: [[[1,2,3,4],[2,1,4,3],[1,2,3,4]]]
expected: 0.8222222222222222
case 4
in: [[[1,3,2],[1,3,2],[1,3,2]]]
expected: 1
case 5
in: [[[1,2],[2,1],[1,2]]]
expected: 0.1111111111111111
Starter codePython
def kendall_w(ratings):
    # Your code here
    pass

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