【问题标题】:How can I do a multiple comparisons test and output the specific groups which have a p-value of less than .05?如何进行多重比较测试并输出 p 值小于 0.05 的特定组?
【发布时间】:2017-08-16 18:50:51
【问题描述】:

我有多个数据框,每个数据框都有不同样本的年龄列。以下数据框只有感兴趣的列(年龄)

df1 <- c(34, 25, 45, 6, 67, 12)
df2 <- c(31, 23, 71, 19)
df3 <- c(12, 45, 42, 89, 12)
df4 <- c(34, 37, 23)

如果我跑

results <- dunn.test(list(df1, df2, df3, df4))

它为 6 个可能的比较中的每一个输出 p 值。仅当这些 p 值之一小于 0.05 时,我如何让它输出它来自哪些特定数据帧(例如,df1 和 df2 比较的 p 值为 0.01,所以我希望它打印df1, df2)。它在结果数据框中输出“比较”,但如果我能得到它来自的特定数据框会更好。

我正在处理的数据包含许多类似于 list(df1, df2, df3, df4) 的列表,所以我正在寻找一个通用的解决方案。

如果您有什么想澄清的,请询问!

【问题讨论】:

  • dunn.test 是从哪里来的?这似乎不是基本的 R 函数。
  • 如果你在做多重比较,你不应该使用Bonferroni correction吗?
  • @MrFlick 似乎来自包dunn.test。但是在 OP 的数据上运行它不会给出任何低于 0.05 的 p 值,results$P 输出 [1] 0.4373240 0.3244279 0.3977284 0.4123293 0.4713834 0.4352448

标签: r


【解决方案1】:

有几种方法可以做到这一点。

为你的数据框命名

df <- list("a" = df1, "b" = df2, "c" = df3, "d" = df4)

然后使用?sapply()

result <- sapply(df, function(x){
    dunn.test(x)
})

result的属性

str(result)
List of 20
 $ : num 5
 $ : num [1:15] 0.378 -0.378 -0.756 1.134 0.756 ...
 $ : num [1:15] 0.353 0.353 0.225 0.128 0.225 ...
 $ : num [1:15] 0.353 0.353 0.225 0.128 0.225 ...
 $ : chr [1:15] "1 - 2" "1 - 3" "2 - 3" "1 - 4" ...
 $ : num 3
 $ : num [1:6] 0.548 -0.548 -1.095 1.095 0.548 ...
 $ : num [1:6] 0.292 0.292 0.137 0.137 0.292 ...
 $ : num [1:6] 0.292 0.292 0.137 0.137 0.292 ...
 $ : chr [1:6] "1 - 2" "1 - 3" "2 - 3" "1 - 4" ...
 $ : num 4
 $ : num [1:10] -1.147 -0.688 0.459 -1.606 -0.459 ...
 $ : num [1:10] 0.1257 0.2456 0.3232 0.0541 0.3232 ...
 $ : num [1:10] 0.1257 0.2456 0.3232 0.0541 0.3232 ...
 $ : chr [1:10] "1 - 2" "1 - 3" "2 - 3" "1 - 4" ...
 $ : num 2
 $ : num [1:3] -0.707 0.707 1.414
 $ : num [1:3] 0.2398 0.2398 0.0786
 $ : num [1:3] 0.2398 0.2398 0.0786
 $ : chr [1:3] "1 - 2" "1 - 3" "2 - 3"
 - attr(*, "dim")= int [1:2] 5 4
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:5] "chi2" "Z" "P" "P.adjusted" ...
  ..$ : chr [1:4] "a" "b" "c" "d"

那就去吧

attr(result,"dimnames")[1] 用于值标签或

attr(result,"dimnames")[2] 用于变量名

【讨论】:

    猜你喜欢
    • 2015-10-14
    • 1970-01-01
    • 2010-12-21
    • 2019-02-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2022-07-08
    相关资源
    最近更新 更多