pingouin.wilcoxon

pingouin.
wilcoxon
(x, y, tail='twosided')[source] Wilcoxon signedrank test. It is the nonparametric version of the paired Ttest.
 Parameters
 x, yarray_like
First and second set of observations.
x
andy
must be related (e.g repeated measures) and, therefore, have the same number of samples. Note that a listwise deletion of missing values is automatically applied. tailstring
Specify whether to return ‘onesided’ or ‘twosided’ pvalue. Can also be ‘greater’ or ‘less’ to specify the direction of the test. If
tail='onesided'
, the alternative of the test will be automatically detected by looking at the sign of the median of the differences betweenx
andy
. For instance, ifnp.median(x  y) > 0
andtail='onesided'
, Pingouin will automatically settail='greater'
and vice versa.
 Returns
 statspandas DataFrame
Test summary
'Wval' : Wvalue 'pval' : pvalue 'RBC' : matched pairs rankbiserial correlation (effect size) 'CLES' : common language effect size
See also
Notes
The Wilcoxon signedrank test 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. A continuity correction is applied by default (see
scipy.stats.wilcoxon()
for details).The rank biserial correlation is the difference between the proportion of favorable evidence minus the proportion of unfavorable evidence (see Kerby 2014).
The common language effect size is the probability (from 0 to 1) that a randomly selected observation from the first sample will be greater than a randomly selected observation from the second sample.
Warning
Versions of Pingouin below 0.2.6 gave wrong twosided pvalues for the Wilcoxon test. Pvalues were accidentally squared, and therefore smaller. This issue has been resolved in Pingouin>=0.2.6. Make sure to always use the latest release.
References
 1
Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics bulletin, 1(6), 8083.
 2
Kerby, D. S. (2014). The simple difference formula: An approach to teaching nonparametric correlation. Comprehensive Psychology, 3, 11IT.
 3
McGraw, K. O., & Wong, S. P. (1992). A common language effect size statistic. Psychological bulletin, 111(2), 361.
Examples
Wilcoxon test on two related samples.
>>> import numpy as np >>> import pingouin as pg >>> 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] >>> pg.wilcoxon(x, y, tail='twosided') Wval tail pval RBC CLES Wilcoxon 20.5 twosided 0.285765 0.379 0.583
Compare with SciPy
>>> import scipy >>> scipy.stats.wilcoxon(x, y, correction=True) WilcoxonResult(statistic=20.5, pvalue=0.2857652190231508)
Onesided tail: one can either manually specify the alternative hypothesis
>>> pg.wilcoxon(x, y, tail='greater') Wval tail pval RBC CLES Wilcoxon 20.5 greater 0.876244 0.379 0.583
>>> pg.wilcoxon(x, y, tail='less') Wval tail pval RBC CLES Wilcoxon 20.5 less 0.142883 0.379 0.583
Or simply leave it to Pingouin, using the ‘onesided’ argument, in which case Pingouin will look at the sign of the median of the differences between
x
andy
and ajust the tail based on that:>>> np.median(np.array(x)  np.array(y)) 1.5
The median is negative, so Pingouin will test for the alternative hypothesis that the median of the differences is negative (= less than 0).
>>> pg.wilcoxon(x, y, tail='onesided') # Equivalent to tail = 'less' Wval tail pval RBC CLES Wilcoxon 20.5 less 0.142883 0.379 0.583