EqualizedOdds.lean

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

/-
EqualizedOdds.lean. Equation 0.37 and chapter 14 section 14.6, equalized odds.

A group's favourable-decision rate is its true-positive rate times its base rate plus its
false-positive rate times one minus its base rate. Under equalized odds, equal true-positive
and false-positive rates across groups, the favourable rates agree exactly when the base
rates agree, given that the classifier separates at all. So equalized odds and parity of
outcomes cannot both hold when the base rates differ, which is the sense in which fairness
cannot be had three ways, and the file gives the numbers.
-/
import Mathlib

namespace DMO.EqualizedOdds

/-- The favourable-decision rate of a group with true-positive rate `tpr`, false-positive
rate `fpr`, and base rate `π`. -/
def favourable (tpr fpr π : ℝ) : ℝ := tpr * π + fpr * (1 - π)

/-- **Equalized odds with equal base rates gives parity.** -/
theorem parity_of_equal_base (tpr fpr π : ℝ) : favourable tpr fpr π = favourable tpr fpr π := rfl

/-- The gap in favourable rates under equalized odds is the separation times the gap in base
rates. -/
theorem favourable_sub (tpr fpr πa πb : ℝ) :
    favourable tpr fpr πa - favourable tpr fpr πb = (tpr - fpr) * (πa - πb) := by
  unfold favourable
  ring

/-- **Equalized odds and parity conflict when base rates differ.** With a classifier that
separates, the favourable rates agree exactly when the base rates do. -/
theorem parity_iff_equal_base (tpr fpr πa πb : ℝ) (hsep : tpr ≠ fpr) :
    favourable tpr fpr πa = favourable tpr fpr πb ↔ πa = πb := by
  rw [← sub_eq_zero, favourable_sub, mul_eq_zero, sub_eq_zero, sub_eq_zero]
  constructor
  · rintro (h | h)
    · exact absurd h hsep
    · exact h
  · intro h; right; exact h

/-- **The numbers.** True-positive rate 0.8 and false-positive rate 0.2 in both groups, base
rates one half and one tenth, give favourable rates 0.5 and 0.26, a disparate impact ratio
below four fifths. -/
theorem example_conflict :
    favourable 0.8 0.2 0.5 = 0.5 ∧ favourable 0.8 0.2 0.1 = 0.26 ∧
      (0.26 : ℝ) / 0.5 < 4 / 5 := by
  unfold favourable
  refine ⟨by norm_num, by norm_num, by norm_num⟩

end DMO.EqualizedOdds