R语言统计绘图

谈谈t检验和Wilcoxon秩和检验

2021-04-07  本文已影响0人  Seurat_Satija

t检验和wilcoxon秩和检验是用于检验两独立样本定量资料的常用方法。t检验是参数方法,需要资料满足正态性和方差齐性的假设,而Wilcoxon秩和检验是非参数方法。我一直感觉,参数方法比非参数方法检验效能更高。其实,我忘掉了一个前提,这个结论只有在资料符合t检验假设的情况下才成立。当资料不符合正态性和方差齐性时,t检验的。

R里面,做t检验和wilcoxon秩和检验的函数分别是:t.test, wilcox.test

其中t.test的帮助文件中举了这样一个有趣的例子:

t.test(1:10,y=c(7:20))

Welch Two Sample t-test data: 1:10 and c(7:20)

t = -5.4349, df = 21.982, p-value = 1.855e-05

alternative hypothesis: true difference in means is not equal to 0

t.test(1:10,y=c(7:20,200))

Welch Two Sample t-test data: 1:10 and c(7:20, 200)

 t = -1.6329, df = 14.165, p-value = 0.1245

alternative hypothesis: true difference in means is not equal to 0

首先注意到自由度不为整数,事实上,t.test默认的是用Welch modification来修正t统计量和自由度的计算,《卫生统计学》(赵耐青,陈峰主编)P97 中也有介绍。

那么我们来看这两个检验:第二个检验中y仅仅比第一个中的y多了一个200,这样y的均数肯定是增加了,感觉和x的差异也更大了,但是检验反而不显著了。因为增加的200大大地增大了方差,从而t大大缩小了。同样的例子,我们用wilcox.test:

> wilcox.test(1:10,y=c(7:20,200))

Wilcoxon rank sum test with continuity correction data: 1:10 and c(7:20, 200) W = 8, p-value = 0.0002229 alternative hypothesis: true location shift is not equal to 0

alternative hypothesis: true difference in means is not equal to 0

可以看出检验结果显著。

因此,在数据呈严重偏态分布或有离群值的时候,可不要用t检验。它可能检验不出很明显的均数差异。

上一篇 下一篇

猜你喜欢

热点阅读