python 中Wilcoxon rank-sum 和 R 中的 wilcox.test

参考网页:http://stackoverflow.com/questions/12797658/pythons-scipy-stats-ranksums-vs-rs-wilcox-test


python scipy 中的 ranksums(x,y) 相当于  

R中的 wilcox.text(x,y,exact=FALSE,correct=FALSE)


#### python  code


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 code

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)


wilcox.test(x, y, exact=FALSE, correct=FALSE)


   Wilcoxon rank sum test


data:  x and y

W = 182, p-value = 1.006e-05

alternative hypothesis: true location shift is not equal to 0




scipy.stats.ranksums(x, y)[source]

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. For tie-handling and an optional continuity correction see scipy.stats.mannwhitneyu.





转载自:http://blog.sciencenet.cn/blog-468005-1022320.html






在R语言中,`wilcox_test`函数`wilcox.test`函数都是用于执行Wilcoxon检验Wilcoxon Rank-Sum Test)的函数,但它们来自不同的软件包。 `wilcox_test`函数属于`coin`软件包(也称为Conditional Inference Procedures),它提供了一些非参数统计方法的实现。该函数的基本语法如下: ```R wilcox_test(formula, data) ``` 其中,`formula`是一个公式对象,描述了要进行Wilcoxon检验的变量组合方式,`data`是要进行分析的数据框。 举个例子,假设有一个名为`df`的数据框,其中有两个组别的变量`group`一个连续变量`value`,我们想要比较这两个组别在`value`上的差异。可以使用`wilcox_test`函数实现: ```R library(coin) result <- wilcox_test(value ~ group, data = df) ``` 执行以上代码后,将会执行Wilcoxon检验,并将结果保存在`result`对象中。 另一方面,`wilcox.test`函数属于R的基本统计软件包,它也提供了Wilcoxon检验的实现。该函数的基本语法如下: ```R wilcox.test(x, y = NULL) ``` 其中,`x`是一个数值向量,表示第一组样本,`y`是一个可选的数值向量,表示第二组样本。如果只提供了一个向量,则执行的是一样本Wilcoxon检验。 举个例子,假设有两个数值向量`x``y`,我们想要比较这两个向量的差异。可以使用`wilcox.test`函数实现: ```R result <- wilcox.test(x, y) ``` 执行以上代码后,将会执行Wilcoxon检验,并将结果保存在`result`对象中。 需要注意的是,`wilcox_test`函数返回的是一个复杂的对象,包含了更多的统计信息可视化选项。而`wilcox.test`函数返回的是一个简单的假设检验结果。 希望以上信息能够解答你的问题!如果还有其他问题,请继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值