Unit 13, lesson 101

Multiple testing and backtest overfitting

How searching many strategies changes false-rejection probabilities, how Bonferroni controls the family-wise error rate, how Benjamini-Hochberg controls the false discovery rate, and what backtest overfitting means.

  • Video 101
  • Validation, multiple testing and cointegration

A research team tries a hundred variations of a trading rule on the same history and reports the variation whose backtest has the smallest p-value. Read as the result of one test chosen in advance, that p-value can look like strong evidence of a positive expected return. The experiment that produced it was a search, though, and the winner of a search has to be judged against what searches produce by chance. This lesson derives how the number of trials changes false-rejection probabilities, proves that the Bonferroni correction controls the family-wise error rate under any dependence, proves the Benjamini-Hochberg bound on the false discovery rate for independent p-values, and sets out what a backtest-overfitting diagnostic can and cannot say.

Key terms

Multiple testing

Definition A multiple testing problem has null hypotheses H1,…,HmH_1, \dots, H_m about one data set, p-values p1,…,pmp_1, \dots, p_m, and a procedure that decides from the p-values which hypotheses to reject. Let H0\mathcal{H}_0 be the unknown set of indices of the true nulls, m0=∣H0∣m_0 = \lvert \mathcal{H}_0 \rvert, RR the number of rejections and VV the number of rejected true nulls. The p-value of a true null is valid, or super-uniform, if

P(pj≤u)≤u\mathbb{P}(p_j \le u) \le u

for every u∈[0,1]u \in [0, 1], where P\mathbb{P} is the law that generates the data. An exact p-value, such as one computed from a continuous test statistic with a correctly specified null distribution, satisfies this with equality and is uniform on [0,1][0, 1]. If each hypothesis is rejected when pj≤αp_j \le \alpha, then E[V]≤m0 α\mathbb{E}[V] \le m_0\,\alpha under any dependence, by linearity of expectation. If all mm nulls are true and the p-values are independent and exact, then

P(V≥1)=1−(1−α)m,\mathbb{P}(V \ge 1) = 1 - (1 - \alpha)^m,

because all mm p-values exceed α\alpha with probability (1−α)m(1 - \alpha)^m, a product that needs independence.

In plain words Each test alone has a small chance of a false alarm. Running many tests gives many chances, and the chance that at least one of them goes off grows quickly with the number of tests, even though no single test has changed.

Example With m=100m = 100 independent exact null tests at α=0.05\alpha = 0.05, the probability of at least one rejection is 1−0.95100≈0.99411 - 0.95^{100} \approx 0.9941, and the expected number of false rejections is 100⋅0.05=5100 \cdot 0.05 = 5. Each test still rejects with probability exactly 0.050.05. A rejection in this experiment carries little evidence, because some rejection was almost certain to occur.

Selection bias

Definition Selection bias is the error made when a statistic is reported because it was the best of several and is then judged as if it had been chosen in advance. If the null scores Z1,…,ZmZ_1, \dots, Z_m are independent with a common distribution function FF, then

P(max⁡jZj≤z)=F(z)m,\mathbb{P}\bigl(\max_j Z_j \le z\bigr) = F(z)^m,

since the maximum is at most zz exactly when every score is. Under these assumptions and for a continuous FF, a winner whose single-test p-value is u=1−F(z)u = 1 - F(z) has the selection-adjusted p-value 1−(1−u)m1 - (1 - u)^m. If each score has distribution function FF but the dependence between them is arbitrary, only the bounds

1−F(z)≤P(max⁡jZj>z)≤min⁡(1,m(1−F(z)))\begin{aligned} &1 - F(z) \le \mathbb{P}\bigl(\max_j Z_j > z\bigr) \\[0.4em] &\quad \le \min\bigl(1, m(1 - F(z))\bigr) \end{aligned}

hold in general, the lower one because the maximum is at least Z1Z_1 and the upper one by the union bound. The count mm in these formulas is the number of candidates whose results could have influenced the choice, not the number shown. Trial accounting is the record of every configuration evaluated, including changed lookbacks, universes and entry thresholds and the variants that were discarded, together with the data and the score used for each, so that the selection experiment can be stated. When attempts are missing from the record, an adjustment that uses the recorded count corrects for a smaller search than the one that took place.

In plain words The best of many noisy scores is large even when no candidate has any edge. It has to be compared with what the best of that many scores looks like by chance, and that comparison needs an honest count of the attempts.

Example Suppose the null scores are 2020 independent standard normal variables. The best of them exceeds the one-sided 55 percent critical value Φ−1(0.95)≈1.645\Phi^{-1}(0.95) \approx 1.645 of a single test with probability 1−0.9520≈0.64151 - 0.95^{20} \approx 0.6415. A winner at z=2.5z = 2.5 has the single-test p-value 1−Φ(2.5)≈0.00621 - \Phi(2.5) \approx 0.0062, but its selection-adjusted p-value is

1−(1−0.0062)20≈0.117.1 - (1 - 0.0062)^{20} \approx 0.117 .

With 100100 such candidates, the median of the maximum is Φ−1(0.51/100)≈2.46\Phi^{-1}\bigl(0.5^{1/100}\bigr) \approx 2.46, so a search over 100100 candidates without any edge produces a winning score above 2.462.46 half the time.

Family-wise error rate

Definition The family-wise error rate of a procedure is FWER⁡=P(V≥1)\operatorname{FWER} = \mathbb{P}(V \ge 1), the probability of at least one false rejection, computed under the true configuration of nulls and alternatives. The Bonferroni correction rejects HjH_j when pj≤α/mp_j \le \alpha/m. If every true-null p-value is valid, then whatever the dependence between the p-values and whichever hypotheses are true, the union bound gives

FWER⁡=P(⋃j∈H0{pj≤α/m})≤∑j∈H0αm=m0 αm≤α.\begin{aligned} &\operatorname{FWER} \\[0.4em] &= \mathbb{P}\Bigl(\bigcup_{j \in \mathcal{H}_0}\{p_j \le \alpha/m\}\Bigr) \\[0.4em] &\le \sum_{j \in \mathcal{H}_0}\frac{\alpha}{m} = \frac{m_0\,\alpha}{m} \le \alpha . \end{aligned}

The bound is attained when m0=mm_0 = m, the p-values are exact and the rejection events are disjoint. Under strong positive dependence it is conservative, and if all the true-null p-values equal one exact p-value, the family-wise error rate is only α/m\alpha/m.

In plain words Bonferroni splits the error budget α\alpha evenly across the mm tests. It protects against even one false alarm and needs no assumption about how the tests depend on each other. The price is a much stricter threshold for each test.

Example For m=100m = 100 and α=0.05\alpha = 0.05 the threshold is 0.00050.0005. With 100100 independent exact null p-values, the family-wise error rate is 1−0.9995100≈0.04881 - 0.9995^{100} \approx 0.0488, below the bound 0.050.05. The exact value uses independence, while the bound holds without it. For the four constructed p-values 0.0010.001, 0.0120.012, 0.0250.025 and 0.120.12 with α=0.05\alpha = 0.05, the threshold is 0.05/4=0.01250.05/4 = 0.0125, and Bonferroni rejects the first two.

False discovery rate

Definition The false discovery proportion is V/max⁡(R,1)V/\max(R, 1), the fraction of rejections that are false, which is 00 when nothing is rejected. The false discovery rate is its expectation,

FDR⁡=E[Vmax⁡(R,1)].\operatorname{FDR} = \mathbb{E}\left[\frac{V}{\max(R, 1)}\right].

Since V≤RV \le R, the proportion is at most the indicator 1{V≥1}\mathbf{1}_{\{V \ge 1\}}, so FDR⁡≤FWER⁡\operatorname{FDR} \le \operatorname{FWER} for every procedure. Under the global null, m0=mm_0 = m, every rejection is false, the proportion equals 1{R≥1}\mathbf{1}_{\{R \ge 1\}}, and the two rates coincide. When some alternatives are true, controlling the false discovery rate at a level qq bounds the expected fraction of false rejections among the rejections. That is a weaker requirement than control of the family-wise error rate, and it allows several false rejections among many rejections. The false discovery rate is the expectation of a ratio, not the ratio E[V]/E[R]\mathbb{E}[V]/\mathbb{E}[R] of expectations.

In plain words The family-wise error rate asks how likely it is to make even one mistake. The false discovery rate asks what fraction of the reported discoveries are mistakes, on average over repetitions of the experiment. When there are many true effects, the second question permits more rejections.

Example In a constructed experiment, with probability 12\tfrac12 the procedure makes one rejection, which is false, and with probability 12\tfrac12 it makes nine rejections, all correct. The false discovery rate is 12⋅1+12⋅0=0.5\tfrac12 \cdot 1 + \tfrac12 \cdot 0 = 0.5, the same as the family-wise error rate, while E[V]/E[R]=0.5/5=0.1\mathbb{E}[V]/\mathbb{E}[R] = 0.5/5 = 0.1.

Benjamini-Hochberg procedure

Definition Fix a level q∈(0,1)q \in (0, 1) and order the p-values as p(1)≤⋯≤p(m)p_{(1)} \le \dots \le p_{(m)}. Let k∗k^* be the largest kk in {1,…,m}\{1, \dots, m\} with

p(k)≤k qm,p_{(k)} \le \frac{k\,q}{m},

and k∗=0k^* = 0 if there is none. The procedure rejects the hypotheses with the k∗k^* smallest p-values. It is a step-up rule, which looks for the largest qualifying position, so a failed comparison at a smaller position does not end the search. Equivalently, R=k∗R = k^* and the rejected set is {j:pj≤qR/m}\{j : p_j \le qR/m\}, because a p-value at a position beyond k∗k^* that is at most k∗q/mk^* q/m would make that position qualify as well.

The theorem is that if the p-values are mutually independent and every true-null p-value is valid, then

FDR⁡≤m0 qm≤q.\operatorname{FDR} \le \frac{m_0\,q}{m} \le q .

For the proof, fix a true null ii and let Ri0R_i^0 be the number of rejections when pip_i is replaced by 00 and the other p-values are kept. Then Ri0≥1R_i^0 \ge 1, because the zero p-value makes position 11 qualify. The count Ri0R_i^0 depends only on (pj)j≠i(p_j)_{j \ne i}, and hypothesis ii is rejected exactly when pi≤qRi0/mp_i \le qR_i^0/m, in which case R=Ri0R = R_i^0. To see this, write N(c)N(c) for the number of p-values at most cc, so that a position kk qualifies exactly when N(kq/m)≥kN(kq/m) \ge k. Lowering pip_i can only raise NN, so R≤Ri0R \le R_i^0. If pi≤qRi0/mp_i \le qR_i^0/m, which holds in particular when ii is rejected, the original and modified counts agree at c=qRi0/mc = qR_i^0/m, so the position Ri0R_i^0 also qualifies for the original p-values. Then R=Ri0R = R_i^0 and pi≤qR/mp_i \le qR/m, so ii is rejected. Hence

1{i rejected}max⁡(R,1)=1{pi≤qRi0/m}Ri0.\begin{aligned} &\frac{\mathbf{1}_{\{i \text{ rejected}\}}}{\max(R, 1)} \\[0.4em] &= \frac{\mathbf{1}_{\{p_i \le qR_i^0/m\}}}{R_i^0} . \end{aligned}

Conditioning on the other p-values fixes Ri0R_i^0, and by independence pip_i stays valid, so the conditional expectation is at most (qRi0/m)/Ri0=q/m(qR_i^0/m)/R_i^0 = q/m. Summing over the m0m_0 true nulls, whose rejection indicators add up to VV, gives FDR⁡≤m0q/m\operatorname{FDR} \le m_0 q/m. With exact true-null p-values each step is an equality and FDR⁡=m0q/m\operatorname{FDR} = m_0 q/m. Other dependence structures need their own conditions, such as a form of positive dependence, or a stricter threshold, and those results are not derived here.

In plain words Compare the kkth smallest p-value with a threshold that grows in proportion to kk, find the last position where the p-value is under its threshold, and reject everything up to there. A p-value that fails its own comparison is still rejected when a larger p-value further down passes.

Example Take the constructed p-values 0.0010.001, 0.0120.012, 0.0250.025 and 0.120.12 with q=0.05q = 0.05 and m=4m = 4. The thresholds are 0.01250.0125, 0.0250.025, 0.03750.0375 and 0.050.05. The first three p-values are at or below their thresholds and 0.12>0.050.12 > 0.05, so k∗=3k^* = 3, and the procedure rejects three hypotheses where Bonferroni at the same level rejected two. This identifies the rejection set only. Which of the three are true nulls is unknown, and the theorem bounds an expectation over repetitions of the experiment, not the false fraction of this one outcome.

Backtest overfitting

Definition Backtest overfitting is present when a configuration is chosen from a candidate family because of its backtest on a sample and its score on that sample overstates its performance on data that played no part in the choice, because the choice rewarded noise along with any real effect. A diagnostic studies the selection step itself. Combinatorially symmetric cross-validation takes NN candidates whose performance series are cut into SS blocks of equal length, SS even. For each of the (SS/2)\binom{S}{S/2} ways of choosing half the blocks as the selection sample, it picks the candidate with the best score on that half and records the relative rank ω=r/(N+1)\omega = r/(N + 1) of that candidate’s score on the other half, where r=1r = 1 is the worst of the NN and r=Nr = N the best. The fraction of splits with ω≤12\omega \le \tfrac12, the splits in which the selected candidate lands in the bottom half out of sample, is reported as an estimate of the probability of backtest overfitting. That number is conditional on the candidate family, the score, the data and the partition design. The splits also select on later blocks and evaluate on earlier ones, so the diagnostic does not follow the time order of a forecast. The number is not a probability that a future trade or strategy will lose, and trials missing from the family limit what it can say.

In plain words If the winner chosen on one part of the history keeps landing near the bottom on the rest, the search was mostly rewarding luck. The diagnostic counts how often that happens over many ways of cutting the history, for the family that was actually searched.

Example Four candidates have the following constructed mean daily returns, in basis points, on four blocks of equal length, so the score on two blocks is the average of their two entries.

CandidateBlock 1Block 2Block 3Block 4
A−3-3−2-233−5-5
B0055−3-3−4-4
C55−2-211−2-2
D110044−2-2

Selecting on blocks 1 and 2 gives the scores −2.5-2.5, 2.52.5, 1.51.5 and 0.50.5, so B wins, and on blocks 3 and 4 the scores are −1-1, −3.5-3.5, −0.5-0.5 and 11, so B is the worst, with r=1r = 1 and ω=0.2\omega = 0.2. Over all six splits the winners are B, C, C, D, B and D for the selection halves {1,2}\{1, 2\}, {1,3}\{1, 3\}, {1,4}\{1, 4\}, {2,3}\{2, 3\}, {2,4}\{2, 4\} and {3,4}\{3, 4\}, with out-of-sample ranks 11, 22, 11, 33, 11 and 22. Five of the six winners land in the bottom half, so the estimate is 5/6≈0.835/6 \approx 0.83 for this family, these blocks and this score. Candidate D, which has the best average over all four blocks, wins only two of the six selections.

Check yourself

  1. Twenty independent exact null tests are each run at α=0.05\alpha = 0.05. Find the probability of at least one rejection and the expected number of rejections. What threshold does the Bonferroni correction use for a family-wise error rate of 0.050.05, and what is the family-wise error rate with that threshold here?
Show the answer

All twenty p-values exceed 0.050.05 with probability 0.95200.95^{20}, so the probability of at least one rejection is 1−0.9520≈0.64151 - 0.95^{20} \approx 0.6415. The expected number of rejections is 20⋅0.05=120 \cdot 0.05 = 1, which needs no independence. The Bonferroni threshold is 0.05/20=0.00250.05/20 = 0.0025. Under independence the family-wise error rate is then

1−0.997520≈0.0488,1 - 0.9975^{20} \approx 0.0488 ,

below 0.050.05. The bound 0.050.05 would still hold if the tests were dependent, while the value 0.04880.0488 uses independence.

  1. Apply the Benjamini-Hochberg procedure with q=0.05q = 0.05 to the p-values 0.0010.001, 0.030.03, 0.0350.035 and 0.040.04. A colleague compares them with the thresholds in order and stops at the first failure. How many hypotheses does each approach reject, and which one is the procedure?
Show the answer

The thresholds kq/4kq/4 are 0.01250.0125, 0.0250.025, 0.03750.0375 and 0.050.05. The first p-value passes, the second fails since 0.03>0.0250.03 > 0.025, the third passes since 0.035≤0.03750.035 \le 0.0375 and the fourth passes since 0.04≤0.050.04 \le 0.05. The largest qualifying position is k∗=4k^* = 4, so the procedure rejects all four hypotheses. Stopping at the first failure rejects only one, which is a step-down reading, not the step-up rule. The rejected set agrees with {j:pj≤qR/m}\{j : p_j \le qR/m\} for R=4R = 4, since every p-value is at most 0.050.05. Bonferroni at level 0.050.05, with threshold 0.01250.0125, would reject only the first.

  1. An analyst backtests 200200 variants of a rule on the same history, keeps the four with the smallest p-values and applies the Benjamini-Hochberg procedure with m=4m = 4 to those four. Why is the result not an FDR guarantee, and what does a p-value of 0.0010.001 need with m=200m = 200 and q=0.05q = 0.05?
Show the answer

The theorem assumes valid p-values for a family fixed in advance. The four p-values kept are the smallest of 200200, so their distribution under the nulls is far from super-uniform, and treating them as a family of four ignores the search. If all 200200 nulls were true with independent exact p-values, the smallest would be at most 0.0010.001 with probability 1−0.999200≈0.1811 - 0.999^{200} \approx 0.181. The family is all 200200 variants. With m=200m = 200 and q=0.05q = 0.05, a hypothesis is rejected exactly when its p-value is at most 0.05 R/200=0.00025 R0.05\,R/200 = 0.00025\,R, so a p-value of 0.0010.001 is rejected only if the procedure makes at least four rejections in all. The independence used in the proof is also doubtful for variants of one rule tested on the same history, while Bonferroni over all 200200, with threshold 0.000250.00025, needs no independence and would not reject 0.0010.001.

How this lesson connects