Exact statistic for Wilcoxon rank-sum / Man-Whitney-U test

Viewed 201

I want to compute a ranksum test statistic for a small sample (n=32). scipy.stats.mannwhitneyu uses a normal approximation for the test statistic and the associated p-value (see here). For small samples, this might be misleading.

Is there a way in python to compute exact test statistics and/or associated p-values (as described here, just not in excel of course)?

[R has such an option, see here but I would prefer to stay in python.]

1 Answers

Looks like pingouin deploys straightforward brute-force approach. On small samples it indeed gives you different results for p-value

Code, Python 3.9 Win10 x64

import numpy as np
import pingouin as pg

import scipy.stats as st

x = [20, 22, 19, 20, 22, 18, 24, 20, 19, 24, 26, 13]
y = [38, 37, 33, 29, 14, 12, 20, 22, 17, 25, 26, 16]

print(pg.wilcoxon(x, y, tail='two-sided'))

st.wilcoxon(x, y, zero_method='wilcox', alternative='two-sided')
Related