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

huangapple go评论60阅读模式
英文:

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

问题

You can set the significant level based on "p.adj" instead of "p.format" by specifying the "p.adjust.method" argument within the compare_means function. Here's the code with the modification:

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

To use the report function from the "report" package for this output, you can do the following:

library(report)
report(df_compare)

This will generate a report for your comparison output using the "report" package.

英文:

required package : install.packages("ggpubr")

library(ggpubr)
data(&quot;ToothGrowth&quot;)
df_compare &lt;- compare_means(len~supp, data=ToothGrowth, method = &quot;wilcox.test&quot;, paired = TRUE,
                                 group.by = &quot;dose&quot;)

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.

答案1

得分: 0

以下是已翻译的内容:

首先,我查看了帮助页面,看是否可以找到一个简单的参数来设置。很不幸,没有这样的运气。然后,我查看了代码,看是否有一个未记录的通向幸福的路径。同样,没有成功。所以我找到了构建p.signif值的代码部分,然后逆向查找了参数是如何获取的,最后对这些值应用了base::p.adjust。(只更改了一行代码。然后,我将环境设置为与compare_means相同。成功。

英文:

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

  symnum.args$x &lt;- p.adjust(res$p)

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


 environment(compare_means_adj) &lt;- environment(compare_means)
 (df_compare &lt;- compare_means_adj(len~supp, data=ToothGrowth, method = &quot;wilcox.test&quot;, paired = TRUE,
                                  group.by = &quot;dose&quot;))
#------------------------------------
# A tibble: 3 &#215; 9
   dose .y.   group1 group2      p p.adj p.format p.signif method  
  &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt;  &lt;chr&gt;   &lt;dbl&gt; &lt;dbl&gt; &lt;chr&gt;    &lt;chr&gt;    &lt;chr&gt;   
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

huangapple
  • 本文由 发表于 2023年5月22日 17:36:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304810.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定