Python和Matlab rank sum test区别(秩和检验)

46 篇文章 3 订阅
11 篇文章 1 订阅

1.Matlab rank sum test

matlab中的rank sum test基本没有什么坑,直接拿来用就行,两组数据不一样长都可以。

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.

p = ranksum(x,y)

[p,h] = ranksum(x,y) also returns a logical value indicating the test decision. The result h = 1 indicates a rejection of the null hypothesis, and h = 0 indicates a failure to reject the null hypothesis at the 5% significance level.

[p,h] = ranksum(x,y)

[p,h,stats] = ranksum(x,y) also returns the structure stats with information about the test statistic.

[p,h,stats] = ranksum(x,y)

[___] = ranksum(x,y,Name,Value) returns any of the output arguments in the previous syntaxes, for a rank sum test with additional options specified by one or more Name,Value pair arguments.

[___] = ranksum(x,y,Name,Value)

2.Python rank sum test

https://stackoverflow.com/questions/60462532/how-to-use-1-side-wilcoxon-rank-sum-test-python/60465812#60465812

讲道理Python同样得到和Matlab一样的结果,只是有一点需要注意。

首先需要导入包

from scipy import stats

之后使用

scipy.stats.mannwhitneyu(x,y,alternative="two-sided")

即可保证两者一致。

import numpy as np
from rpy2.robjects import FloatVector
from rpy2.robjects.packages import importr
stats = importr('stats')

x = np.random.poisson(1,size=20)
y = np.random.poisson(3,size=20)

test = stats.wilcox_test(FloatVector(x),FloatVector(y),alternative='less')
d = { key : test.rx2(key)[0] for key in ['statistic','p.value','alternative'] }
d

References

Reference

https://docs.scipy.org/doc/scipy/reference/stats.html

https://ww2.mathworks.cn/help/stats/ranksum.html

https://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值