MultipleComparisons.lean

Lean 4 source, lean/DataMiningAsObservation/MultipleComparisons.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
MultipleComparisons.lean. Chapter 0 section 0.9 and chapter 5 section 5.5, multiple comparisons.

Test many hypotheses and report the best, and the reported score is the maximum of many
noisy draws, which is at least any single draw. At a five percent threshold, ten thousand
null hypotheses produce five hundred passes in expectation and forty produce two. The
Bonferroni correction of equation 8.3, checked in Bonferroni.lean, divides the threshold by
the number of tests, which at ten thousand tests is five in a million.
-/
import Mathlib
import DataMiningAsObservation.Bonferroni

namespace DMO.MultipleComparisons

open Finset

variable {ι : Type*}

/-- **Reporting the best of many.** The maximum over the tests is at least any single test's
score, so the reported number is biased upward by the selection. -/
theorem max_ge_each (T : Finset ι) (hT : T.Nonempty) (score : ι → ℝ) (i : ι) (hi : i ∈ T) :
    score i ≤ T.sup' hT score :=
  Finset.le_sup' score hi

/-- The expected number of null passes at level `α` over `m` independent tests is `m α`. -/
def expectedPasses (m : ℕ) (α : ℝ) : ℝ := m * α

/-- **The chapter's numbers.** Ten thousand tests at five percent pass five hundred by chance,
forty pass two, and the Bonferroni threshold at ten thousand tests is five in a million. -/
theorem book_numbers :
    expectedPasses 10000 0.05 = 500 ∧ expectedPasses 40 0.05 = 2 ∧
      (0.05 : ℝ) / 10000 = 5e-6 := by
  unfold expectedPasses
  refine ⟨by norm_num, by norm_num, by norm_num⟩

/-- **The family-wise rate at the corrected level stays under the target**, ten thousand
tests included. -/
theorem corrected_family_rate (m : ℕ) (hm : 0 < m) :
    1 - (1 - 0.05 / m) ^ m ≤ (0.05 : ℝ) :=
  DMO.Bonferroni.bonferroni 0.05 (by norm_num) m hm

/-- The expected passes grow linearly in the number of tests, so no fixed threshold survives
an unbounded search. -/
theorem expectedPasses_unbounded (α : ℝ) (hα : 0 < α) (M : ℝ) : ∃ m : ℕ, M < expectedPasses m α := by
  unfold expectedPasses
  obtain ⟨m, hm⟩ := exists_nat_gt (M / α)
  exact ⟨m, by rwa [div_lt_iff₀ hα] at hm⟩

end DMO.MultipleComparisons