ConfidenceInterval.lean
Lean 4 source, lean/DataMiningAsObservation/ConfidenceInterval.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
ConfidenceInterval.lean. Chapter 0 section 0.9, the confidence interval.
An interval with coverage `1 − α` misses the true value in a fraction `α` of repeated
samples. Over `m` independent intervals the expected number of misses is `m α`, the chance
that all of them cover is `(1 − α)^m`, and the chance that at least one misses is at most
`m α`, which is the family-wise error of the Bonferroni file. With nine intervals at
ninety-five percent, the chance of two or more misses is about seven percent, which is how
chapter 14 reads seven of nine inside the interval.
-/
import Mathlib
import DataMiningAsObservation.Bonferroni
namespace DMO.ConfidenceInterval
/-- The miss rate of an interval with coverage `1 − α`. -/
def missRate (α : ℝ) : ℝ := 1 - (1 - α)
/-- Coverage and miss rate are complements. -/
theorem missRate_eq (α : ℝ) : missRate α = α := by
unfold missRate; ring
/-- **The expected number of misses** over `m` independent intervals is `m α`. -/
def expectedMisses (m : ℕ) (α : ℝ) : ℝ := m * α
/-- **The chance that all cover** is `(1 − α)^m`, and the chance that at least one misses is at
most `m α`. -/
theorem some_miss_le (α : ℝ) (hα1 : α ≤ 1) (m : ℕ) : 1 - (1 - α) ^ m ≤ m * α :=
DMO.Bonferroni.family_error_le α hα1 m
/-- **Nine intervals at ninety-five percent.** The chance of at most one miss is between 0.92
and 0.93, so the chance of two or more misses is about seven percent. -/
theorem nine_intervals :
(0.92 : ℝ) < 0.95 ^ 9 + 9 * 0.05 * 0.95 ^ 8 ∧ (0.95 : ℝ) ^ 9 + 9 * 0.05 * 0.95 ^ 8 < 0.93 := by
constructor <;> norm_num
/-- The expected misses for the chapter 14 table, nine intervals at five percent. -/
theorem nine_expected : expectedMisses 9 0.05 = 0.45 := by
unfold expectedMisses; norm_num
end DMO.ConfidenceInterval