Thin wrapper over stats::p.adjust(method = "bonferroni").
Examples
set.seed(1)
# 60 tests: 50 null (uniform p) + 10 strong signals near zero.
p <- c(runif(50), runif(10, 0, 0.005))
res <- bonferroni(p, alpha = 0.05)
res # rich print: method, alpha, tests, rejected
#> Adjusted p-values (bonferroni)
#> ==============================
#> Call: method=bonferroni, alpha=0.0500, n=60
#>
#> Method bonferroni
#> alpha 0.05
#> Tests (n) 60
#> Rejected 2
#> Min adjusted p 0.021204
#> Max adjusted p 1
#>
#> 2 of 60 hypotheses are rejected at alpha=0.0500.
# The result carries the full adjusted-p and rejection vectors.
head(res$adjusted) # each raw p multiplied by n (capped at 1)
#> [1] 1 1 1 1 1 1
res$n_rejected # how many survive alpha after correction
#> [1] 2
which(res$rejected) # indices declared significant
#> [1] 55 56
# `alpha` sets the rejection threshold; stricter alpha rejects fewer.
bonferroni(p, alpha = 0.01)$n_rejected
#> [1] 0
# `labels` names each test so the output is self-documenting.
bonferroni(c(0.001, 0.02, 0.3),
labels = c("geneA", "geneB", "geneC"))$labels
#> [1] "geneA" "geneB" "geneC"
# Bonferroni is the most conservative FWER method -- compare to Holm/BH.
c(bonferroni = bonferroni(p)$n_rejected,
holm = holm(p)$n_rejected,
BH = benjamini_hochberg(p)$n_rejected)
#> bonferroni holm BH
#> 2 2 10
