This is a test version of Biostars. For the public version, visit https://www.biostars.org.
p-value and Boneferroni adjusted p-value the same in R

I'm analysing nearly 20k genes using r (code below) with Fisher's exact test but the adjusted p-value using Bonferroni correction is the same as the one that came out of the exact test, please can someone tell me where it has gone wrong?

I have saved p-values, odds ratio and adjusted p-values so that they can be presented as separate columns as well.

for (i in 1:nrow(RVAS_counts)) {
ctbl <- matrix(c(RVAS_counts[i, "cases"], RVAS_counts[i, "ctrls"], 
               ncases - RVAS_counts[i, "cases"], 
               nctrls - RVAS_counts[i, "ctrls"]),
               nrow = 2, byrow = FALSE)

ctable <- matrix(unlist(ctbl), 2)

fisher_result <- fisher.test(ctable, alternative="greater")

p_values[i] <- fisher_result$p.value
odds_ratios[i] <- fisher_result$estimate
adjusted_p_values[i] <- p.adjust(p_values[i], method = "bonferroni", n = leng(p_values[i]))
}

Any help is much appreciated.

bonferroni r statistics p-value fisher

1 answer

You need to adjust pvalues outside of the loop, for all genes at once. Otherwise it will adjust as if there were only 1 test (meaning no adjustment at all). Also there is usually no need to specify the n argument when using p.adjust(). So do something like this instead:

for (i in 1:nrow(RVAS_counts)) {
    ...
}

adjusted_p_values <- p.adjust(p_values, method = "bonferroni"))

Log in to answer this question.