R语言 沃利斯Dunn事后检验的紧凑字母显示

sdnqo3pr  于 2023-01-10  发布在  其他
关注(0)|答案(1)|浏览(211)

我有一个正在执行Kruskal-Wallis测试的 Dataframe 。我想将结果的紧凑字母显示添加到:
1.平均值、sd、Z统计、P值+字母表

  1. A显示紧凑字母的结果图
    关于如何在TukeyHSD后进行此操作,有丰富的知识,但我无法使用其他模型(即Kruskal-Wallis Dunn检验、welch ANOVA配对t检验等)在Hocs后找出答案。我曾想过手动进行此操作,但它不起作用。
    这是我目前掌握的情况:
data <- iris
kruskal <- kruskal.test(Petal.Width ~ Species, data = data)
kruskal_ph <- dunnTest(Petal.Width ~ Species,
                  data=data,
                  method="bonferroni")

#Make CLD here ....


#OR

#First make comparisons table and mannually insert letters. E.g.

pvalue <- kruskal_ph[[2]][, "P.adj"]
    hi <- kruskal_ph[[2]][,"Comparison"] %>%
              as.data.frame()
      hi <- hi %>%
          rename(hi, comps = .) %>%
          separate(comps, c("group1","group2"))
      comparisons <- cbind(hi, pvalue)
    comparisons$Sig <- comparisons$Sig
    comparisons$Sig[comparisons$pvalue > 0.05] <- "ns"
    comparisons$Sig[comparisons$pvalue <= 0.05] <- "*"
    comparisons$Sig[comparisons$pvalue <= 0.01] <- "**"
comparisons

# Make CLD from comparisons here

# Add to a summary table (how?) and graph?

library(ggplot2)
ggplot(data, aes(x = Species, y = Petal.Width, colour = Species, fill = Species)) +
  geom_bar(stat = "summary", fun = "mean")
fcy6dtqo

fcy6dtqo1#

agricolae包在这种情况下可能很有用。
试试这个:

library(agricolae)
kruskal_cld <- kruskal(iris$Petal.Width, iris$Species, group=TRUE, p.adj="bonferroni")$groups
cld <- as.data.frame(kruskal_cld)
group_df <- iris %>% 
  group_by(Species) %>% 
  summarise(mean = mean(Petal.Width), sd = sd(Petal.Width)) 

library(ggplot2)
ggplot(iris, aes(x = Species, y = Petal.Width, colour = Species, fill = Species)) +
  geom_bar(stat = "summary", fun = "mean") +
  geom_text(data = group_df, aes(label = cld$group, y = mean + sd, x = Species), vjust = -0.5, inherit.aes = FALSE)

其他人将不得不帮助为表,我自己还在学习R:)

相关问题