Foundations to Frontier
Tests
A. Mathematical Foundations › A5 Statistics › Descriptive and inferential statistics

Non-parametric Tests: Mann–Whitney, Wilcoxon, Permutation Tests

Tests that don't assume a normal distribution. Rank tests (Mann–Whitney for two groups, Wilcoxon signed-rank for pairs, the sign test) replace values by their order, so a single wild outlier can't dominate; permutation tests compute exact p-values by reshuffling group labels, valid under the null with no distributional assumptions. You will see when rank tests beat the t-test (heavy tails) and when they barely lose (normal data, 95% efficiency), why five seeds per algorithm can never give p < 0.008, and the matching robust effect size (Hodges–Lehmann).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Who finished first?

To compare two teams of runners, you could average their times, but one runner who tripped and took an hour would wreck the average. Instead, line everyone up in finishing order and ask: are team A’s runners mostly ahead? That uses only ranks, not how big each gap was, so one disaster barely matters.

Another trick: if the teams don’t really differ, the labels “A” and “B” are arbitrary. Shuffle them randomly many times and see how often a shuffled split looks as different as the real one. That’s a permutation test, and it needs no formula at all.

When outliers lurk, ranks beat means
noise:
group A (shifted)group B
Welch t-test
32.0%
Mann–Whitney (ranks)
77.0%
power to detect a shift of 1.00 with n = 25 per group, over 600 experiments
With normal noise the t-test is slightly better: Mann–Whitney's efficiency is 3/π ≈ 95%. With heavy tails a few huge values inflate the sd and the t-test loses most of its power, while ranks ignore how extreme an outlier is. Both keep their 5% level at shift 0. Values beyond the plot range are drawn at its edge.
Why engineers care

Robot task times, RL returns over seeds, and network latencies are skewed and full of outliers (a stalled run, a collapsed seed). Rank and permutation tests give trustworthy answers where the t-test’s normality assumption fails.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A rank test uses…
  2. 2. One huge outlier affects a rank test…
  3. 3. A permutation test reshuffles…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Mann–Whitney (Wilcoxon rank-sum) test

Rank all na+nbn_a + n_b values together, with ties given average ranks. Let RaR_a be the sum of group A’s ranks, and U=Ra−na(na+1)/2U = R_a - n_a(n_a + 1)/2. Equivalently, UU counts the pairs (ai,bj)(a_i, b_j) with ai>bja_i > b_j. Under H0H_0 (same distribution), EU=nanb/2\mathbb EU = n_an_b/2 and Var⁡U=nanb(N+1)/12\operatorname{Var}U = n_an_b(N + 1)/12. Use the normal approximation for moderate nn, or exact tables when nn is small. Interpretation: U/(nanb)U/(n_an_b) estimates P(A>B)P(A > B).

Wilcoxon signed-rank (paired data)

Rank the absolute differences ∣di∣\lvert d_i\rvert (dropping zeros), and sum the ranks of the positive ones: W+W^+. Under H0H_0 (differences symmetric about 0), EW+=n(n+1)/4\mathbb EW^+ = n(n + 1)/4 and Var⁡=n(n+1)(2n+1)/24\operatorname{Var} = n(n + 1)(2n + 1)/24.

Sign test

Count how many differences are positive. Under H0H_0 (median difference 0), that count is Bin(n,1/2)\text{Bin}(n, 1/2). It’s the most assumption-light test: 9 wins out of 10 gives p=0.021p = 0.021.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Values 10, 20, 20, 30: the ranks are…
  2. 2. E U under H₀ with nₐ = n_b = 10?
  3. 3. The sign test uses the distribution…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Permutation tests

Under H0H_0: “the group labels don’t matter” (exchangeability). Every relabelling of the pooled data is equally likely. The exact p-value is the fraction of the (Nna)\binom{N}{n_a} relabellings whose statistic is at least as extreme as the observed one.

  • Any statistic works: difference in means, medians, trimmed means, or a classifier’s accuracy.
  • For large NN, sample random permutations. Report (#extreme+1)/(B+1)(\#\text{extreme} + 1)/(B + 1), which keeps the test valid.
  • Granularity: with 5 vs 5 seeds there are only 252 splits. A two-sided p can never be below 2/252≈0.0082/252\approx0.008. With 3 vs 3, never below 0.1.

Power: ranks vs means

The asymptotic relative efficiency of Mann–Whitney vs the t-test is 3/π≈0.9553/\pi\approx0.955 for normal data. You lose 5% at most. It’s never below 0.864 for any distribution, and it’s unbounded for heavy tails. Mann–Whitney is a safe default.

Robust effect size

Report the Hodges–Lehmann shift, the median of all pairwise differences ai−bja_i - b_j, with a rank-based CI. Or report P^(A>B)=U/(nanb)\hat P(A > B) = U/(n_an_b). Means and t-intervals mislead when one seed collapses.

🐍 Exercise 1: rank tests and a permutation test
Implement average ranks, Mann–Whitney with tie correction, Wilcoxon signed-rank and a Monte Carlo permutation test. Check the 5% type I error, and show that with heavy-tailed noise Mann–Whitney is much more powerful than the t-test.
📝 Quick check (Level 2)
0/3 answered
  1. 1. For normal data, Mann–Whitney's efficiency relative to the t-test is…
  2. 2. The smallest two-sided permutation p with 5 vs 5 observations?
  3. 3. A permutation test's validity requires…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

The null distribution of U

Under H0H_0 with continuous data, every assignment of ranks to groups is equally likely. U=∑i,j1{ai>bj}U = \sum_{i,j}\mathbf 1\{a_i > b_j\} is a sum of nanbn_an_b indicators, each with mean 1/2. The variance comes from counting the covariances between indicators that share an aia_i or a bjb_j: Var⁡U=nanb(na+nb+1)12\operatorname{Var}U = \frac{n_an_b(n_a + n_b + 1)}{12}. A CLT for U-statistics (Hoeffding, 1948) gives asymptotic normality. Ties reduce the variance by nanb12∑(t3−t)N(N−1)\frac{n_an_b}{12}\frac{\sum(t^3 - t)}{N(N - 1)}.

Why permutation tests are exact

Let TT be any statistic and GG the group of label permutations. Under exchangeability, the data XX and gXgX have the same distribution for every g∈Gg\in G. So T(X)T(X) is uniformly distributed over the multiset {T(gX)}\{T(gX)\}, and the rank of the observed statistic among them is uniform. Rejecting when it falls in the top α\alpha fraction has probability ≤α\le\alpha, for any sample size and any distribution. ∎ Fisher’s “lady tasting tea” (1935) was the first example.

What rank tests actually test

Mann–Whitney tests P(A>B)=1/2P(A > B) = 1/2 (stochastic equality), not equality of means or medians. With equal shapes, a shift in location is detected. With different shapes (one group more spread), it can reject even when the medians are equal. State the hypothesis you mean.

Exercise 3.1: Show E U = nₐn_b/2 under H₀

For continuous data and identical distributions, P(ai>bj)=1/2P(a_i > b_j) = 1/2 by symmetry. Sum over the nanbn_an_b pairs.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Permutation tests are valid for…
  2. 2. Mann–Whitney fundamentally tests…
  3. 3. Ties make Var U…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Comparing RL algorithms over a handful of seeds

Final returns over 5 seeds per algorithm are typical, and heavy-tailed: one seed of algorithm B collapsed to 120. Welch’s t is diluted by that seed and calls the difference insignificant. Yet every A seed beat every B seed. The exact permutation test gives the smallest p achievable with 5 vs 5, which is 2/252 ≈ 0.008, and that floor is itself a warning about how little 5 seeds can show. Report the Hodges–Lehmann shift (62 here, not the 183 mean difference that the collapsed seed inflates) and P^(A>B)=1\hat P(A > B) = 1. Run more seeds when you can (Henderson et al., 2018; Colas, Sigaud and Oudeyer, 2019; Agarwal et al., 2021).

🐍 Exercise 2 (research): exact permutation test for 5 vs 5 seeds
Enumerate all 252 splits of 10 seeds to get the exact two-sided permutation p for the difference in returns. Show that it equals the floor 2/252, that a Monte Carlo permutation test agrees, and that the Welch t statistic is diluted by one collapsed seed.

Non-parametric tests in AI, robotics and aerospace

  • Algorithm comparison. Wilcoxon signed-rank across datasets for two classifiers, and Friedman + Nemenyi for many (Demšar, 2006). Permutation tests on per-example losses compare models on the same test set.
  • Feature importance. Permutation importance scores a feature by shuffling it and measuring the performance drop (Breiman, 2001).
  • Latency and timing analysis. Real-time task durations are skewed with long tails, so rank tests and quantile comparisons are standard for comparing schedulers or middleware versions.
  • Two-sample tests for shift. Kolmogorov–Smirnov, energy-distance and kernel (MMD) tests, calibrated by permutation, detect when deployment data differ from training data.
  • Randomization inference for A/B tests on robot fleets: re-randomize the actual assignment to get exact p-values (Fisher’s sharp null).

References

  1. H. Mann, D. Whitney (1947). “On a test of whether one of two random variables is stochastically larger than the other.” Annals of Mathematical Statistics, 18(1).
  2. F. Wilcoxon (1945). “Individual comparisons by ranking methods.” Biometrics Bulletin, 1(6).
  3. R. A. Fisher (1935). The Design of Experiments. Oliver & Boyd.
  4. E. Pitman (1937). “Significance tests which may be applied to samples from any populations.” JRSS Supplement, 4(1).
  5. W. Hoeffding (1948). “A class of statistics with asymptotically normal distribution.” Annals of Mathematical Statistics, 19(3).
  6. J. Hodges, E. Lehmann (1963). “Estimates of location based on rank tests.” Annals of Mathematical Statistics, 34(2).
  7. P. Good (2005). Permutation, Parametric, and Bootstrap Tests of Hypotheses, 3rd ed. Springer.
  8. P. Henderson et al. (2018). “Deep reinforcement learning that matters.” AAAI.
  9. C. Colas, O. Sigaud, P.-Y. Oudeyer (2019). “A Hitchhiker’s guide to statistical comparisons of reinforcement learning algorithms.” ICLR RML workshop.
  10. L. Breiman (2001). “Random forests.” Machine Learning, 45.