Skip to content

Non-Parametric Tests (Mann-Whitney, Wilcoxon)

Why non-parametric tests

When data is:

  • Not normally distributed
  • Heavy-tailed
  • Contains outliers

…it can be safer to compare median/rank behavior.

Mann–Whitney U test (two independent groups)

Alternative to the independent t-test.

Mann–Whitney
import numpy as np
from scipy import stats
 
A = np.array([1, 2, 2, 3, 100])
B = np.array([1, 1, 2, 2, 3])
 
u, p = stats.mannwhitneyu(A, B, alternative="two-sided")
print("U:", u)
print("p:", p)
Mann–Whitney
import numpy as np
from scipy import stats
 
A = np.array([1, 2, 2, 3, 100])
B = np.array([1, 1, 2, 2, 3])
 
u, p = stats.mannwhitneyu(A, B, alternative="two-sided")
print("U:", u)
print("p:", p)

Wilcoxon signed-rank (paired)

Alternative to the paired t-test.

Wilcoxon
import numpy as np
from scipy import stats
 
before = np.array([10, 12, 11, 9, 13])
after  = np.array([11, 12, 12, 10, 14])
 
w, p = stats.wilcoxon(after - before)
print("W:", w)
print("p:", p)
Wilcoxon
import numpy as np
from scipy import stats
 
before = np.array([10, 12, 11, 9, 13])
after  = np.array([11, 12, 12, 10, 14])
 
w, p = stats.wilcoxon(after - before)
print("W:", w)
print("p:", p)

Notes

  • Non-parametric tests often have less power when assumptions for parametric tests are satisfied.
  • Always combine tests with visualizations.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did