在R中使用compare_means函数时,有没有办法根据'p.adj'而不是'p.format'来设置显著性水平

pbpqsu0x  于 2023-05-26  发布在  其他
关注(0)|答案(1)|浏览(123)

所需 Package :install.packages(“ggpubr”)

library(ggpubr)
data("ToothGrowth")
df_compare <- compare_means(len~supp, data=ToothGrowth, method = "wilcox.test", paired = TRUE,
                                 group.by = "dose")

我的问题是如何根据'p.adj'而不是'p.format'设置显著性水平,因为我想在我的图上添加'p.signif',但基于'p.adj',第二个问题是如何使用报告包中的报告功能来输出?如果有人有任何建议或解释,我将不胜感激。

kq4fsx7k

kq4fsx7k1#

首先,我查看了帮助页面,看看是否可以找到一个简单的参数来设置。没那么幸运。然后我查看了代码,看看是否有一条没有记录的通往幸福的道路。同样,没有喜悦。因此,我找到了构造p.signif值的代码段,然后反向工作,看看参数是从哪里获得的,最后应用base::p.adjust来调整这些值。(这是一个改变。然后我将环境设置为与compare_means相同。成功

compare_means # code appears on console

compare_means_adj <-  # edit a copy of the code scraped from console
+ function (formula, data, method = "wilcox.test", paired = FALSE, 
+     group.by = NULL, ref.group = NULL, symnum.args = list(), 
+     p.adjust.method = "holm", ...) 
+ {
+     . <- NULL
+     method.info <- .method_info(method)
+     method <- method.info$method
# --- leaving out a couple of pages of code
# --- one finds the relevant code at the very end

  symnum.args$x <- p.adjust(res$p)

#  --- that was the only line of code that was changed

 environment(compare_means_adj) <- environment(compare_means)
 (df_compare <- compare_means_adj(len~supp, data=ToothGrowth, method = "wilcox.test", paired = TRUE,
                                  group.by = "dose"))
#------------------------------------
# A tibble: 3 × 9
   dose .y.   group1 group2      p p.adj p.format p.signif method  
  <dbl> <chr> <chr>  <chr>   <dbl> <dbl> <chr>    <chr>    <chr>   
1   0.5 len   OJ     VC     0.0330 0.066 0.033    ns       Wilcoxon
2   1   len   OJ     VC     0.0137 0.041 0.014    *        Wilcoxon
3   2   len   OJ     VC     1      1     1.000    ns       Wilcoxon

相关问题