One-sided Wilcoxon acquaintance test using scipy

I would like to fulfill the one-sided wilcoxon ranking criterion for my paired data, as I am wondering if one sample is significantly larger than another.

Scipy offers

scipy.stats.wilcoxon(x,y) 

perform a two-way test with paired samples x and y. Since I cannot accept a normal (symmetric) distribution, I cannot get a one-sided p-value from a two-sided p-value.

Can anyone now use python to get p values ​​for a one-way test?

Thanks!

+6
source share
2 answers

The P value returned by scipy.stats.wilcoxon has nothing to do with the distribution of x or y , and also the difference between them. It is determined by Wilcoxon statistics (W like this at http://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test , or T like scipy ), which is supposed to follow the normal distribution. If you check the source (in ~ python_directory \ site-packages \ scipy \ stats \ morestats.py), you will find the last few lines of def wilcoxon() :

 se = sqrt(se / 24) z = (T - mn) / se prob = 2. * distributions.norm.sf(abs(z)) return T, prob 

and

 mn = count*(count + 1.) * 0.25 se = count*(count + 1.) * (2. * count + 1.) 

Where count is the number of nonzero differences between x and y .

So, to get a one-way p value, you just need prob/2. or 1-prob/2.

Examples: In Python :

 >>> y1=[125,115,130,140,140,115,140,125,140,135] >>> y2=[110,122,125,120,140,124,123,137,135,145] >>> ss.wilcoxon(y1, y2) (18.0, 0.5936305914425295) 

In R :

 > wilcox.test(y1, y2, paired=TRUE, exact=FALSE, correct=FALSE) Wilcoxon signed rank test data: y1 and y2 V = 27, p-value = 0.5936 alternative hypothesis: true location shift is not equal to 0 > wilcox.test(y1, y2, paired=TRUE, exact=FALSE, correct=FALSE, alt='greater') Wilcoxon signed rank test data: y1 and y2 V = 27, p-value = 0.2968 alternative hypothesis: true location shift is greater than 0 
+8
source

If you have enough observations (and another hypothesis), I remember that the Scipy Mann-Withney test is one-sided: http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mannwhitneyu.html

+1
source

Source: https://habr.com/ru/post/943950/


All Articles