Skip to content
DeepForgeby svx
All problems
HardStatisticsst-049

Mann-Whitney U and Wilcoxon Rank-Sum

Problem

Return [W, U] for samples x and y, where W is the Wilcoxon rank-sum statistic (the sum of the average ranks of x within the combined sample) and U = W - n1*(n1+1)/2. Ties get average ranks. Return [0.0, 0.0] if either sample is empty.

Hint

Rank the combined data, sum the ranks belonging to x, then subtract the shift.

Test cases

case 1
in: [[1,2,3],[4,5,6]]
expected: [6,0]
case 2
in: [[4,5,6],[1,2,3]]
expected: [15,9]
case 3
in: [[1,2,2],[2,3,4]]
expected: [7,1]
case 4
in: [[5],[5]]
expected: [1.5,0.5]
case 5
in: [[],[1,2]]
expected: [0,0]
Starter codePython
def mann_whitney_u(x, y):
    # Your code here
    pass

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