P值调整(用于一起调整所有测试的R代码)

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

Pvalue adjustment (Rcode to adjust all tests together)

问题

我想知道如何调整所有比较的P值。我想一起对这两列p-value1和p-value2运行FDR(这样我会有6个测试),并将结果放入新列(Adjustment_Pvalues)。

类似于:

  1. p.adjust(c(p-value1,p-value2), method = "fdr")
  2. 特征 p-value1 p-value2 调整后的P
  3. 1 0.5 0.01
  4. 2 NA NA
  5. 3 0.2 0.45
  6. 4 0.2 0.02
英文:

I was wondering how I can adjust the P-value for all comparisons together. I want to run FDR for these two columns p-value1 and p-value2 together (So I will have 6 tests) and bring the results into a new column (Adjustment_Pvalues).

Something like:

  1. p.adjust (c(p-value1,p-value2), method = "fdr")
  2. Trait p-value1 p-value2 Adjustment_Pvalues
  3. 1 0.5 0.01
  4. 2 NA NA
  5. 3 0.2 0.45
  6. 4 0.2 0.02

答案1

得分: 1

如果我理解正确(即您希望它们都一起调整),您将需要使用 pivot_longerpivot_wider

  1. require(tidyverse)
  2. df.test.long <- tibble(
  3. Trait = 1:4,
  4. p_value1 = c(0.5, NA, 0.2, 0.2),
  5. p_value2 = c(0.01, NA, 0.45, 0.02)
  6. ) %>%
  7. pivot_longer(cols = -Trait, names_to = "pvalue_column", values_to = "pvalue")
  8. df.test.long$adjusted <- p.adjust(df.test.long$pvalue, method = "fdr")
  9. df.test.final <- df.test.long %>%
  10. pivot_wider(names_from = "pvalue_column", values_from = c(pvalue, adjusted))

输出

A tibble: 4 × 5

Trait pvalue_p_value1 pvalue_p_value2 adjusted_p_value1 adjusted_p_value2

1 1 0.5 0.01 0.5 0.06
2 2 NA NA NA NA
3 3 0.2 0.45 0.3 0.5
4 4 0.2 0.02 0.3 0.06

  1. <details>
  2. <summary>英文:</summary>
  3. If I understand correctly (i.e. you want all of them adjusted together), you&#39;ll want to use `pivot_longer` and `pivot_wider`:
  4. require(tidyverse)
  5. df.test.long &lt;- tibble(
  6. Trait = 1:4,
  7. p_value1 = c(0.5, NA, 0.2, 0.2),
  8. p_value2 = c(0.01, NA, 0.45, 0.02)
  9. ) %&gt;%
  10. pivot_longer(cols = -Trait, names_to = &quot;pvalue_column&quot;, values_to = &quot;pvalue&quot;)
  11. df.test.long$adjusted &lt;- p.adjust(df.test.long$pvalue, method = &quot;fdr&quot;)
  12. df.test.final &lt;- df.test.long %&gt;% pivot_wider(names_from = &quot;pvalue_column&quot;, values_from = c(pvalue, adjusted))
  13. # output
  14. # A tibble: 4 &#215; 5
  15. Trait pvalue_p_value1 pvalue_p_value2 adjusted_p_value1 adjusted_p_value2
  16. &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  17. 1 1 0.5 0.01 0.5 0.06
  18. 2 2 NA NA NA NA
  19. 3 3 0.2 0.45 0.3 0.5
  20. 4 4 0.2 0.02 0.3 0.06
  21. </details>

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

发表评论

匿名网友

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

确定