scipy.stats.wilcoxon返回的P值与x或y的分布无关,也与它们之间的区别无关。它由 Wilcoxon 检验统计量确定(W 与http://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test 相同,或 T 与scipy 相同),假定服从正态分布。如果你查看源码(在~python_directory\site-packages\scipy\stats\morestats.py),你会发现def wilcoxon()的最后几行:
se = sqrt(se / 24)
z = (T - mn) / se
prob = 2. * distributions.norm.sf(abs(z))
return T, prob
和:
mn = count*(count + 1.) * 0.25
se = count*(count + 1.) * (2. * count + 1.)
其中count 是x 和y 之间的非零差数。
因此,要获得单侧 p 值,您只需要 prob/2. 或 1-prob/2.
示例:
在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)
在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