我试图在我创建的框图中添加紧凑的字母显示,有没有机会将cldList()函数与ggboxplot()结合起来?
这是我的样本数据
library(FSA)
library(multcompView)
library(rcompanion)
library(ggplot2)
library(ggpubr)
library(tidyr)
df_list <- list(
`1.3.A` =
tibble::tribble(
~Person, ~Height, ~Weight,
"Alex", 175, 75,
"Gerard", 110, 85,
"Clyde", 120, 79
),
`2.2.A` =
tibble::tribble(
~Person, ~Height, ~Weight,
"Missy", 162, 55,
"Britany", 111, 56,
"Sussie", 192, 85
),
`1.1.B` =
tibble::tribble(
~Person, ~Height, ~Weight,
"Luke", 177, 66,
"Alex", 169, 69,
"Haley", 145, 54
)
)
lapply(df_list, function(i) ggboxplot(i, x = "Person", y = c("Height", "Weight"), combine = TRUE))
lapply(df_list, function(k) dunnTest(Weight ~ as.factor(Person), method = "bh", data = k))
lapply(df_list, function(i) cldList(P.adj ~ Comparison, threshold = 0.05))我试图为每个Person添加重要的字母,在我的原始数据中,我有30个组要比较,并在框图中添加紧凑的字母显示将使数据解释更加容易。
我在一个列表中也有多个数据文件,我想知道cldList()是否可以包装在lapply()函数中。
我希望有人能帮忙。
发布于 2021-10-08 11:09:19
我是您已经在评论中提到过的示例的作者。其中一位评论员已经正确地指出了.group列的来源。但是,当指出代码与示例中的代码之间的一般区别时,我发现
FSA::Dunntest来拟合模型,并立即比较每个因素级别的平均值。
2b。我用lm()来建立一个模型,然后用emmeans::emmeans()来比较每个因素水平的平均值。rcompanion::cldList()得到这些字母。
3b。我用multcomp::cld()得到这些字母。我认为第2点和第3点都很好--只是不同的函数导致了相同的目标。我试着用你的方法处理我的数据,结果成功了:
dunnTest_out <- FSA::dunnTest(weight ~ as.factor(group), method = "bh", data = PlantGrowth)
rcompanion::cldList(P.adj ~ Comparison, data = dunnTest_out$res, threshold = 0.05)
#> Group Letter MonoLetter
#> 1 ctrl ab ab
#> 2 trt1 a a
#> 3 trt2 b b然而,在我看来,你的数据似乎是错的。如果您的“意思”不是真正的意思,而是单个值,您就不应该能够将“意思”相互比较,甚至不能执行测试(如果您的“意思”实际上不是“意思”而是单个值,那么测试的结果可以通过紧凑的字母显示来显示)。
我将您的示例简化为其中一个数据集:
dat_1.1.B <-
tibble::tribble(
~Person, ~Height, ~Weight,
"Luke", 177, 66,
"Alex", 169, 69,
"Haley", 145, 54
)
dunnTest_out <- FSA::dunnTest(Weight ~ as.factor(Person), method = "bh", data = dat_1.1.B)
dunnTest_out
#> Dunn (1964) Kruskal-Wallis multiple comparison
#> p-values adjusted with the Benjamini-Hochberg method.
#> Comparison Z P.unadj P.adj
#> 1 Alex - Haley 1.4142136 0.1572992 0.4718976
#> 2 Alex - Luke 0.7071068 0.4795001 0.4795001
#> 3 Haley - Luke -0.7071068 0.4795001 0.7192502
rcompanion::cldList(P.adj ~ Comparison, data = dunnTest_out$res, threshold = 0.05)
#> Error: No significant differences.请注意,当我将其中一个Weight值更改为大得多的数值但p-值一点也不改变时,很明显有些东西不能正常工作。
dat_1.1.B <-
tibble::tribble(
~Person, ~Height, ~Weight,
"Luke", 177, 66,
"Alex", 169, 100000069,
"Haley", 145, 54
)
dunnTest_out <- FSA::dunnTest(Weight ~ as.factor(Person), method = "bh", data = dat_1.1.B)
dunnTest_out
#> Dunn (1964) Kruskal-Wallis multiple comparison
#> p-values adjusted with the Benjamini-Hochberg method.
#> Comparison Z P.unadj P.adj
#> 1 Alex - Haley 1.4142136 0.1572992 0.4718976
#> 2 Alex - Luke 0.7071068 0.4795001 0.4795001
#> 3 Haley - Luke -0.7071068 0.4795001 0.7192502
rcompanion::cldList(P.adj ~ Comparison, data = dunnTest_out$res, threshold = 0.05)
#> Error: No significant differences.所以是的,我想是因为数据。请注意,“没有显著差异”的错误对我来说也很奇怪,因为假设测试是正确的,那么没有显著的差异就意味着所有的值都得到相同的字母。
博士:数据就是问题所在。您不能通过测试来比较每个组的“均值”是否仅为单个值。如果您拥有用于获取每个组的单个值的原始数据,则应该将其输入到模型中--就像我的示例以及?FSA::Dunntest和::cldList()示例中所做的那样。
https://stackoverflow.com/questions/69423508
复制相似问题