/-- The mean minimises the sum of squared deviations.
Hint: rewrite with `sum_sq_sub hn x c`; the extra term `n * (mean x - c) ^ 2` is `≥ 0`
(`positivity`), and `linarith` finishes. -/
theorem mean_minimizes {n : ℕ} (hn : 0 < n) (x : Fin n → ℝ) (c : ℝ) :
∑ i, (x i - mean x) ^ 2 ≤ ∑ i, (x i - c) ^ 2 := by
sorryShow the compiled solution
/-- **The mean minimises the sum of squared deviations:** `Σ (xᵢ − x̄)² ≤ Σ (xᵢ − c)²` for
every number `c`, with the extra amount exactly `n (x̄ − c)²`. -/
theorem mean_minimizes {n : ℕ} (hn : 0 < n) (x : Fin n → ℝ) (c : ℝ) :
∑ i, (x i - mean x) ^ 2 ≤ ∑ i, (x i - c) ^ 2 := by
rw [sum_sq_sub hn x c]
have : 0 ≤ (n : ℝ) * (mean x - c) ^ 2 := by positivity
linarithAxioms used: propext, Classical.choice, Quot.soundformal/Lumenary/StatisticalInferenceIntro.leanTry it in the Lean web editor