Imputation.lean
Lean 4 source, lean/DataMiningAsObservation/Imputation.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Imputation.lean. Chapter 2 section 2.3, imputation.
Mean imputation writes the observed mean into every missing cell. The mean of the filled
column equals the observed mean, the filled cells contribute nothing to the sum of squared
deviations, and the variance shrinks because the same sum of squares is spread over more
rows. The consumer reads the filled cells all the same, which is why chapter 2 calls an
imputation a claim.
-/
import Mathlib
namespace DMO.Imputation
/-- **Filling `m` cells with the observed mean leaves the mean unchanged.** With `S` the
observed sum over `n` rows. -/
theorem mean_imputed (S : ℝ) (n m : ℕ) (hn : 0 < n) :
(S + m * (S / n)) / (n + m) = S / n := by
have hn' : (n : ℝ) ≠ 0 := by positivity
have hnm : (n : ℝ) + m ≠ 0 := by positivity
rw [div_eq_div_iff hnm hn', show (m : ℝ) * (S / n) = m * S / n by ring, add_div' _ _ _ hn',
div_mul_cancel₀ _ hn']
ring
/-- **The filled cells add nothing to the sum of squared deviations.** -/
theorem sum_sq_imputed (SS μ : ℝ) (m : ℕ) : SS + m * (μ - μ) ^ 2 = SS := by
ring
/-- **The variance shrinks.** The same sum of squares over more rows is smaller. -/
theorem variance_imputed_le (SS : ℝ) (hSS : 0 ≤ SS) (n m : ℕ) (hn : 0 < n) :
SS / (n + m) ≤ SS / n := by
apply div_le_div_of_nonneg_left hSS (by exact_mod_cast hn)
exact le_add_of_nonneg_right (Nat.cast_nonneg m)
end DMO.Imputation