8
$\begingroup$

I've been using http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.wilcoxon.html but then I realized that there is http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ranksums.html

They sound like they are pretty much the same. I always hear wilcoxons referred to as wilcoxon rank sums. In SciPy how are they different and how can I know which one to use? My data is rarely normally distributed which why I use these non-parametric tests instead of t-tests.

$\endgroup$
3
  • 3
    $\begingroup$ Check the first sentence of each help page you linked to. Calculate the Wilcoxon signed-rank test. vs Compute the Wilcoxon rank-sum statistic for two samples. ... the first goes on to explain tests the null hypothesis that two related paired samples come from the same distribution. In particular, it tests whether the distribution of the differences x - y is symmetric about zero. It is a non-parametric version of the paired T-test. while the second states The Wilcoxon rank-sum test tests the null hypothesis that two sets of measurements are drawn from the same distribution... $\endgroup$
    – Glen_b
    Sep 16, 2016 at 1:06
  • 1
    $\begingroup$ ctd... (it later mentions the Mann-Whitney). If you need more, try searching on those names. e.g. here on site: stats.stackexchange.com/search?q=signed+rank or see what Wikipedia says: en.wikipedia.org/wiki/Wilcoxon_signed-rank_test where its first sentence explains what that is. Perhaps you can use those pieces of information to better formulate your question $\endgroup$
    – Glen_b
    Sep 16, 2016 at 1:16
  • $\begingroup$ So the null hypothesis for both are that they are from the same distribution right? $\endgroup$
    – O.rka
    Sep 16, 2016 at 5:44

1 Answer 1

14
$\begingroup$

Frank Wilcoxon's 1945 paper [1] described two tests -- for "Unpaired Experiments" and "Paired Comparisons" which have come to be called the (Wilcoxon) rank sum test and the (Wilcoxon) signed rank test respectively.

So the first test is for independent (unpaired) samples and the second is for paired samples*.

* It can also be used for comparing single samples from a symmetric distribution versus some specified center of location.

The test for comparing unpaired samples was extended by Mann and Whitney in 1947. They organized it in a way that may at first seem like a different test, though the tests turn out to be equivalent. [A number of other authors suggested the same idea around the same time as Wilcoxon -- or even a bit earlier. Nevertheless the test is generally named for Wilcoxon or Mann and Whitney or both]

However, you seem to be familiar with the rank sum test so I will now focus on the signed rank test.

In the same way that the rank sum test corresponds (more or less) to an ordinary two-sample t-test, the signed rank test corresponds to a one-sample t-test on paired differences. In this case the differences are ranked in magnitude (i.e. without regard to sign) then the ranks that correspond to positive differences are summed.

This is compared with the distribution of the same statistic if the pair labels had be allocated to the pair-members arbitrarily (because if they come from the same population distribution their pair differences should be symmetrically distributed about 0, and the sign that goes with each rank would then be equally likely to be + or - when the null is true.

Conversely when the populations are different in distribution in a way that tends to make one sample larger, the statistic should tend to be large or small (depending on which sample is from the population that tends to be larger).

[Note that if the null is false, it is not required that the differences be symmetrically distributed - many books incorrectly claim this is a requirement. However, if you are focused only on location shift alternatives then the differences should be symmetric about the amount of the location-shift.]

That is, large or small sums of positive ranks (relative to what you'd expect under the null) indicate a difference in the populations in a way that indicates one group tends to be higher than the other.

Wikipedia's version of the test adds together the positive and negative ranks (with the accompanying signs instead. This shifts the center to 0 but gives an equivalent test.

The function you're calling defines the statistic differently to both of the above versions (as the smaller of the sum of positive and sum of negative ranks, which matches the original definition in Wilcoxon's paper) but the different versions of the tests are all equivalent and should give the same p-values under the same conditions.

[1] Wilcoxon, Frank (1945),
"Individual comparisons by ranking methods"
Biometrics Bulletin. 1 (6), Dec, p80–83.
(The Wikipedia page on this test offers a link to a pdf of the paper)

$\endgroup$
2
  • $\begingroup$ Great answer @Gleb_b that cleared up my questions. Is mannwhitneyu nonparametric? It looks like the data needs to follow a normal. $\endgroup$
    – O.rka
    Sep 16, 2016 at 5:46
  • 3
    $\begingroup$ As my answer already describes it's the same test as the rank sum test (up to a constant shift of the test statistic); the only real difference of import is that they've implemented handling ties for it. The normal they refer to is an approximation to the distribution of the test statistic for large samples. [They've been lazy and not actually implemented an exact table for smaller sample sizes. This is astounding to me.] $\endgroup$
    – Glen_b
    Sep 16, 2016 at 6:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.