Statistics: ranksum

### Function Reference: `ranksum`

statistics: p = ranksum (x, y)
statistics: p = ranksum (x, y, alpha)
statistics: p = ranksum (x, y, alpha, Name, Value)
statistics: p = ranksum (x, y, Name, Value)
statistics: [p, h] = ranksum (x, y, …)
statistics: [p, h, stats] = ranksum (x, y, …)

Wilcoxon rank sum test for equal medians. This test is equivalent to a Mann-Whitney U-test.

`p = ranksum (x, y)` returns the p-value of a two-sided Wilcoxon rank sum test. It tests the null hypothesis that two independent samples, in the vectors X and Y, come from continuous distributions with equal medians, against the alternative hypothesis that they are not. x and y can have different lengths and the test assumes that they are independent.

`ranksum` treats NaN in x, y as missing values. The two-sided p-value is computed by doubling the most significant one-sided value.

`[p, h] = ranksum (x, y)` also returns the result of the hypothesis test with `h = 1` indicating a rejection of the null hypothesis at the default alpha = 0.05 significance level, and `h = 0` indicating a failure to reject the null hypothesis at the same significance level.

`[p, h, stats] = ranksum (x, y)` also returns the structure stats with information about the test statistic. It contains the field `ranksum` with the value of the rank sum test statistic and if computed with the "approximate" method it also contains the value of the z-statistic in the field `zval`.

`[…] = ranksum (x, y, alpha)` or alternatively `[…] = ranksum (x, y, "alpha", alpha)` returns the result of the hypothesis test performed at the significance level ALPHA.

`[…] = ranksum (x, y, "method", M)` defines the computation method of the p-value specified in M, which can be "exact", "approximate", or "oldexact". M must be a single string. When "method" is unspecified, the default is: "exact" when `min (length (x), length (y)) < 10` and `length (x) + length (y) < 10`, otherwise the "approximate" method is used.

- "exact" method uses full enumeration for small total sample size (< 10), otherwise the network algorithm is used for larger samples.
- "approximate" uses normal approximation method for computing the p-value.
- "oldexact" uses full enumeration for any sample size. Note, that this option can lead to out of memory error for large samples. Use with caution!

`[…] = ranksum (x, y, "tail", tail)` defines the type of test, which can be "both", "right", or "left". tail must be a single string.

- "both" – "medians are not equal" (two-tailed test, default)
- "right" – "median of X is greater than median of Y" (right-tailed test)
- "left" – "median of X is less than median of Y" (left-tailed test)

Note: the rank sum statistic is based on the smaller sample of vectors x and y.

Source Code: ranksum