rstatisticsp-valueadjustmentbonferroni

Apply Bonferroni to each p-value of my table


I have a a little problem with an adjustment of Bonferroni on my datas. Here is an exemple of my datas :

structure(list(p_values = c(0.00551261839474566, 0.00909340979590469, 
+                                  0.42610555368556, 0.711610700326496, 0.00439218856215691, 0.859681237958105)), class = "data.frame", row.names = c("a","b","c","d","e","f"))

I obtained these p-values with a wilcoxon test and I would like to adjust them with a Bonferroni and Benjamin Hochberg adjustment.

I tried this : but the values never change :(

rf0->d. #base dataset from which I extracted the values, 1020 subjects and 156 features to test with one.
out <- lapply(3:158, function(x) pairwise.wilcox.test(d[[x]], d$LesionResponse,p.adjust.method="bonferroni")). #Applying the wilcoxon test to the 3->158 features with the "LesionResponse"
names(out) <- names(d)[3:158]
pvalue<-sapply(out, function(x) {
    p <- x$p.value
    n <- outer(rownames(p), colnames(p), paste, sep='v')
    p <- as.vector(p)
    names(p) <- n
    p
})
pvalue<-as.data.frame(pvalue)```

I must so adjust because It realized 1020 tests for each comparison...Unfortunately it changes nothing in comparison of the unadjusted values...

Solution

  • library(dplyr)
    df |> 
      mutate(bonferroni = p.adjust(p_values, method="bonferroni"),
             hochberg = p.adjust(p_values, method="hochberg"))
    

    Output:

         p_values bonferroni   hochberg
    a 0.005512618 0.03307571 0.02756309
    b 0.009093410 0.05456046 0.03637364
    c 0.426105554 1.00000000 0.85968124
    d 0.711610700 1.00000000 0.85968124
    e 0.004392189 0.02635313 0.02635313
    f 0.859681238 1.00000000 0.85968124