python 的 scipy.stats.ranksums 和 R 的 wilcox.test 都应该计算 Wilcoxon 秩和检验的两侧 p 值。但是当我在相同的数据上运行这两个函数时,我得到的 p 值相差几个数量级:
回复:
> x=c(57.07168,46.95301,31.86423,38.27486,77.89309,76.78879,33.29809,58.61569,18.26473,62.92256,50.46951,19.14473,22.58552,24.14309)
> y=c(8.319966,2.569211,1.306941,8.450002,1.624244,1.887139,1.376355,2.521150,5.940253,1.458392,3.257468,1.574528,2.338976)
> print(wilcox.test(x, y))
Wilcoxon rank sum test
data: x and y
W = 182, p-value = 9.971e-08
alternative hypothesis: true location shift is not equal to 0
Python:
>>> x=[57.07168,46.95301,31.86423,38.27486,77.89309,76.78879,33.29809,58.61569,18.26473,62.92256,50.46951,19.14473,22.58552,24.14309]
>>> y=[8.319966,2.569211,1.306941,8.450002,1.624244,1.887139,1.376355,2.521150,5.940253,1.458392,3.257468,1.574528,2.338976]
>>> scipy.stats.ranksums(x, y)
(4.415880433163923, 1.0059968254463979e-05)
所以 R 给了我 1e-7 而 Python 给了我 1e-5。
这种差异从何而来,哪一个是“正确”的 p 值?