我想测试一下这两个样本之间的均值是否存在显着差异:
withincollaraccuracyknn<-c(0.960, 0.993,0.975,0.967,0.968,0.948)
withincollaraccuracytree<-c(0.953,0.947,0.897,0.943,0.933,0.879)
运行Shapiro-Wilk测试后,数据可以正常分布:
> sh<-c(0.960,0.993,0.975,0.967,0.968,0.948,0.953,0.947,0.897,0.943,0.933,0.879)
> shapiro.test(sh)
Shapiro-Wilk normality test
data: sh
W = 0.91711, p-value = 0.2628
但是,使用t.test()
或wilcox.test()
会产生不同的p值:
> t.test(withincollaraccuracyknn,withincollaraccuracytree)
Welch Two Sample t-test
data: withincollaraccuracyknn and withincollaraccuracytree
t = 3.1336, df = 7.3505, p-value = 0.01552
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.01090532 0.07542802
sample estimates:
mean of x mean of y
0.9685000 0.9253333
> wilcox.test(withincollaraccuracyknn,withincollaraccuracytree)
Wilcoxon rank sum test
data: withincollaraccuracyknn and withincollaraccuracytree
W = 35, p-value = 0.004329
alternative hypothesis: true location shift is not equal to 0
有人可以让我知道为什么吗?在Mann-Whitney U检验的Wikipedia页面上指出:“对于正态分布,它的效率几乎与t检验一样。”
请注意,如果数据不是正态分布的,则为Warning
:
> withincollarprecisionknn<-c(0.985,0.995,0.962,1,0.982,0.990)
> withincollarprecisiontree<-c(1,0.889,0.96,0.953,0.926,0.833)
>
> sh<-c(0.985,0.995,0.962,1,0.982,0.990,1,0.889,0.96,0.953,0.926,0.833)
>
> shapiro.test(sh)
Shapiro-Wilk normality test
data: sh
W = 0.82062, p-value = 0.01623
>
>
> wilcox.test(withincollarprecisionknn,withincollarprecisiontree)
Wilcoxon rank sum test with continuity correction
data: withincollarprecisionknn and withincollarprecisiontree
W = 30.5, p-value = 0.05424
alternative hypothesis: true location shift is not equal to 0
Warning message:
In wilcox.test.default(withincollarprecisionknn, withincollarprecisiontree) :
cannot compute exact p-value with ties
感谢您的帮助。请注意,我需要对其他没有正态分布数据的数据集进行类似的分析,因此使用wilcox.test()
代替t.test()
将是一个优势!