Library · Validation

The best of N trials

The best result among many attempts carries a selection bias: it was kept because it was high. The more variants were tried, the better the best one looks, even when none has any real effect.

By , published

Definition

Each trial gives an estimate with noise. The maximum of N noisy estimates is larger than a typical one, and its expected value grows with N. For independent standard normal noise it grows roughly like the square root of twice the logarithm of N.

E[ max of N ] ≈ σ √( 2 ln N )

A p-value answers the question for one test fixed in advance. Applied to the winner of a search, it overstates the evidence. Corrections exist: Bonferroni controls the chance of any false positive, and the Benjamini-Hochberg procedure controls the expected share of false positives among the discoveries.

Worked example

Each trial is a feature of pure noise, tested for a difference between two groups of 200 rows. We print the smallest p-value found as the number of trials grows, then count the discoveries on 1,000 trials of which 20 have a real effect.

import numpy as np
from scipy import stats

rng = np.random.default_rng(5)

def p_values(n_trials, n_real=0, effect=0.4):
    a = rng.normal(size=(n_trials, 200))
    b = rng.normal(size=(n_trials, 200))
    b[:n_real] += effect
    return stats.ttest_ind(a, b, axis=1).pvalue

for n in (1, 10, 100, 1000):
    print(f"{n:5d} trials of pure noise: smallest p-value = {p_values(n).min():.4f}")

p = p_values(1000, n_real=20)
order = np.argsort(p)
passed = np.nonzero(p[order] <= 0.05 * np.arange(1, 1001) / 1000)[0]
k = passed.max() + 1 if passed.size else 0
found = order[:k]
print(f"1,000 trials, 20 real: p < 0.05 flags {np.sum(p < 0.05)} (real among them: {np.sum(p[:20] < 0.05)})")
print(f"Benjamini-Hochberg at 5 %: {k} discoveries, of which real: {np.sum(found < 20)}")

Output, produced by running the code above when this page was built:

    1 trials of pure noise: smallest p-value = 0.7895
   10 trials of pure noise: smallest p-value = 0.0627
  100 trials of pure noise: smallest p-value = 0.0021
 1000 trials of pure noise: smallest p-value = 0.0008
1,000 trials, 20 real: p < 0.05 flags 76 (real among them: 20)
Benjamini-Hochberg at 5 %: 14 discoveries, of which real: 14

With a thousand trials of noise, a p-value that would look decisive for a single test appears by chance. On the mixed set, the raw threshold flags dozens of noise features next to the real ones; the procedure keeps a short list, at the price of missing some real effects.

Where it misleads

  • The number of trials is rarely known. Variants tried and abandoned, by the analyst or by colleagues on the same data, count too.
  • Trials are not independent. A hundred variations of one idea are closer to a handful of independent attempts, and a correction by the raw count is then too severe.
  • A stricter threshold reduces false positives and discards real effects in proportion. With a small sample the loss of power can exceed the protection gained.

A correction adjusts the reading of data that has already been searched. Fresh data needs no correction: one result named in advance, read once on a sample that took no part in the search, as in the sealed test set.

In our work

We report the number of trials behind each result and we do not tighten thresholds as that number grows. The decision rests on development checks and on one read of a sealed sample; at an older, stricter threshold we measured 34 real effects discarded for each false positive avoided.

References

  1. Benjamini, Y., Hochberg, Y. (1995). Controlling the false discovery rate: a practical and powerful approach to multiple testing. Journal of the Royal Statistical Society: Series B, 57(1), 289-300. doi:10.1111/j.2517-6161.1995.tb02031.x
  2. White, H. (2000). A reality check for data snooping. Econometrica, 68(5), 1097-1126. doi:10.1111/1468-0262.00152
  3. Harvey, C. R., Liu, Y., Zhu, H. (2016). ... and the cross-section of expected returns. Review of Financial Studies, 29(1), 5-68. doi:10.1093/rfs/hhv059

Have a question like this one on your own data? Tell us what you need in a few lines.

Send us the brief

Related pages

  • The deflated Sharpe ratioA Sharpe ratio selected among many backtests has to beat more than zero: it has to beat the best ratio that pure noise would produce over the same number of trials. The deflated Sharpe ratio makes that comparison.
  • PBO: the probability of backtest overfittingThe probability of backtest overfitting asks one question of a search: when the best configuration is chosen on part of the data, where does it rank on the rest. If it usually falls in the bottom half, the selection found noise.
  • The sealed test set, read onceA holdout sample gives an unbiased estimate once. Each time a decision is taken after looking at it, a little of it passes into the model. After enough rounds the reported score describes the holdout, not the future.
All library pages