Panel.Weighted
Weighted panel estimators: weighting schemes over cohorts/periods and the estimands they aggregate to.
Support 2 core · 3 supporting This file defines WeightedSupport, a finite observed support equipped with strictly positive weights that sum to one on the observed set and vanish off it. ★ sum_weight
Weighted finite supports
This file defines WeightedSupport, a finite observed support equipped with
strictly positive weights that sum to one on the observed set and vanish off it.
It also proves the basic normalization lemmas weight_nonneg,
sum_weight_univ, sum_weight, and sum_weight_univ_eq_one.
The resulting object is the common finite weighted-index substrate for weighted inner products, weighted least squares, and Frisch-Waugh-Lovell decompositions.
A finite weighted index together with positive normalized weights: a nonempty observed subset of indices together with a weight function that is strictly positive on every observed index, vanishes off the observed set, and sums to one over the observed indices.
Definition (Lean source)
For a weighted-support system c, the weights sum to one over the observed index set (restated from the structure's normalization field for convenient reuse).
Formal statement
Proof (Lean source)
3 supporting declarations (lemmas, instances)
-
weight_nonneglemma — The weight function ω is nonnegative everywhere on R.Proof (Lean source)
lemma weight_nonneg (c : WeightedSupport R) (r : R) : 0 ≤ c.weight r := by by_cases h : r ∈ c.observed · exact (c.weight_pos r h).le · simp [c.weight_zero_off r h] -
sum_weight_univlemma — Summing ω over the full type R equals summing over observed, because ω vanishes outside observed.Proof (Lean source)
lemma sum_weight_univ (c : WeightedSupport R) : ∑ r, c.weight r = ∑ r ∈ c.observed, c.weight r := by classical refine (Finset.sum_subset (Finset.subset_univ _) ?_).symm intro r _ hr exact c.weight_zero_off r hr -
sum_weight_univ_eq_onelemma — Summing the weights over Finset.univ gives 1.Proof (Lean source)
lemma sum_weight_univ_eq_one (c : WeightedSupport R) : ∑ r, c.weight r = 1 := by rw [c.sum_weight_univ, c.weight_sum_one]
InnerProduct 3 core · 14 supporting This file defines the scalar weighted inner product over observed records and its matrix-valued lift to tuples of arrays. ★ ip_self_eq_zero_iff
Weighted inner products over a finite support
This file defines the scalar weighted inner product over observed records and its matrix-valued lift to tuples of arrays.
The inner product is the WLS pairing used by the weighted projection, WLS-optimality, and Frisch-Waugh-Lovell layers. It is bilinear, positive-semidefinite, definite on the observed support, and symmetric after matrix transposition.
The weighted inner product multiplies two arrays record by record and sums the products with the support weights over observed records.
Definition (Lean source)
For a weighted-support system c, the weighted self inner product ⟨A, A⟩_ω of an array A vanishes if and only if A is zero at every index in the observed set. Arrays that differ only off c.observed are thus identified by this inner product.
Formal statement
Proof (Lean source)
The matrix-valued inner product takes the scalar weighted inner product between each pair of columns.
Definition (Lean source)
14 supporting declarations (lemmas, instances)
-
ip_deflemma — The weighted inner product unfolds to its finite weighted sum over observed records.hypothesesc :A B :R → ℝconclusionc.ip A B = ∑ r ∈ c.observed, c.weight r * A r * B rProof (Lean source)
@[simp] lemma ip_def (c : WeightedSupport R) (A B : R → ℝ) : c.ip A B = ∑ r ∈ c.observed, c.weight r * A r * B r := rfl -
ip_symmlemma — Symmetry of the weighted inner product.Proof (Lean source)
lemma ip_symm (c : WeightedSupport R) (A B : R → ℝ) : c.ip A B = c.ip B A := by unfold ip refine Finset.sum_congr rfl ?_ intro r _ ring -
ip_add_leftlemma — Additivity in the left argument.Proof (Lean source)
lemma ip_add_left (c : WeightedSupport R) (A A' B : R → ℝ) : c.ip (A + A') B = c.ip A B + c.ip A' B := by unfold ip rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro r _ simp [Pi.add_apply]; ring -
ip_add_rightlemma — Additivity in the right argument.Proof (Lean source)
lemma ip_add_right (c : WeightedSupport R) (A B B' : R → ℝ) : c.ip A (B + B') = c.ip A B + c.ip A B' := by rw [ip_symm, ip_add_left, ip_symm c A B, ip_symm c A B'] -
ip_smul_leftlemma — Scalar homogeneity in the left argument.Proof (Lean source)
lemma ip_smul_left (c : WeightedSupport R) (s : ℝ) (A B : R → ℝ) : c.ip (s • A) B = s * c.ip A B := by unfold ip rw [Finset.mul_sum] refine Finset.sum_congr rfl ?_ intro r _ simp [Pi.smul_apply]; ring -
ip_smul_rightlemma — Scalar homogeneity in the right argument.Proof (Lean source)
lemma ip_smul_right (c : WeightedSupport R) (s : ℝ) (A B : R → ℝ) : c.ip A (s • B) = s * c.ip A B := by rw [ip_symm, ip_smul_left, ip_symm c A B] -
ip_self_summand_nonneglemma — Each summand of ⟨A, A⟩_ω is nonnegative.Proof (Lean source)
lemma ip_self_summand_nonneg (c : WeightedSupport R) (A : R → ℝ) : ∀ r ∈ c.observed, 0 ≤ c.weight r * A r * A r := by intro r hr have hw : 0 ≤ c.weight r := (c.weight_pos r hr).le have hsq : 0 ≤ A r * A r := mul_self_nonneg (A r) have : 0 ≤ c.weight r * (A r * A r) := mul_nonneg hw hsq simpa [mul_assoc] using this -
ip_self_nonneglemma — Positivity: ⟨A, A⟩_ω ≥ 0.Proof (Lean source)
lemma ip_self_nonneg (c : WeightedSupport R) (A : R → ℝ) : 0 ≤ c.ip A A := by unfold ip exact sum_nonneg (c.ip_self_summand_nonneg A) -
ipMat_applylemma — Each entry of the matrix-valued inner product is the scalar weighted inner product of the corresponding two columns.hypothesesconclusionc.ipMat A B j k = c.ip (A j) (B k)Proof (Lean source)
@[simp] lemma ipMat_apply (c : WeightedSupport R) (A B : J → R → ℝ) (j k : J) : c.ipMat A B j k = c.ip (A j) (B k) := rfl -
ipMat_transposelemma — The transpose of ⟨A, B⟩_ω is ⟨B, A⟩_ω.Proof (Lean source)
lemma ipMat_transpose (c : WeightedSupport R) (A B : J → R → ℝ) : (c.ipMat A B).transpose = c.ipMat B A := by ext j k rw [Matrix.transpose_apply, ipMat_apply, ipMat_apply, ip_symm] -
ipMat_add_leftlemma — Additivity in the left tuple argument (entrywise).hypothesesc :A A' B :J → R → ℝconclusionc.ipMat (A + A') B = c.ipMat A B + c.ipMat A' BProof (Lean source)
lemma ipMat_add_left (c : WeightedSupport R) (A A' B : J → R → ℝ) : c.ipMat (A + A') B = c.ipMat A B + c.ipMat A' B := by ext j k change c.ip ((A + A') j) (B k) = c.ipMat A B j k + c.ipMat A' B j k rw [Pi.add_apply, ip_add_left] simp [ipMat_apply] -
ipMat_add_rightlemma — Additivity in the right tuple argument (entrywise).hypothesesc :A B B' :J → R → ℝconclusionc.ipMat A (B + B') = c.ipMat A B + c.ipMat A B'Proof (Lean source)
lemma ipMat_add_right (c : WeightedSupport R) (A B B' : J → R → ℝ) : c.ipMat A (B + B') = c.ipMat A B + c.ipMat A B' := by ext j k change c.ip (A j) ((B + B') k) = c.ipMat A B j k + c.ipMat A B' j k rw [Pi.add_apply, ip_add_right] simp [ipMat_apply] -
ipMat_smul_leftlemma — Scalar homogeneity in the left tuple argument (entrywise).hypothesesconclusionc.ipMat (s • A) B = s • c.ipMat A BProof (Lean source)
lemma ipMat_smul_left (c : WeightedSupport R) (s : ℝ) (A B : J → R → ℝ) : c.ipMat (s • A) B = s • c.ipMat A B := by ext j k change c.ip ((s • A) j) (B k) = s • (c.ipMat A B) j k rw [Pi.smul_apply, ip_smul_left] simp [ipMat_apply, smul_eq_mul] -
ipMat_smul_rightlemma — Scalar homogeneity in the right tuple argument (entrywise).hypothesesconclusionc.ipMat A (s • B) = s • c.ipMat A BProof (Lean source)
lemma ipMat_smul_right (c : WeightedSupport R) (s : ℝ) (A B : J → R → ℝ) : c.ipMat A (s • B) = s • c.ipMat A B := by ext j k change c.ip (A j) ((s • B) k) = s • (c.ipMat A B) j k rw [Pi.smul_apply, ip_smul_right] simp [ipMat_apply, smul_eq_mul]
Subspace 5 core · 11 supporting This file defines the weighted orthogonal projection onto a nuisance subspace and the corresponding residual maker. ★ residualize_in_orthogonal
Weighted projections and residual makers
This file defines the weighted orthogonal projection onto a nuisance subspace and the corresponding residual maker.
The projection exists for the semidefinite weighted inner product because only observed records matter. The resulting projection and residual maker are used by the WLS optimality and finite-cell Frisch-Waugh-Lovell layers.
The c.ip-orthogonal projection onto H, chosen via classical choice from weighted_orthogonal_projection_exists.
Definition (Lean source)
The residual maker M_H = id - P_H.
Definition (Lean source)
The residualized scalar array X̃ := M_H X.
Definition (Lean source)
Key orthogonality. For any array h lying in the nuisance subspace H, the residualized array X̃ = M_H X is orthogonal to h under the weighted inner product c.ip.
Formal statement
Proof (Lean source)
Column-by-column residualization for vector arrays X : J → (R → ℝ).
Definition (Lean source)
11 supporting declarations (lemmas, instances)
-
weighted_orthogonal_projection_existslemma — Existence of a c.ip-orthogonal projection onto a subspace H.hypothesesc :H :Submodule ℝ (R → ℝ)conclusion∃ P : (R → ℝ) →ₗ[ℝ] (R → ℝ), (∀ X, P X ∈ H) ∧ (∀ X, ∀ h ∈ H, c.ip (X - P X) h = 0)Proof (Lean source)
lemma weighted_orthogonal_projection_exists (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) : ∃ P : (R → ℝ) →ₗ[ℝ] (R → ℝ), (∀ X, P X ∈ H) ∧ (∀ X, ∀ h ∈ H, c.ip (X - P X) h = 0) := by classical let B : BilinForm ℝ (R → ℝ) := LinearMap.mk₂ ℝ (fun X Y => c.ip X Y) (by intro X Y Z exact c.ip_add_left X Y Z) (by intro a X Z exact c.ip_smul_left a X Z) (by intro X Y Z exact c.ip_add_right X Y Z) (by intro a X Z exact c.ip_smul_right a X Z) have hsymm : ∀ X Y : R → ℝ, B X Y = B Y X := by intro X Y exact c.ip_symm X Y have hpos : ∀ X : R → ℝ, 0 ≤ B X X := by intro X exact c.ip_self_nonneg X rcases exists_orthogonalProjection_of_posSemidef (B := B) hsymm hpos H with ⟨P, hmem, horth⟩ refine ⟨P, hmem, ?_⟩ intro X h hH change B (X - P X) h = 0 exact horth X h hH -
proj_memlemma — The chosen weighted projection always lands in the nuisance subspace.Proof (Lean source)
lemma proj_mem (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) : c.proj H X ∈ H := (c.weighted_orthogonal_projection_exists H).choose_spec.1 X -
proj_orthogonallemma — The residual from the chosen weighted projection is orthogonal to every element of the nuisance subspace.hypothesesconclusionc.ip (X - c.proj H X) h = 0Proof (Lean source)
lemma proj_orthogonal (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) {h : R → ℝ} (hH : h ∈ H) : c.ip (X - c.proj H X) h = 0 := (c.weighted_orthogonal_projection_exists H).choose_spec.2 X h hH -
proj_apply_of_memlemma — If Y ∈ H then c.proj H Y agrees with Y on every observed index.hypothesesconclusionc.proj H Y r = Y rProof (Lean source)
lemma proj_apply_of_mem (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) {Y : R → ℝ} (hY : Y ∈ H) (r : R) (hr : r ∈ c.observed) : c.proj H Y r = Y r := by have hdiff : Y - c.proj H Y ∈ H := H.sub_mem hY (c.proj_mem H Y) have hself : c.ip (Y - c.proj H Y) (Y - c.proj H Y) = 0 := c.proj_orthogonal H Y hdiff have hzero : ∀ s ∈ c.observed, (Y - c.proj H Y) s = 0 := (c.ip_self_eq_zero_iff (Y - c.proj H Y)).mp hself have h := hzero r hr have hh : Y r - c.proj H Y r = 0 := h exact (sub_eq_zero.mp hh).symm -
proj_apply_eq_of_mem_orthogonallemma — Projection uniqueness on observed indices.hypothesesc :H :Submodule ℝ (R → ℝ)X :R → ℝY :R → ℝhY :Y ∈ Hhorth :∀ h ∈ H, c.ip (X - Y) h = 0r :Rhr :r ∈ c.observedconclusionc.proj H X r = Y rProof (Lean source)
lemma proj_apply_eq_of_mem_orthogonal (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) {Y : R → ℝ} (hY : Y ∈ H) (horth : ∀ h ∈ H, c.ip (X - Y) h = 0) (r : R) (hr : r ∈ c.observed) : c.proj H X r = Y r := by let W : R → ℝ := Y - c.proj H X have hWmem : W ∈ H := H.sub_mem hY (c.proj_mem H X) have hproj : c.ip (X - c.proj H X) W = 0 := c.proj_orthogonal H X hWmem have hYorth : c.ip (X - Y) W = 0 := horth W hWmem have hdecomp : X - c.proj H X = (X - Y) + W := by ext s simp [W] have hsplit : c.ip (X - c.proj H X) W = c.ip (X - Y) W + c.ip W W := by rw [hdecomp, c.ip_add_left] have hself : c.ip W W = 0 := by rw [hproj, hYorth, zero_add] at hsplit exact hsplit.symm have hzero : ∀ s ∈ c.observed, W s = 0 := (c.ip_self_eq_zero_iff W).mp hself have hrzero : Y r - c.proj H X r = 0 := hzero r hr exact (sub_eq_zero.mp hrzero).symm -
proj_idem_applylemma — Idempotence of the projection on the observed indices.hypothesesconclusionc.proj H (c.proj H X) r = c.proj H X rProof (Lean source)
lemma proj_idem_apply (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) (r : R) (hr : r ∈ c.observed) : c.proj H (c.proj H X) r = c.proj H X r := c.proj_apply_of_mem H (c.proj_mem H X) r hr -
residualize_applylemma — Applying the residual maker subtracts the weighted projection from the original array.hypothesesconclusionc.residualize H X = X - c.proj H XProof (Lean source)
@[simp] lemma residualize_apply (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) : c.residualize H X = X - c.proj H X := by simp [residualize] -
tildeX_eqlemma — The residualized scalar array is the original array minus its weighted projection onto the nuisance subspace.hypothesesconclusionc.tildeX H X = X - c.proj H XProof (Lean source)
@[simp] lemma tildeX_eq (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) : c.tildeX H X = X - c.proj H X := by simp [tildeX] -
residualize_self_of_memlemma — If X ∈ H then X̃ = M_H X vanishes on c.observed.hypothesesconclusionc.tildeX H X r = 0Proof (Lean source)
lemma residualize_self_of_mem (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) {X : R → ℝ} (hX : X ∈ H) (r : R) (hr : r ∈ c.observed) : c.tildeX H X r = 0 := by simp only [tildeX_eq, Pi.sub_apply] rw [c.proj_apply_of_mem H hX r hr] ring -
residualize_idem_applylemma — Idempotence of M_H on the observed indices: M_H (M_H X) = M_H X on c.observed.hypothesesconclusionc.residualize H (c.residualize H X) r = c.residualize H X rProof (Lean source)
lemma residualize_idem_apply (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) (r : R) (hr : r ∈ c.observed) : c.residualize H (c.residualize H X) r = c.residualize H X r := by simp only [residualize_apply, Pi.sub_apply] have hkey : c.proj H (X - c.proj H X) r = 0 := by set Z : R → ℝ := X - c.proj H X set W : R → ℝ := c.proj H Z have hWmem : W ∈ H := c.proj_mem H Z have h1 : c.ip Z W = 0 := c.proj_orthogonal H X hWmem have h2 : c.ip (Z - W) W = 0 := c.proj_orthogonal H Z hWmem have h3 : c.ip W W = 0 := by have hZ : Z = (Z - W) + W := (sub_add_cancel Z W).symm have hsplit : c.ip Z W = c.ip (Z - W) W + c.ip W W := by calc c.ip Z W = c.ip ((Z - W) + W) W := by rw [← hZ] _ = c.ip (Z - W) W + c.ip W W := c.ip_add_left _ _ _ have hsum : c.ip (Z - W) W + c.ip W W = 0 := hsplit ▸ h1 have : c.ip W W = 0 := by have := hsum rw [h2, zero_add] at this exact this exact this have hzero : ∀ s ∈ c.observed, W s = 0 := (c.ip_self_eq_zero_iff W).mp h3 exact hzero r hr change (X - c.proj H X) r - c.proj H (X - c.proj H X) r = (X - c.proj H X) r rw [hkey, sub_zero] -
tildeXVec_applylemma — The residualized vector array applies scalar residualization to the chosen column.hypothesesconclusionc.tildeXVec H X k = c.tildeX H (X k)Proof (Lean source)
@[simp] lemma tildeXVec_apply (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : J → R → ℝ) (k : J) : c.tildeXVec H X k = c.tildeX H (X k) := rfl
AdditiveSpan 4 core · 1 supporting This file defines AdditiveSpan, the linear subspace of finite arrays that decompose additively through two index maps. ★ const_mem
Additive Two-Axis Spans
This file defines AdditiveSpan, the linear subspace of finite arrays that
decompose additively through two index maps. It provides the generic algebra
behind two-way fixed-effect nuisance spaces, the product-index specialization
twoAxisAdditiveSpan, and the unit/time membership predicate
IsUnitTimeAdditive. The main public facts expose membership, constants in the
span, and finite dimensionality over a finite support.
The additive span of two projections f₁ : R → A and f₂ : R → B: the subspace of R → ℝ consisting of arrays h r = a (f₁ r) + b (f₂ r) for some a : A → ℝ and b : B → ℝ.
Definition (Lean source)
The constant function equal to c₀ belongs to the additive span generated by two feature maps f₁ and f₂; it is witnessed by taking the f₁-component function constantly c₀ and the f₂-component function constantly 0.
Formal statement
Proof (Lean source)
The two-axis additive span for the product index R = I × T: specializes AdditiveSpan to f₁ = Prod.fst, f₂ = Prod.snd.
Definition (Lean source)
Predicate for the unit/time additive class h i t = a i + b t.
Definition (Lean source)
1 supporting declaration (lemmas, instances)
-
mem_ifflemma — Membership unfolding for AdditiveSpan.hypothesesh :R → ℝconclusionh ∈ AdditiveSpan f₁ f₂ ↔ ∃ a : A → ℝ, ∃ b : B → ℝ, ∀ r : R, h r = a (f₁ r) + b (f₂ r)Proof (Lean source)
lemma mem_iff {h : R → ℝ} : h ∈ AdditiveSpan f₁ f₂ ↔ ∃ a : A → ℝ, ∃ b : B → ℝ, ∀ r : R, h r = a (f₁ r) + b (f₂ r) := Iff.rfl
FWL 5 core · 6 supporting This file states and proves the finite weighted-support Frisch-Waugh-Lovell identity. ★ fwl_identity
Weighted Frisch-Waugh-Lovell Identity
This file states and proves the finite weighted-support
Frisch-Waugh-Lovell identity. It constructs the residualized Gram matrix
Q_XX, residualized score vector rhsVec, residualized coefficient
thetaHat, and rank condition RankCondition. The lemma
Q_XX_mulVec_thetaHat proves that thetaHat solves the residualized normal
equations, and the theorem fwl_identity proves that any long weighted
least-squares minimizer has coefficient thetaHat after residualizing against
the nuisance space.
Residualized regressor Gram matrix Q_XX = ⟨M_H X, M_H X⟩_ω.
Residualized FWL right-hand side ⟨M_H X, Y⟩_ω.
Definition (Lean source)
Residualized weighted least-squares coefficient θ̂ = Q_XX⁻¹ ⟨M_H X, Y⟩_ω.
Rank condition for the residualized regressors: Q_XX is invertible.
Definition (Lean source)
Frisch–Waugh–Lovell at the WeightedSupport level. Assume the residualized-regressor Gram matrix Q_XX is invertible (the rank condition). Then whenever a coefficient vector β together with a nuisance term α ∈ H jointly minimizes the weighted least-squares objective c.ip (Y − ∑ₖ βₖ·Xₖ − α) (Y − ∑ₖ βₖ·Xₖ − α) over all coefficient/nuisance pairs, β must equal the short-regression residualized coefficient thetaHat c X H Y.
Formal statement
Proof (Lean source)
6 supporting declarations (lemmas, instances)
-
Q_XX_applylemma — Each entry of the residualized Gram matrix is the weighted inner product of the corresponding residualized regressors.hypothesesconclusionQ_XX c X H j k = c.ip (c.tildeX H (X j)) (c.tildeX H (X k))Proof (Lean source)
@[simp] lemma Q_XX_apply (c : WeightedSupport R) (X : Fin K → R → ℝ) (H : Submodule ℝ (R → ℝ)) (j k : Fin K) : Q_XX c X H j k = c.ip (c.tildeX H (X j)) (c.tildeX H (X k)) := rfl -
rhsVec_applylemma — Each entry of the residualized right-hand side is the weighted inner product of a residualized regressor with the outcome.hypothesesconclusionrhsVec c X H Y j = c.ip (c.tildeX H (X j)) YProof (Lean source)
@[simp] lemma rhsVec_apply (c : WeightedSupport R) (X : Fin K → R → ℝ) (H : Submodule ℝ (R → ℝ)) (Y : R → ℝ) (j : Fin K) : rhsVec c X H Y j = c.ip (c.tildeX H (X j)) Y := rfl -
ip_sum_left_finsetlemma — For a weighted inner product, the inner product of a finite sum of functions with another function equals the corresponding finite sum of inner products.hypothesesconclusionc.ip (∑ i ∈ s, f i) B = ∑ i ∈ s, c.ip (f i) BProof (Lean source)
lemma ip_sum_left_finset (c : WeightedSupport R) {ι : Type*} (s : Finset ι) (f : ι → R → ℝ) (B : R → ℝ) : c.ip (∑ i ∈ s, f i) B = ∑ i ∈ s, c.ip (f i) B := by classical induction s using Finset.induction_on with | empty => simp [ip] | insert a s' hk ih => rw [Finset.sum_insert hk, Finset.sum_insert hk, c.ip_add_left, ih] -
ip_sum_rightlemma — The weighted inner product of a function with a finite sum of functions equals the sum of its weighted inner products with the summands.hypothesesconclusionc.ip A (∑ k, f k) = ∑ k, c.ip A (f k)Proof (Lean source)
lemma ip_sum_right (c : WeightedSupport R) (A : R → ℝ) (f : Fin K → R → ℝ) : c.ip A (∑ k, f k) = ∑ k, c.ip A (f k) := by rw [c.ip_symm, c.ip_sum_left] refine Finset.sum_congr rfl ?_ intro k _; exact c.ip_symm _ _ -
ip_tildeX_eq_ip_tildeX_residuallemma — A regressor residualized against a control space has the same weighted inner product with any function as with that function after residualizing it against the same control space.hypothesesconclusionc.ip (c.tildeX H (X k)) A = c.ip (c.tildeX H (X k)) (c.tildeX H A)Proof (Lean source)
lemma ip_tildeX_eq_ip_tildeX_residual (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : Fin K → R → ℝ) (A : R → ℝ) (k : Fin K) : c.ip (c.tildeX H (X k)) A = c.ip (c.tildeX H (X k)) (c.tildeX H A) := by have h1 : c.ip (c.tildeX H (X k)) (c.proj H A) = 0 := by have hsymm := c.ip_symm (c.tildeX H (X k)) (c.proj H A) rw [hsymm] rw [c.ip_symm] exact c.residualize_in_orthogonal H (X k) (c.proj_mem H A) have hAsplit : A = c.tildeX H A + c.proj H A := by simp [tildeX_eq] conv_lhs => rw [hAsplit] rw [c.ip_add_right, h1, add_zero]
IndicatorSpan 7 core · 8 supporting This file provides finite-cell partition algebra over a weighted support. ★ cellMean_mul_cellMass
Indicator spans and partition-cell statistics
This file provides finite-cell partition algebra over a weighted support.
It defines singleton cell indicators cellIndicator, one-axis spans
indicatorSpan, two-axis spans twoAxisIndicatorSpan, and weighted
partition-cell statistics WeightedSupport.cellMass, cellMean, and
jointCellMass.
The declarations are the finite-support interface for nuisance spaces generated by classifier cells and for weighted averages over positive-mass partition cells.
The cell indicator is one on records classified into a given cell and zero elsewhere.
Definition (Lean source)
The one-axis indicator span contains exactly the finite linear combinations of singleton indicators for one classifier.
Definition (Lean source)
The two-axis indicator span contains sums of one-axis indicator functions from two classifiers.
Definition (Lean source)
The cell mass is the total weight of observed records in one classifier cell.
Definition (Lean source)
On a classifier cell with positive observed mass, the cell mean is the ordinary weighted average of the outcome over observed records in that cell.
Definition (Lean source)
On a classifier cell g with strictly positive total weight, multiplying the cell mean of F by the cell's mass recovers the weighted sum of F over observed records in that cell.
Formal statement
Proof (Lean source)
The joint cell mass is the total weight of observed records lying in a given pair of classifier cells.
Definition (Lean source)
8 supporting declarations (lemmas, instances)
-
cellIndicator_applylemma — The cell indicator evaluates by checking whether the record belongs to the chosen classifier cell.hypothesesconclusioncellIndicator G g r = if G r = g then (1 : ℝ) else 0Proof (Lean source)
@[simp] lemma cellIndicator_apply {R 𝒢 : Type*} [DecidableEq 𝒢] (G : R → 𝒢) (g : 𝒢) (r : R) : cellIndicator G g r = if G r = g then (1 : ℝ) else 0 := rfl -
mem_indicatorSpan_ifflemma — Membership in the one-axis indicator span is equivalent to having coefficients on the classifier cells whose weighted sum reproduces the array.hypothesesconclusionf ∈ indicatorSpan G ↔ ∃ c : 𝒢 → ℝ, ∀ r : R, f r = ∑ g, c g * cellIndicator G g rProof (Lean source)
lemma mem_indicatorSpan_iff {R 𝒢 : Type*} [Fintype 𝒢] [DecidableEq 𝒢] (G : R → 𝒢) (f : R → ℝ) : f ∈ indicatorSpan G ↔ ∃ c : 𝒢 → ℝ, ∀ r : R, f r = ∑ g, c g * cellIndicator G g r := Iff.rfl -
cellIndicator_mem_indicatorSpanlemma — Each singleton cell indicator belongs to the span generated by all cells of the same classifier.hypothesesconclusioncellIndicator G g ∈ indicatorSpan GProof (Lean source)
lemma cellIndicator_mem_indicatorSpan {R 𝒢 : Type*} [Fintype 𝒢] [DecidableEq 𝒢] (G : R → 𝒢) (g : 𝒢) : cellIndicator G g ∈ indicatorSpan G := by classical refine ⟨fun g' => if g' = g then (1 : ℝ) else 0, ?_⟩ intro r -- exactly one summand survives (the one with `g' = g`); equals -- `cellIndicator G g r`. have hsum : (∑ g' ∈ (Finset.univ : Finset 𝒢), (if g' = g then (1 : ℝ) else 0) * cellIndicator G g' r) = (if g = g then (1 : ℝ) else 0) * cellIndicator G g r := by refine Finset.sum_eq_single g ?_ ?_ · intro b _ hbne simp [hbne] · intro hnot exact elim (hnot (Finset.mem_univ _)) rw [hsum] simp -
indicatorSpan_le_twoAxisIndicatorSpanlemma — The first classifier's indicator span is contained in the two-axis indicator span.hypothesesconclusionindicatorSpan G ≤ twoAxisIndicatorSpan G TProof (Lean source)
lemma indicatorSpan_le_twoAxisIndicatorSpan {R 𝒢 𝒯 : Type*} [Fintype 𝒢] [DecidableEq 𝒢] [Fintype 𝒯] [DecidableEq 𝒯] (G : R → 𝒢) (T : R → 𝒯) : indicatorSpan G ≤ twoAxisIndicatorSpan G T := le_sup_left -
indicatorSpan_le_twoAxisIndicatorSpan_rightlemma — The second classifier's indicator span is contained in the two-axis indicator span.hypothesesconclusionindicatorSpan T ≤ twoAxisIndicatorSpan G TProof (Lean source)
lemma indicatorSpan_le_twoAxisIndicatorSpan_right {R 𝒢 𝒯 : Type*} [Fintype 𝒢] [DecidableEq 𝒢] [Fintype 𝒯] [DecidableEq 𝒯] (G : R → 𝒢) (T : R → 𝒯) : indicatorSpan T ≤ twoAxisIndicatorSpan G T := le_sup_right -
cellMass_deflemma — The cell mass unfolds to the weighted sum of the corresponding cell indicator over observed records.hypothesesconclusionc.cellMass G g = ∑ r ∈ c.observed, c.weight r * cellIndicator G g rProof (Lean source)
@[simp] lemma cellMass_def {𝒢 : Type*} [DecidableEq 𝒢] (c : WeightedSupport R) (G : R → 𝒢) (g : 𝒢) : c.cellMass G g = ∑ r ∈ c.observed, c.weight r * cellIndicator G g r := rfl -
cellMass_nonneglemma — Every classifier cell has nonnegative total weight.hypothesesconclusion0 ≤ c.cellMass G gProof (Lean source)
lemma cellMass_nonneg {𝒢 : Type*} [DecidableEq 𝒢] (c : WeightedSupport R) (G : R → 𝒢) (g : 𝒢) : 0 ≤ c.cellMass G g := by refine sum_nonneg ?_ intro r hr by_cases h : G r = g · have hw : 0 ≤ c.weight r := (c.weight_pos r hr).le simp [cellIndicator, h, hw] · simp [cellIndicator, h] -
jointCellMass_deflemma — The joint cell mass unfolds to the weighted sum of the two corresponding cell indicators over observed records.hypothesesconclusionc.jointCellMass G T g t= ∑ r ∈ c.observed, c.weight r * cellIndicator G g r * cellIndicator T t rProof (Lean source)
@[simp] lemma jointCellMass_def {𝒢 𝒯 : Type*} [DecidableEq 𝒢] [DecidableEq 𝒯] (c : WeightedSupport R) (G : R → 𝒢) (T : R → 𝒯) (g : 𝒢) (t : 𝒯) : c.jointCellMass G T g t = ∑ r ∈ c.observed, c.weight r * cellIndicator G g r * cellIndicator T t r := rfl
NormalizedWeights 2 core · 5 supporting This file develops paper-agnostic finite-sum algebra for normalized weights, weighted centered covariances, and weighted centered variances. ★ weighted_center_cov
Normalized finite weights and pairwise moment identities
This file develops paper-agnostic finite-sum algebra for normalized weights,
weighted centered covariances, and weighted centered variances. It defines
normalizedWeight, proves the basic nonnegativity and sum-to-one facts
normalizedWeight_nonneg and sum_normalizedWeight_eq_one, and proves the
pairwise formulas weighted_center_cov and weighted_center_var.
These identities are reusable in regression-weight decompositions where a coefficient is re-expressed as a finite weighted sum over cells or cohorts.
Generic normalized finite weight a_i / Σ_k a_k.
Definition (Lean source)
For weights p summing to one over a field where 2 is nonzero, the weighted centered covariance of x and y equals half the average, weighted by p ⊗ p, of the pairwise cross-products of their differences: Σᵢ pᵢ (xᵢ − x̄)(yᵢ − ȳ) = 1/2 Σᵢ Σⱼ pᵢpⱼ (xᵢ − xⱼ)(yᵢ − yⱼ).
Formal statement
Proof (Lean source)
5 supporting declarations (lemmas, instances)
-
normalizedWeight_nonneglemma — Nonnegativity of normalized weights from nonnegative raw weights and a positive normalizing sum.hypothesesK :a :ι → Kha :∀ i, 0 ≤ a ihsum :0 < ∑ i, a ii :ιconclusion0 ≤ normalizedWeight a iProof (Lean source)
lemma normalizedWeight_nonneg {K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (a : ι → K) (ha : ∀ i, 0 ≤ a i) (hsum : 0 < ∑ i, a i) (i : ι) : 0 ≤ normalizedWeight a i := by unfold normalizedWeight exact div_nonneg (ha i) (le_of_lt hsum) -
sum_normalizedWeight_eq_onelemma — Normalized finite weights sum to one when the normalizing sum is nonzero.Proof (Lean source)
lemma sum_normalizedWeight_eq_one {K : Type*} [Field K] (a : ι → K) (hsum : ∑ i, a i ≠ 0) : ∑ i, normalizedWeight a i = 1 := by unfold normalizedWeight rw [← Finset.sum_div] exact div_self hsum -
weighted_center_cov_leftlemma — When finite weights sum to one, the weighted covariance of two centered variables equals their weighted cross-moment minus the product of their weighted means.hypothesesconclusion∑ i, p i * (x i - ∑ j, p j * x j) * (y i - ∑ j, p j * y j)= (∑ i, p i * x i * y i) - (∑ j, p j * x j) * (∑ j, p j * y j)Proof (Lean source)
lemma weighted_center_cov_left {K : Type*} [CommRing K] (p x y : ι → K) (hp : ∑ i, p i = 1) : ∑ i, p i * (x i - ∑ j, p j * x j) * (y i - ∑ j, p j * y j) = (∑ i, p i * x i * y i) - (∑ j, p j * x j) * (∑ j, p j * y j) := by classical let mx := ∑ j, p j * x j let my := ∑ j, p j * y j have hpx : (∑ i, (p i * x i) * my) = mx * my := by dsimp [mx] rw [Finset.sum_mul] have hpy : (∑ i, (p i * y i) * mx) = my * mx := by dsimp [my] rw [Finset.sum_mul] have hpmy : (∑ i : ι, p i * mx * my) = mx * my := by calc (∑ i : ι, p i * mx * my) = ∑ i : ι, p i * (mx * my) := by refine Finset.sum_congr rfl ?_ intro i _hi ring _ = (∑ i : ι, p i) * (mx * my) := by exact (Finset.sum_mul (s := univ) (f := fun i : ι => p i) (a := mx * my)).symm _ = mx * my := by rw [hp] ring calc ∑ i, p i * (x i - ∑ j, p j * x j) * (y i - ∑ j, p j * y j) = ∑ i, (p i * x i * y i - (p i * x i) * my - (p i * y i) * mx + p i * mx * my) := by refine Finset.sum_congr rfl ?_ intro i _hi dsimp [mx, my] ring _ = (∑ i, p i * x i * y i) - (∑ i, (p i * x i) * my) - (∑ i, (p i * y i) * mx) + ∑ i, p i * mx * my := by simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib] _ = (∑ i, p i * x i * y i) - mx * my := by rw [hpx, hpy, hpmy] ring _ = (∑ i, p i * x i * y i) - (∑ j, p j * x j) * (∑ j, p j * y j) := by rfl -
pairwise_cov_rightlemma — When finite weights sum to one, the weighted sum of pairwise products of differences equals twice the weighted cross-moment minus twice the product of the weighted means.hypothesesconclusion(∑ i, ∑ j, p i * p j * (x i - x j) * (y i - y j))= 2 * ((∑ i, p i * x i * y i) - (∑ j, p j * x j) * (∑ j, p j * y j))Proof (Lean source)
lemma pairwise_cov_right {K : Type*} [CommRing K] (p x y : ι → K) (hp : ∑ i, p i = 1) : (∑ i, ∑ j, p i * p j * (x i - x j) * (y i - y j)) = 2 * ((∑ i, p i * x i * y i) - (∑ j, p j * x j) * (∑ j, p j * y j)) := by classical calc (∑ i, ∑ j, p i * p j * (x i - x j) * (y i - y j)) = (∑ i, ∑ j, (((p i * x i * y i) * p j - (p i * x i) * (p j * y j)) - (p i * y i) * (p j * x j) + p i * (p j * x j * y j))) := by refine Finset.sum_congr rfl ?_ intro i _hi refine Finset.sum_congr rfl ?_ intro j _hj ring _ = ((∑ i, p i * x i * y i) * (∑ j, p j)) - ((∑ i, p i * x i) * (∑ j, p j * y j)) - ((∑ i, p i * y i) * (∑ j, p j * x j)) + ((∑ i, p i) * (∑ j, p j * x j * y j)) := by simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib] rw [double_sum_mul (fun i => p i * x i * y i) (fun j => p j)] rw [double_sum_mul (fun i => p i * x i) (fun j => p j * y j)] rw [double_sum_mul (fun i => p i * y i) (fun j => p j * x j)] rw [double_sum_mul (fun i => p i) (fun j => p j * x j * y j)] _ = 2 * ((∑ i, p i * x i * y i) - (∑ j, p j * x j) * (∑ j, p j * y j)) := by rw [hp] ring -
weighted_center_varlemma — Weighted centered variance as half the average pairwise squared gap.hypothesesconclusion∑ i, p i * (x i - ∑ j, p j * x j)^2 = (1 / 2) * ∑ i, ∑ j, p i * p j * (x i - x j)^2Proof (Lean source)
lemma weighted_center_var {K : Type*} [Field K] (p x : ι → K) (hp : ∑ i, p i = 1) (h2 : (2 : K) ≠ 0) : ∑ i, p i * (x i - ∑ j, p j * x j)^2 = (1 / 2) * ∑ i, ∑ j, p i * p j * (x i - x j)^2 := by have h := weighted_center_cov p x x hp h2 calc ∑ i, p i * (x i - ∑ j, p j * x j)^2 = ∑ i, p i * (x i - ∑ j, p j * x j) * (x i - ∑ j, p j * x j) := by refine Finset.sum_congr rfl ?_ intro i _hi ring _ = (1 / 2) * ∑ i, ∑ j, p i * p j * (x i - x j) * (x i - x j) := h _ = (1 / 2) * ∑ i, ∑ j, p i * p j * (x i - x j)^2 := by congr 1 refine Finset.sum_congr rfl ?_ intro i _hi refine Finset.sum_congr rfl ?_ intro j _hj ring
OfProbabilityMeasure 2 core · 1 supporting This file connects the finite weighted-support algebra to probability measures on finite measurable spaces. ★ ip_eq_integral
Weighted supports from probability measures
This file connects the finite weighted-support algebra to probability measures
on finite measurable spaces. The construction ofProbabilityMeasure turns point
masses into a WeightedSupport whose observed set is the positive-mass support,
and ofProbabilityMeasure_weight exposes the resulting atom weights.
The main bridge theorem, ip_eq_integral, identifies the finite weighted inner
product with the corresponding L²(μ) integral pairing. This lets
measure-theoretic cell bridges and finite weighted-support Frisch-Waugh-Lovell
arguments be used interchangeably on a finite probability space.
A probability measure on a finite measurable space induces a weighted support whose weights are point masses and whose observed records have positive mass.
Definition (Lean source)
For a finite probability measure μ, the weighted inner product induced by μ on any two functions A and B equals the L²(μ) integral pairing ∫ A·B dμ.
Formal statement
Proof (Lean source)
1 supporting declaration (lemmas, instances)
-
ofProbabilityMeasure_weightlemma — The induced weighted support assigns each record the point mass of that record under the probability measure.Proof (Lean source)
@[simp] lemma ofProbabilityMeasure_weight (μ : Measure R) [IsProbabilityMeasure μ] (r : R) : (ofProbabilityMeasure μ).weight r = (μ {r}).toReal := rfl
ScalarFWL 1 core · 1 supporting This file proves the single-regressor finite weighted-support Frisch-Waugh-Lovell formula from weighted normal equations. ★ scalar_fwl_of_normalEqs
Scalar Frisch-Waugh-Lovell from normal equations
This file proves the single-regressor finite weighted-support
Frisch-Waugh-Lovell formula from weighted normal equations. The supporting lemma
ip_tildeX_self identifies the residualized regressor's inner product with the
original regressor and with itself. The main theorem
scalar_fwl_of_normalEqs states that any scalar coefficient satisfying the
regressor and nuisance normal equations equals the residualized coefficient
ratio.
The result supplies the normal-equation form needed by downstream estimand-characterization arguments without requiring them to restate a joint least-squares minimization problem.
Scalar FWL from the normal equations. Suppose the nuisance term α lies in H, the H-residualized regressor X̃ has nonzero weighted self-inner-product, and the coefficient β with nuisance term α satisfies the weighted normal equation against the raw regressor X and the weighted normal equation against every element of the nuisance space H. Then β equals the residualized coefficient ratio ⟨X̃, Y⟩_ω / ⟨X̃, X̃⟩_ω.
Formal statement
Proof (Lean source)
1 supporting declaration (lemmas, instances)
-
ip_tildeX_selflemma — ⟨X̃, X⟩_ω = ⟨X̃, X̃⟩_ω: the residualized regressor sees X and its residual identically, because the projection part lies in H and is orthogonal to the residual.hypothesesconclusionc.ip (c.tildeX H X) X = c.ip (c.tildeX H X) (c.tildeX H X)Proof (Lean source)
lemma ip_tildeX_self (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X : R → ℝ) : c.ip (c.tildeX H X) X = c.ip (c.tildeX H X) (c.tildeX H X) := by -- Write `X = tildeX + proj X` only in the *right* slot. have hsplit : X = c.tildeX H X + c.proj H X := by rw [tildeX_eq]; ext r; simp calc c.ip (c.tildeX H X) X = c.ip (c.tildeX H X) (c.tildeX H X + c.proj H X) := by rw [← hsplit] _ = c.ip (c.tildeX H X) (c.tildeX H X) + c.ip (c.tildeX H X) (c.proj H X) := c.ip_add_right _ _ _ _ = c.ip (c.tildeX H X) (c.tildeX H X) := by rw [c.residualize_in_orthogonal H X (c.proj_mem H X), add_zero]
WLS 2 core · 3 supporting This file proves that the semidefinite weighted projection from Causalean.Panel.Weighted.Subspace has the expected least-squares characterization. ★ proj_eq_argmin★ residualize_orth_iff_argmin
Weighted least-squares optimality
This file proves that the semidefinite weighted projection from
Causalean.Panel.Weighted.Subspace has the expected least-squares
characterization. The lemma ip_self_sub_le_of_orth gives the forward
orthogonality-to-optimality implication, and proj_eq_argmin specializes it to
the chosen weighted projection c.proj H X.
The reverse perturbation argument is packaged in residualize_orth_iff_argmin:
for any candidate p ∈ H, residual orthogonality to every direction in H is
equivalent to weighted least-squares optimality. The helper lemmas
ip_eq_zero_of_zero_on_observed and ip_sub_smul_expand handle the
semidefinite zero-energy case and the quadratic expansion used in that proof.
The weighted orthogonal projection minimizes the WLS objective over H. Given a weighted support on a finite index set and a submodule H of candidate real-valued functions, for any competitor h lying in H, the weighted sum of squared residuals of the projection of a target function onto H is at most the weighted sum of squared residuals of h.
Formal statement
Proof (Lean source)
First-order WLS optimality. For a weighted support and a submodule H of candidate functions, fix a candidate function p belonging to H; then the residual X - p being weighted-orthogonal to every element of H is equivalent to p attaining the minimal weighted sum of squared residuals over H.
Formal statement
Proof (Lean source)
3 supporting declarations (lemmas, instances)
-
ip_self_sub_le_of_orthlemma — If p ∈ H and the residual X - p is c.ip-orthogonal to all of H, then p minimizes the WLS objective over H.hypothesesc :H :Submodule ℝ (R → ℝ)X p :R → ℝhp :p ∈ Hhorth :∀ h ∈ H, c.ip (X - p) h = 0h :R → ℝhh :h ∈ Hconclusionc.ip (X - p) (X - p) ≤ c.ip (X - h) (X - h)Proof (Lean source)
lemma ip_self_sub_le_of_orth (c : WeightedSupport R) (H : Submodule ℝ (R → ℝ)) (X p : R → ℝ) (hp : p ∈ H) (horth : ∀ h ∈ H, c.ip (X - p) h = 0) {h : R → ℝ} (hh : h ∈ H) : c.ip (X - p) (X - p) ≤ c.ip (X - h) (X - h) := by -- `X - h = (X - p) + (p - h)`. have hph : p - h ∈ H := H.sub_mem hp hh have hdecomp : X - h = (X - p) + (p - h) := by ext s; simp [sub_eq_add_neg] -- Expand the inner product via bilinearity. have hcross : c.ip (X - p) (p - h) = 0 := horth (p - h) hph have hexpand : c.ip (X - h) (X - h) = c.ip (X - p) (X - p) + c.ip (p - h) (p - h) := by -- `⟨(X-p)+(p-h), (X-p)+(p-h)⟩ -- = ⟨X-p, X-p⟩ + ⟨X-p, p-h⟩ + ⟨p-h, X-p⟩ + ⟨p-h, p-h⟩`. rw [hdecomp, c.ip_add_left, c.ip_add_right, c.ip_add_right] have hsymm : c.ip (p - h) (X - p) = c.ip (X - p) (p - h) := c.ip_symm _ _ rw [hsymm, hcross]; ring -- `⟨p - h, p - h⟩ ≥ 0`. have hpos : 0 ≤ c.ip (p - h) (p - h) := c.ip_self_nonneg (p - h) linarith -
ip_eq_zero_of_zero_on_observedlemma — If h vanishes on every observed index, then c.ip A h = 0 for any A.Proof (Lean source)
lemma ip_eq_zero_of_zero_on_observed (c : WeightedSupport R) (A h : R → ℝ) (hh : ∀ r ∈ c.observed, h r = 0) : c.ip A h = 0 := by unfold ip refine Finset.sum_eq_zero ?_ intro r hr rw [hh r hr]; ring -
ip_sub_smul_expandlemma — Quadratic-in-t expansion used in the perturbation argument: ⟨X - p - t • h, X - p - t • h⟩_ω = ⟨X-p, X-p⟩_ω - 2 t · ⟨X-p, h⟩_ω + t² · ⟨h, h⟩_ω.hypothesesconclusionc.ip (X - p - t • h) (X - p - t • h)= c.ip (X - p) (X - p) - 2 * t * c.ip (X - p) h + t^2 * c.ip h hProof (Lean source)
lemma ip_sub_smul_expand (c : WeightedSupport R) (X p h : R → ℝ) (t : ℝ) : c.ip (X - p - t • h) (X - p - t • h) = c.ip (X - p) (X - p) - 2 * t * c.ip (X - p) h + t^2 * c.ip h h := by have hsub : X - p - t • h = (X - p) + (- (t • h)) := by ext s; simp [sub_eq_add_neg] rw [hsub] rw [c.ip_add_left, c.ip_add_right, c.ip_add_right] have hneg : -(t • h) = (-t) • h := by ext s; simp have h1 : c.ip (X - p) (-(t • h)) = - (t * c.ip (X - p) h) := by rw [hneg, c.ip_smul_right]; ring have h2 : c.ip (-(t • h)) (X - p) = - (t * c.ip (X - p) h) := by rw [c.ip_symm]; exact h1 have h3 : c.ip (-(t • h)) (-(t • h)) = t^2 * c.ip h h := by rw [hneg, c.ip_smul_left, c.ip_smul_right]; ring rw [h1, h2, h3]; ring