Bonferroni.lean

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

/-
Bonferroni.lean. Equation 8.3.

A harness that looks at the data `m` times at level `α` passes at least one null test with
probability `1 − (1 − α)^m`, which is at most `m α`. Dividing the level by the number of looks
brings the family-wise rate back under `α`. Both are Bernoulli's inequality.
-/
import Mathlib

namespace DMO.Bonferroni

/-- **Equation 8.3, the family-wise error.** Under independence, `m` looks at level `α` pass at
least one null test with probability `1 − (1 − α)^m`, and that is at most `m α`. -/
theorem family_error_le (α : ℝ) (hα1 : α ≤ 1) (m : ℕ) :
    1 - (1 - α) ^ m ≤ m * α := by
  have h := one_add_mul_le_pow (show (-2 : ℝ) ≤ -α by linarith) m
  have e : (1 : ℝ) + -α = 1 - α := by ring
  rw [e] at h
  linarith

/-- **The Bonferroni correction.** Testing each of `m` looks at level `α / m` keeps the
family-wise rate at or below `α`. -/
theorem bonferroni (α : ℝ) (hα1 : α ≤ 1) (m : ℕ) (hm : 0 < m) :
    1 - (1 - α / m) ^ m ≤ α := by
  have hm' : (0 : ℝ) < m := by exact_mod_cast hm
  have hm1 : (1 : ℝ) ≤ m := by exact_mod_cast hm
  have h := family_error_le (α / m) ((div_le_one hm').2 (hα1.trans hm1)) m
  have e : (m : ℝ) * (α / m) = α := by field_simp
  rw [e] at h
  exact h

/-- One preregistered look needs no correction. -/
theorem one_look (α : ℝ) : 1 - (1 - α) ^ 1 = α := by ring

end DMO.Bonferroni