Ties are given average ranks, which is what makes the variance correction the right one. This tests a shift in DISTRIBUTION, not in mean.
Details
Formula: W = sum of the ranks of x in the pooled sample; E[W] = n1(n1 + n2 + 1)/2; Var[W] = n1 n2 (N + 1)/12 - n1 n2 sum(t^3 - t)/(12 N (N - 1)); z = (W - EW -+ 1/2) / sd
References
Wilcoxon (1945), Biometrics Bulletin 1(6), 80-83, and Mann & Whitney (1947), Annals of Mathematical Statistics 18(1), 50-60 – the primary sources. Wasserman (2004), All of Statistics, does not contain the rank-sum test.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
Ranksum(V, V)
#> $statistic
#> [1] 68
#>
#> $U
#> [1] 32
#>
#> $z
#> [1] 0
#>
#> $p_value
#> [1] 1
#>
#> $expected
#> [1] 68
#>
#> $variance
#> [1] 89.6
#>
#> $n1
#> [1] 8
#>
#> $n2
#> [1] 8
#>
#> $n_tied_groups
#> [1] 8
#>
#> $method
#> [1] "Wilcoxon rank-sum, normal approximation with tie correction"
#>
#> attr(,"class")
#> [1] "morie_rich_result" "list"
