配对样本Mann Whitney Wilcoxon测试不起作用

时间:2018-11-19 18:37:51

标签: r

我正在尝试进行配对的Mann Whitney U测试。我的每个测试的样本都非常不同,并且通过t.test确实会产生不同的结果,但是对于MW测试,结果是相同的。相比之下,MW测试的默认设置可以正常工作,并且给出不同的结果。有任何想法吗?随附的代码包含我的整体数据和测试功能的样本。包含了t.test以表明该测试产生了不同的结果:

x1 <- c(26.33323, 26.69508, 26.25390, 18.78399, 24.11386, 23.94950, 
23.77843, 21.09932, 17.71425, 19.03429, 20.01796, 19.86626, 12.84303)
x2 <- c(20.82535, 20.27921, 17.99138, 10.40184, 23.23184, 22.56530, 
18.69153, 18.33580, 13.83343, 18.22934, 15.21738, 10.07495, 9.93721)

y1 <- c(169.73751, 134.85579, 122.62475, 67.87308, 110.10757, 125.72300, 
133.87937, 135.56772, 79.41600, 96.92930, 97.92528, 68.62409, 40.21653)
y2 <- c(92.88698, 54.23404, 51.58410, 21.72830, 72.02835, 70.74432, 
69.52055, 89.59934, 49.08684, 79.98573, 50.58707, 22.80362, 22.49185)

wilcox.test(x1, x2, paired = TRUE)
wilcox.test(y1, y2, paired = TRUE)

t.test(x1, x2, paired = TRUE)
t.test(y1, y2, paired = TRUE)

1 个答案:

答案 0 :(得分:0)

测试未按预期执行。也许看到wilcox.test的R中的算术会有所帮助。

Wikipedia page example开始,下面是wilcox.text(x, y, paired = TRUE)或Wilcoxon签名等级测试的步骤:

# calculate pair-wise differences
x_diffs <- x1 - x2 
y_diffs <- y1 - y2

# rank them
x_ranks <- rank(x_diffs)
y_ranks <- rank(y_diffs)

# adjust ranks by the original sign of each difference
x_ranks_signed <- rank(x_diffs) * sign(x_diffs)
y_ranks_signed <- rank(y_diffs) * sign(y_diffs)

# sum them for the test statistic
sum(x_ranks_signed)
sum(y_ranks_signed)

在您的示例中,两个2值都小于1值,因此,由于所有增量都是正数,因此排名不会乘以-1。由于xy的长度13相同,因此对于两个测试,您正确地获得了相同的测试统计量91或sum(1:13)

要获得不同的测试统计信息,您需要引入一些负增量值,即使x3大于x1

x3 <- c(28, 29, 17.99138, 10.40184, 23.23184, 22.56530, 
        18.69153, 18.33580, 13.83343, 18.22934, 15.21738, 10.07495, 9.93721)

wilcox.test(x1, x2, paired = T) # same old test statistic and p-value

    Wilcoxon signed rank test

data:  x1 and x2
V = 91, p-value = 0.0002441
alternative hypothesis: true location shift is not equal to 0

wilcox.test(x1, x3, paired = T) # new negative deltas >> new test stat and new p-value

    Wilcoxon signed rank test

data:  x1 and x3
V = 82, p-value = 0.008057
alternative hypothesis: true location shift is not equal to 0