R语言 如何在ggplot上将stats方法从默认ttest更改为Mann Whitney

6yoyoihd  于 2023-05-11  发布在  其他
关注(0)|答案(1)|浏览(151)

I created this boxplot but need different stats method p values
使用此代码,即函数stat_compare_means,但我想使用mannwhitney/非参数p值,因为数据不是正态分布的。
还有,我怎么能看到有哪些统计方法的选项可以使用?(帮助说明在Stat_compare_means中使用“method”-我希望能够看到将来可以用于不同测试的不同方法的列表

my_comparisons <- list (c("AA/AG","GG"))
  
  df <- GDFSNP1_for_R
  df  %>% 
    drop_na(Genotype) %>%
    pivot_longer(starts_with("GDF")) %>%
    mutate(name = factor(name, c("GDFb", "GDFt6", "GDFt12"))) %>%
    ggplot(. , aes(y = value, x = Genotype, group = Genotype, fill=Genotype)) + 
    facet_grid(~name, labeller = as_labeller(GDF_label)) + 
    geom_violin(width=0.9) +
    geom_boxplot(width=0.1, alpha=0.2) + 
    stat_compare_means(comparisons = my_comparisons)
4nkexdtk

4nkexdtk1#

不知道它在哪里被记录下来,但是如果你源代码ggpubr:::.method_info,你可以看看可用的方法。

{
    if (is.null(method)) 
        method = "wilcox.test"
    allowed.methods <- list(t = "t.test", t.test = "t.test", 
        student = "t.test", wiloxon = "wilcox.test", wilcox = "wilcox.test", 
        wilcox.test = "wilcox.test", anova = "anova", aov = "anova", 
        kruskal = "kruskal.test", kruskal.test = "kruskal.test")
    method.names <- list(t.test = "T-test", wilcox.test = "Wilcoxon", 
        anova = "Anova", kruskal.test = "Kruskal-Wallis")
    if (!(method %in% names(allowed.methods))) 
        stop("Non-supported method specified. Allowed methods are one of: ", 
            .collapse(allowed.methods, sep = ", "))
    method <- allowed.methods[[method]]
    method.name <- method.names[[method]]
    list(method = method, name = method.name)
}

看起来非参数方法的选项是"wilcox.test""kruskal.test"。我相信威尔科克斯和曼-惠特尼是一回事。

相关问题