Compute the Wilcoxon rank-sum statistic for two samples.
The Wilcoxon rank-sum test tests the null hypothesis that two sets of measurements are drawn from the same distribution. The alternative hypothesis is that values in one sample are more likely to be larger than the values in the other sample.
This test should be used to compare two samples from continuous distributions. It does not handle ties between measurements in x and y. For tie-handling and an optional continuity correction see
The data from the two samples.
The test statistic under the large-sample approximation that the rank sum statistic is normally distributed.
The two-sided p-value of the test.
We can test the hypothesis that two independent unequal-sized samples are drawn from the same distribution with computing the Wilcoxon rank-sum statistic.
>>> from scipy.stats import ranksums >>> sample1 = np.random.uniform(-1, 1, 200) >>> sample2 = np.random.uniform(-0.5, 1.5, 300) # a shifted distribution >>> ranksums(sample1, sample2) RanksumsResult(statistic=-7.887059, pvalue=3.09390448e-15) # may vary
The p-value of less than
0.05indicates that this test rejects the hypothesis at the 5% significance level.