【发布时间】:2017-04-12 19:58:11
【问题描述】:
所以我遇到了一个奇怪的差异,这取决于我如何使用 R 中的 wilcox.test() 函数分析相同的数据。在此示例中,我正在比较两组中的值。我可以将它们作为两个单独的向量提供给 wilcox.test 函数,或者我可以给函数一个 data.frame 并使用一个公式来指定我想要进行的比较。奇怪的是,我最终得到了不同的测试统计值 (W),这取决于我使用的输入法。我在下面包含了一个示例(R v3.3.1):
#Prepare test data
wt_exp = c(0.59, 0.56, 0.45, 0.59, 0.54, 0.13, 0.25, 0.10, 0.15)
kd_exp = c(0.27, 0.27, 0.33, 0.25, 0.22, 0.2, 0.16, 0.2, 0.36, 0.58, 0.51)
test.data_frame =
data.frame(Expression = c(wt_exp, kd_exp),
Genotype = rep(c("WT", "KD"),
times=c(length(wt_exp), length(kd_exp))))
#Wilcox test using two input vectors
wilcox.test(wt_exp, kd_exp)
# Result:
# Wilcoxon rank sum test with continuity correction
#
# data: wt_exp and kd_exp
# W = 55.5, p-value = 0.6756
# alternative hypothesis: true location shift is not equal to 0
#
# Warning message:
# In wilcox.test.default(wt_exp, kd_exp) :
# cannot compute exact p-value with ties
#Wilcox test using data.frame and formula
wilcox.test(Expression ~ Genotype, data=test.data_frame)
# Result:
# Wilcoxon rank sum test with continuity correction
#
# data: Expression by Genotype
# W = 43.5, p-value = 0.6756
# alternative hypothesis: true location shift is not equal to 0
#
# Warning message:
# In wilcox.test.default(x = c(0.27, 0.27, 0.33, 0.25, 0.22, 0.2, :
# cannot compute exact p-value with ties
虽然我意识到在这种情况下 p 值是相同的,但我将进行数千次这样的测试,并且我想确定造成这种情况的原因,所以我不需要保留抽查结果。想法?
【问题讨论】:
标签: r