gpt4 book ai didi

R:t.test 和pairwise.t.test 给出不同的结果?

转载 作者:行者123 更新时间:2023-12-03 19:59:29 24 4
gpt4 key购买 nike

我尝试对以下数据帧使用 R 进行 t 检验。

df <- structure(list(freq = c(9, 11, 14, 12, 10, 9, 16, 10, 11, 15, 
13, 12, 12, 13, 13, 9, 16, 14, 12, 15, 16, 10, 11, 13, 14, 14,
14, 16, 8, 10, 14, 14, 11, 11, 11, 11, 13, 7, 12, 13, 14, 11,
11, 13, 10, 14, 10, 10, 12, 8, 9, 12, 14, 11, 12, 12, 14, 14,
14, 15, 12, 13, 14, 8, 9, 11, 10, 14, 12, 12, 9, 10, 8, 14, 11,
14, 9, 13, 13, 13, 10, 9, 13, 10, 13, 10, 13, 12, 11, 12, 10,
12, 8, 11, 12, 15, 12, 12, 11, 13, 12, 10, 13, 9, 11, 9, 11,
8, 12, 12, 12, 10, 11, 12, 9, 13, 14, 11, 11, 14, 13, 12, 14,
15, 12, 12, 12, 14), class = structure(c(3L, 3L, 2L, 2L, 2L,
2L, 2L, 3L, 2L, 3L, 4L, 4L, 4L, 4L, 3L, 2L, 3L, 2L, 1L, 4L, 1L,
4L, 1L, 4L, 2L, 2L, 3L, 3L, 2L, 4L, 1L, 4L, 4L, 4L, 3L, 3L, 3L,
2L, 1L, 4L, 3L, 3L, 1L, 4L, 1L, 2L, 2L, 3L, 3L, 4L, 2L, 2L, 3L,
3L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 4L, 1L, 1L, 1L, 2L, 2L, 3L,
2L, 3L, 2L, 3L, 3L, 4L, 2L, 1L, 4L, 1L, 1L, 3L, 2L, 2L, 2L, 3L,
1L, 1L, 1L, 1L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 3L, 3L, 4L,
4L, 3L, 4L, 4L, 4L, 4L, 3L, 3L, 1L, 4L, 4L, 1L, 4L, 4L, 1L, 3L,
1L, 2L, 2L, 1L, 2L, 1L, 1L, 3L, 3L, 2L, 1L), .Label = c("ending",
"mobile", "stem.first", "stem.second"), class = "factor")), .Names = c("freq",
"class"), row.names = c(NA, -128L), class = "data.frame")

正如我在 previous post 中读到的在 R 中有不止一种方法可以做到这一点。
我尝试使用 t.test -function 并使用 pairwise.t.test -功能。

用于使用 t.test我通过要比较的类对数据帧进行子集化,并对子集进行后续 t 检验。
ending.vs.mobile <- df[df$class=="ending"|df$class=="mobile",]
ending.vs.first <- df[df$class=="ending"|df$class=="stem.first",]
ending.vs.second <- df[df$class=="ending"|df$class=="stem.second",]
mobile.vs.first <- df[df$class=="mobile"|df$class=="stem.first",]
mobile.vs.second <- df[df$class=="mobile"|df$class=="stem.second",]
first.vs.second <- df[df$class=="stem.first"|df$class=="stem.second",]

t.test(ending.vs.mobile$freq ~ ending.vs.mobile$class, var.equal=T)
t.test(ending.vs.first$freq ~ ending.vs.first$class, var.equal=T)
t.test(ending.vs.second$freq ~ ending.vs.second$class, var.equal=T)
t.test(mobile.vs.first$freq ~ mobile.vs.first$class, var.equal=T)
t.test(mobile.vs.second$freq ~ mobile.vs.second$class, var.equal=T)
t.test(first.vs.second$freq ~ first.vs.second$class, var.equal=T)

据我所知(这里我可能错了) pairwise.t.test在这里会更方便,因为我不需要创建所有子集并且可以在原始数据帧上运行它。
pairwise.t.test(df$freq, df$class, p.adjust.method="none", paired=FALSE, pooled.sd=FALSE)

然而,我在这里得到了不同的结果,最明显的是比较结束与茎.秒:p=0.7 使用 t.test并且 p=0.1 使用 pairwise.t.test .

这里有什么问题?我在哪里做过某事。错误的?

虽然问题本身已经解决了,但我觉得它发生的原因,让我有点偏执(不再相信自己了):
只需输入 pooled.sd而不是 pool.sd我没有得到我期望的结果。
这不是很容易出错吗?

在许多其他情况下,您可以键入变体,例如 bonfbonferroni , fa()factor() , 等等。但是这里 pooled.sd尽管实际上是“pooled sd”,但被完全忽略。
好的,如果您仔细阅读输出的标题,您可以猜到 pooled.sd没有被识别,因为它仍然说“t tests with pooled SD”但是如果我什至不打印这个怎么办,例如将输出通过管道传输到自写函数时?有可能永远无法识别此错误。

我应该写信给 R 的一些开发人员,在 R 的 future 版本中,这两种拼写变体都应该有效吗?

最佳答案

问题不在于 p 值校正,而在于(声明)方差假设。您已使用 var.equal=T在您的 t.test电话和 pooled.sd=FALSE在您的 pairwise.t.test调用。但是,pairwise.t.test 的参数是 pool.sd ,不是 pooled.sd .改变这一点,p 值相当于对 t.test 的单独调用。

pairwise.t.test(df$freq, df$class, p.adjust.method="none", 
paired=FALSE, pool.sd=FALSE)

关于R:t.test 和pairwise.t.test 给出不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11454521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com