- Used to control the False Discovery Rate (FDR)
- Used in multiple hypothesis testing
- Commonly used in genomics, medical research, and finance
2025-02-12
library(ggplot2)
set.seed(123)
pvals <- rbeta(500, shape1 = 1, shape2 = 10)
df <- data.frame(pvals)
ggplot(df, aes(x = pvals)) +
geom_histogram(fill = "darkgreen", color = "black",
bins = 20, alpha= 0.7, boundary = 0) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
theme_minimal(base_size = 14) +
labs(title = "Histogram of p-values",
x = "p-value",
y = "Frequency")
m <- 500 # number of tests
pvals <- sort(rbeta(m, shape1 = 1, shape2 = 10)) # Sorted p-values
df <- data.frame(rank = 1:m, pvals = pvals)
#calculate bh threshold
q <- 0.05 # desired FDR
df$bh_threshold <- df$rank / m * q
ggplot(df, aes(x = rank, y = pvals)) +
geom_point(color = "maroon") + # p values
geom_line(aes(y = bh_threshold), color = "darkgreen") + #bh threshold
geom_hline(yintercept = 0.05, linetype="dashed", color="black") +
theme_minimal() +
labs(title = "Benjamini-Hochberg Threshold",
x = "Rank of p-value",
y = "p-value")