In statistical analysis, knowing what the software or library you are using does in the background is the fundamental requirement for correctly interpreting the results. The Benjamini-Hochberg (BH) procedure, though it may seem complex at first glance, is actually an algorithm whose logic is quite simple, powerful, and elegant. In this article, we will examine the mathematical steps of the BH algorithm step-by-step through a numerical example, illustrating how you could perform it manually on a spreadsheet or piece of paper.
Required Parameters for Calculation
To start the algorithm, you need two basic components:
- Raw P-Values: The $m$ number of p-values obtained from your multiple tests (t-test, ANOVA, etc.) to which no correction has yet been applied.
- FDR Target (q): The threshold value determining the rate at which you are willing to tolerate false discoveries (false positives). It is usually chosen as 0.05 or 0.10 (5% or 10%).
Step 1: Sorting the P-Values
Sort all your $m$ raw p-values from the smallest (most significant) to the largest (least significant). Assign a rank index ($i$) from $1$ to $m$ for each value. Let's call the array of p-values sorted by this arrangement $p_{(i)}$.
Step 2: Calculating BH Threshold Values
Calculate the Benjamini-Hochberg critical threshold for each rank $i$ in the series. The formula is remarkably simple:
$\text{Threshold}_{(i)} = \frac{i}{m} \times q$
This formula demands that the most powerful (smallest) p-value pass the most rigorous threshold (e.g., $\frac{1}{m} \times q$), while linearly relaxing the threshold toward the end of the list.
Step 3: The Step-Up Decision Rule
The most critical point of the BH method is the "step-up" (bottom-up / end-to-beginning) rule. You start from the bottom of the sorted list ($i=m$) and move upwards ($i=1$).
Our condition is this: Find the first row where $p_{(i)} \le \text{Threshold}_{(i)}$. The rank corresponding to the value satisfying this condition is called the $k$ index.
If such a $k$ is found, that row and all tests above it (i.e., those with a smaller p-value than it) are rejected (deemed significant), even if they didn't pass their own thresholds individually.
Step 4: Finding Adjusted P-Values
Software packages (for example, the p.adjust function in R) generally output an "Adjusted P-Value" rather than making threshold comparisons. The user compares this value directly against the $q$ target.
The adjusted p-value calculation is also done from back to front (cumulative minimum):
$p_{\text{adj}(i)} = \min \left( 1, \min_{j \ge i} \left( \frac{m \times p_{(j)}}{j} \right) \right)$
In other words, the adjusted p-value of a test is "the smallest number between its own provisional value calculated by the formula and all adjusted values that follow it."
Numerical Example Solution
We have $m = 5$ tests, and our target is $q = 0.05$.
Our raw p-values are (in random order): $0.200, 0.031, 0.001, 0.025, 0.015$.
Creating the Table (Steps 1 and 2):
First, let's sort from smallest to largest (from $i=1$ to $5$) and calculate the BH thresholds ($(i/5) \times 0.05$).
- $i=1$, $p_{(1)} = 0.001$, Threshold = $(1/5) \times 0.05 = 0.010$
- $i=2$, $p_{(2)} = 0.015$, Threshold = $(2/5) \times 0.05 = 0.020$
- $i=3$, $p_{(3)} = 0.025$, Threshold = $(3/5) \times 0.05 = 0.030$
- $i=4$, $p_{(4)} = 0.031$, Threshold = $(4/5) \times 0.05 = 0.040$
- $i=5$, $p_{(5)} = 0.200$, Threshold = $(5/5) \times 0.05 = 0.050$
Decision Phase (Step 3):
Let's go backwards starting from the end ($i=5$):
- For $i=5$: Is $0.200 \le 0.050$? No.
- For $i=4$: Is $0.031 \le 0.040$? Yes!
The largest index we found is $k=4$. According to the rule, the 1st, 2nd, 3rd, and 4th tests are all statistically significant.
Adjusted P-Value Calculation (Step 4):
Formula: $\text{Provisional} = m \times p_{(i)} / i$. (Here $m=5$). We will take the cumulative minimum from back to front.
- $i=5$: $\text{Provisional} = 5 \times 0.200 / 5 = 0.200$. (Minimum: 0.200) $\rightarrow$ $p_{\text{adj}(5)} = 0.200$
- $i=4$: $\text{Provisional} = 5 \times 0.031 / 4 = 0.03875$. (Min(0.03875, 0.200) = 0.03875) $\rightarrow$ $p_{\text{adj}(4)} = 0.03875$
- $i=3$: $\text{Provisional} = 5 \times 0.025 / 3 = 0.04166$. We must take the cumulative minimum: Min(0.04166, $p_{\text{adj}(4)}$) = Min(0.04166, 0.03875) = 0.03875. $\rightarrow$ $p_{\text{adj}(3)} = 0.03875$ (Note: It became smaller than its own provisional value!)
- $i=2$: $\text{Provisional} = 5 \times 0.015 / 2 = 0.0375$. Min(0.0375, 0.03875) = 0.0375 $\rightarrow$ $p_{\text{adj}(2)} = 0.0375$
- $i=1$: $\text{Provisional} = 5 \times 0.001 / 1 = 0.005$. Min(0.005, 0.0375) = 0.005 $\rightarrow$ $p_{\text{adj}(1)} = 0.005$
As a result, our adjusted p-values are respectively (and are all evaluated as being smaller or larger than q=0.05): 0.005, 0.0375, 0.03875, 0.03875, and 0.200. It is confirmed that the first four tests are smaller than the q=0.05 threshold and are rejected.
Common Errors and Misinterpretations
There are a few traps researchers frequently fall into when applying the algorithm step-by-step or reporting the results. The first error is viewing the "adjusted p-value" as a binary (right/wrong) decision mechanism like the classical $\alpha = 0.05$ logic. FDR controls a probability ratio; meaning, you have accepted that about 5 out of 100 results you find significant might still be erroneous (Type 1 Error). The second error is failing to report the p-values properly. Instead of providing only adjusted p-values, for the sake of transparency, the original raw p-values, the rank of the test ($i$), and the calculated BH threshold should be shared in a tabular format. In this way, other researchers can audit your calculation process.
Software Preferences and Alternative Implementations
While doing the Benjamini-Hochberg correction manually is instructive for small datasets, this process is automated with R, Python, or specialized statistical software (SPSS, SAS) in modern applications involving tens of thousands of tests. However, even if the "p.adjust" logic of every software yields the same result, the sorting algorithms they apply when encountering tied p-values might show slight differences. For example, if three different tests yield the exact same raw p-value (0.015), should the same index be assigned to all three, or should they be randomly ordered and given different thresholds? The standard application of the BH algorithm recommends making a decision by assigning a common or conservative index corresponding to the largest threshold among them for tests with tied p-values. Ultimately, knowing the documentation of the tool or software you are using (especially its tie-handling strategy) is of great importance for a transparent and reproducible analysis process.
Automate Your Calculations
While grasping the logic is educational, calculating large amounts of data manually causes errors and time loss. To calculate thousands of rows of your p-values in seconds without installing complex libraries or writing formulas in Excel, you should try our Benjamini-Hochberg False Discovery Rate Adjustment Calculator tool. Paste your raw data and instantly download flawless results where the cumulative step-up method has been applied!