【发布时间】:2020-10-01 08:12:06
【问题描述】:
据我所知,当应用于具有一个解释变量的数据时,t 检验应提供与 ANOVA 相同的结果(相同的 p 值)。为了测试这一点,我运行了以下代码来比较结果:
df <- structure(list(y = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 1), x = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("FP", "WP" ), class = "factor")), class = "data.frame", row.names = c(NA,-11L))
summary(aov(y ~ x, data = df))
Df Sum Sq Mean Sq F value Pr(>F)
x 1 0.3068 0.3068 1.473 0.256
Residuals 9 1.8750 0.2083
t.test(y ~ x, data = df)
Welch Two Sample t-test
data: y by x
t = -2.0494, df = 7, p-value = 0.0796
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.80768193 0.05768193
sample estimates:
mean in group FP mean in group WP
1.000 1.375
可以看出,方差分析的 p 值为 0.256,而 t 检验的 p 值为 0.0796。
为了了解这种偏差的原因,我使用t-test 和ANOVA 的公式自己计算了测试统计数据。当组的大小不同时,t 检验函数似乎给出了错误的结果。
是否有设置可以使 t-test 正确适用于不同的组大小?
【问题讨论】: