Is there any way to set significant level based on 'p.adj' instead of 'p.format' when using compare_means function in R

required package : install.packages("ggpubr")

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

My question is how I can set the significant level based on 'p.adj' instead of 'p.format' because I want to add 'p.signif' on my plot but based on 'p.adj' ,and second question is how can I use report function from report package for this output? If someone has a suggestion or explanation, I would appreciate.


  • First I looked at the help page to see if I could find a simple parameter to set. No such luck. Then I looked at the code to see if there were an undocumented route to happiness. Again, no joy. So I found the section of code where the p.signif value was constructed and then worked backward to see whee the arguments were obtaine and finally applied base::p.adjust to those values. (It was an alteration of one line. Then I set the environment to the same as compare_means. Success.

    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