英文:
Pvalue adjustment (Rcode to adjust all tests together)
问题
我想知道如何调整所有比较的P值。我想一起对这两列p-value1和p-value2运行FDR(这样我会有6个测试),并将结果放入新列(Adjustment_Pvalues)。
类似于:
p.adjust(c(p-value1,p-value2), method = "fdr")
特征 p-value1 p-value2 调整后的P值
1 0.5 0.01
2 NA NA
3 0.2 0.45
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:
p.adjust (c(p-value1,p-value2), method = "fdr")
Trait p-value1 p-value2 Adjustment_Pvalues
1 0.5 0.01
2 NA NA
3 0.2 0.45
4 0.2 0.02
答案1
得分: 1
如果我理解正确(即您希望它们都一起调整),您将需要使用 pivot_longer
和 pivot_wider
:
require(tidyverse)
df.test.long <- tibble(
Trait = 1:4,
p_value1 = c(0.5, NA, 0.2, 0.2),
p_value2 = c(0.01, NA, 0.45, 0.02)
) %>%
pivot_longer(cols = -Trait, names_to = "pvalue_column", values_to = "pvalue")
df.test.long$adjusted <- p.adjust(df.test.long$pvalue, method = "fdr")
df.test.final <- df.test.long %>%
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
<details>
<summary>英文:</summary>
If I understand correctly (i.e. you want all of them adjusted together), you'll want to use `pivot_longer` and `pivot_wider`:
require(tidyverse)
df.test.long <- tibble(
Trait = 1:4,
p_value1 = c(0.5, NA, 0.2, 0.2),
p_value2 = c(0.01, NA, 0.45, 0.02)
) %>%
pivot_longer(cols = -Trait, names_to = "pvalue_column", values_to = "pvalue")
df.test.long$adjusted <- p.adjust(df.test.long$pvalue, method = "fdr")
df.test.final <- df.test.long %>% pivot_wider(names_from = "pvalue_column", values_from = c(pvalue, adjusted))
# output
# A tibble: 4 × 5
Trait pvalue_p_value1 pvalue_p_value2 adjusted_p_value1 adjusted_p_value2
<int> <dbl> <dbl> <dbl> <dbl>
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
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论