python - python中Matlab的ranksum相当于什么?

标签 python matlab scipy statistical-test

scipy.stats.ranksumswilcoxonmannwhitneyu 都给出了与 Matlab 的 ranksum 不同的结果。

最佳答案

这取决于您使用的选项。检查以下示例:

1-MATLAB

rng('default') % for reproducibility
x = unifrnd(0,1,20,1);
y = unifrnd(0.25,1.25,20,1);
p = ranksum(x,y);
p =
   0.2503

2-Python (为了保持一致,我没有再次生成数字,但我已将 MATLAB 中生成的数字移至 Python 脚本)

from scipy.stats import *
import numpy as np

y=np.array([0.905740699156587, 0.285711678574190, 1.09912930586878, 1.18399324775755, 0.928735154857774, 1.00774013057833, 0.993132468124916, 0.642227019534168, 0.905477890177557, 0.421186687811562, 0.956046088019609, 0.28183284637742, 0.526922984960890, 0.296171390631154, 0.347131781235848, 1.07345782832729, 0.944828622975817, 0.567099480060861, 1.20022204883835, 0.284446080502909])
x=np.array([0.814723686393179,  0.905791937075619,  0.126986816293506,  0.913375856139019,  0.632359246225410,  0.0975404049994095, 0.278498218867048,  0.546881519204984,  0.957506835434298,  0.964888535199277,  0.157613081677548,  0.970592781760616,  0.957166948242946,  0.485375648722841,  0.800280468888800,  0.141886338627215,  0.421761282626275,  0.915735525189067,  0.792207329559554,  0.959492426392903])

p = ranksums(x,y)
print p

RanksumsResult(statistic=-1.1631538287209875, pvalue=0.24476709560795806)

此结果具有以下选项:

1- 对于 MATLAB:

p = ranksum(x,y) returns the p-value of a two-sided Wilcoxon rank sum test. ranksum tests the null hypothesis that data in x and y are samples from continuous distributions with equal medians, against the alternative that they are not. The test assumes that the two samples are independent. x and y can have different lengths. This test is equivalent to a Mann-Whitney U-test.

2- 对于Python:

Compute the Wilcoxon rank-sum statistic for two samples. The Wilcoxon rank-sum test tests the null hypothesis that two sets of measurements are drawn from the same distribution. The alternative hypothesis is that values in one sample are more likely to be larger than the values in the other sample. This test should be used to compare two samples from continuous distributions. It does not handle ties between measurements in x and y.


另一个例子

这里我使用相同的数据,具有相同的 MATLAB 函数,但选项不同。现在您可以看到结果与 Scipy 中的 mannwhitneyu 函数的结果相同。

MATLAB

[p,h,stats] = ranksum(x,y,'alpha',0.01,'tail','left','method','exact');
p = 
    0.1267

Python

m = mannwhitneyu(xx, yy, use_continuity=True)
print m

MannwhitneyuResult(statistic=157.0, pvalue=0.12514839875175593)

关于python - python中Matlab的ranksum相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31709475/

相关文章:

python - Matplotlib 所以日志轴在指定点只有次要刻度线标签。还可以更改颜色栏中刻度标签的大小

python - 在 Python 中实现 Paypal REST API

matlab - 用于 MATLAB 的多标签 AdaBoost

matlab - 如何在matlab中获得唯一的数字对,其中两个数字之前在矩阵中没有重复过

python - 在 32 位 Windows 7 机器上的 Python 3.5 中安装 scipy

scipy - scipy.linalg.orth() 中的 "automatic cutoff"是什么?

Python继承 - 如何禁用函数

python - 如何动态更改字符串中变量的值?

python - 遍历 Python 列表中的每两个元素

matlab - 如何从矩阵的每一行中减去一个向量?