Panel
Panel-data causal econometrics: adoption paths, cell-level potential outcomes, fixed effects, residualization and weighted-regression infrastructure, and estimand-characterization results for DiD, event-study, and TWFE designs.
Cells 3 core · 1 supporting This file provides the observed-cell substrate for panel regressions: a finite set of observed unit-period cells with strictly positive normalized weights. ★ balanced_weight
Observed Panel Cells
This file provides the observed-cell substrate for panel regressions: a finite set of observed unit-period cells with strictly positive normalized weights. It specializes the generic weighted-support infrastructure to panel cell indices and supplies the balanced-panel constructor. It mirrors Definition 2.1 of the projection note.
Relation to Causalean.Panel.CellBridge. Both files use the word cell,
but for different objects. Here a cell is a discrete index r = (i, t) ∈ I × T
carrying a positive normalized weight — a finite-weighted-support object with no
measure theory. In CellBridge a cell is a measurable level set
{ω | G ω = g} of an observable map on a probability space. The two share no
declarations and neither imports the other; the only common substrate is
Causalean.Panel.Weighted.IndicatorSpan.
For finite sets of units and periods with decidable equality, the observed cells of a panel are a finite collection of unit-period pairs equipped with strictly positive weights that sum to one over that collection.
Definition (Lean source)
The balanced panel: every cell is observed and every cell carries weight 1 / (|I| · |T|).
Definition (Lean source)
For any unit-period cell r, the balanced panel design assigns it weight equal to one divided by the total number of unit-period cells.
Formal statement
1 supporting declaration (lemmas, instances)
InnerProduct 3 core · 15 supporting This file provides the panel-facing import point for weighted inner products on observed cell arrays. ★ ip_self_eq_zero_iff
Panel Inner Products
This file provides the panel-facing import point for weighted inner products on
observed cell arrays. It restates the generic weighted-support inner-product
operations and algebraic lemmas under the panel cell namespace, including the
scalar aliases Cells.ip, Cells.ip_eq_weighted, the matrix-valued aliases
Cells.ipMat, Cells.ipMat_eq_weighted, and the symmetry, additivity,
homogeneity, nonnegativity, vanishing, and transpose lemmas used by panel
projection proofs.
Bare-name alias for c.ip. Defined with the explicit finset-sum body (same as WeightedSupport.ip) so that unfold ip exposes the sum form expected by the pre-refactor proof scripts. Definitionally equal (by rfl) to Causalean.Panel.Weighted.WeightedSupport.ip.
Definition (Lean source)
Bare-name alias for the matrix-valued panel inner product. Its (j, k) entry is the scalar weighted inner product of the jth array in A with the kth array in B.
For a panel cell structure and a panel array A, the self inner product c.ip A A is zero exactly when A vanishes on every observed cell of c.
Formal statement
Proof (Lean source)
15 supporting declarations (lemmas, instances)
-
ip_deflemma — The panel weighted inner product unfolds to the weighted sum over observed unit-period cells.hypothesesconclusionc.ip A B = ∑ r ∈ c.observed, c.weight r * A r * B r -
ip_symmlemma — The panel weighted inner product is symmetric in its two arrays.hypothesesconclusionc.ip A B = c.ip B A -
ip_add_leftlemma — The panel weighted inner product is additive in its left array.hypothesesconclusionc.ip (A + A') B = c.ip A B + c.ip A' BProof (Lean source)
lemma ip_add_left (c : Cells I T) (A A' B : (I × T) → ℝ) : c.ip (A + A') B = c.ip A B + c.ip A' B := ip_add_left c A A' B -
ip_add_rightlemma — The panel weighted inner product is additive in its right array.hypothesesconclusionc.ip A (B + B') = c.ip A B + c.ip A B'Proof (Lean source)
lemma ip_add_right (c : Cells I T) (A B B' : (I × T) → ℝ) : c.ip A (B + B') = c.ip A B + c.ip A B' := ip_add_right c A B B' -
ip_smul_leftlemma — The panel weighted inner product is homogeneous in its left array.hypothesesconclusionc.ip (s • A) B = s * c.ip A BProof (Lean source)
lemma ip_smul_left (c : Cells I T) (s : ℝ) (A B : (I × T) → ℝ) : c.ip (s • A) B = s * c.ip A B := ip_smul_left c s A B -
ip_smul_rightlemma — The panel weighted inner product is homogeneous in its right array.hypothesesconclusionc.ip A (s • B) = s * c.ip A BProof (Lean source)
lemma ip_smul_right (c : Cells I T) (s : ℝ) (A B : (I × T) → ℝ) : c.ip A (s • B) = s * c.ip A B := ip_smul_right c s A B -
ip_self_nonneglemma — The self inner product of any panel array is nonnegative.hypothesesconclusion0 ≤ c.ip A AProof (Lean source)
lemma ip_self_nonneg (c : Cells I T) (A : (I × T) → ℝ) : 0 ≤ c.ip A A := ip_self_nonneg c A -
ipMat_transposelemma — Swapping the two tuples of arrays transposes the matrix-valued panel inner product.hypothesesconclusion(c.ipMat A B).transpose = c.ipMat B AProof (Lean source)
lemma ipMat_transpose (c : Cells I T) (A B : Fin K → (I × T) → ℝ) : (c.ipMat A B).transpose = c.ipMat B A := ipMat_transpose c A B -
ipMat_add_leftlemma — The matrix-valued panel inner product is additive in its left tuple of arrays.hypothesesconclusionc.ipMat (A + A') B = c.ipMat A B + c.ipMat A' BProof (Lean source)
lemma ipMat_add_left (c : Cells I T) (A A' B : Fin K → (I × T) → ℝ) : c.ipMat (A + A') B = c.ipMat A B + c.ipMat A' B := ipMat_add_left c A A' B -
ipMat_add_rightlemma — The matrix-valued panel inner product is additive in its right tuple of arrays.hypothesesconclusionc.ipMat A (B + B') = c.ipMat A B + c.ipMat A B'Proof (Lean source)
lemma ipMat_add_right (c : Cells I T) (A B B' : Fin K → (I × T) → ℝ) : c.ipMat A (B + B') = c.ipMat A B + c.ipMat A B' := ipMat_add_right c A B B' -
ipMat_smul_leftlemma — The matrix-valued panel inner product is homogeneous in its left tuple of arrays.hypothesesconclusionc.ipMat (s • A) B = s • c.ipMat A BProof (Lean source)
lemma ipMat_smul_left (c : Cells I T) (s : ℝ) (A B : Fin K → (I × T) → ℝ) : c.ipMat (s • A) B = s • c.ipMat A B := ipMat_smul_left c s A B -
ipMat_smul_rightlemma — The matrix-valued panel inner product is homogeneous in its right tuple of arrays.hypothesesconclusionc.ipMat A (s • B) = s • c.ipMat A BProof (Lean source)
lemma ipMat_smul_right (c : Cells I T) (s : ℝ) (A B : Fin K → (I × T) → ℝ) : c.ipMat A (s • B) = s • c.ipMat A B := ipMat_smul_right c s A B
WeightedTwoWayPanel 11 core · 9 supporting Paper-agnostic finite-sum infrastructure for two-way panels under a general unit weight p : Unit → ℝ (a pmf: ∑ p = 1, 0 < p i) with a uniform period measure. ★ ddot_orthogonal_unit_time★ ddot_eq_residualize
Weighted Finite Two-Way Panel Helpers
Paper-agnostic finite-sum infrastructure for two-way panels under a general
unit weight p : Unit → ℝ (a pmf: ∑ p = 1, 0 < p i) with a uniform period
measure. This is the share-weighted generalization of the uniform two-way panel
algebra used by the estimand-characterization modules:
- uniform balanced panels recover the old
UniformTwoWayPanelbyp ≡ 1/|Unit|; - Goodman-Bacon cohort-share panels take
p = cohort shares.
It provides the p-weighted unit/time/grand means, double demeaning (ddot), the
p-weighted inner product, the unit/time additive nuisance class, the
reconstruction identity, and the share-weighted orthogonality theorems
(ddot ⟂ unit / time / additive).
Bridge to the generic WeightedSupport FWL tower
The closed forms above are connected to the abstract Frisch–Waugh–Lovell
substrate in Causalean/Panel/Weighted/ by the Bridge section: the panel is the
cell support R = Unit × Time with weight ω_{(i,t)} = p_i / |Time|
(cellSupport), the p-weighted inner product is |Time| times
WeightedSupport.ip (inner_eq_card_smul_ip), and ddot is the generic residual
maker against the two-axis additive span (ddot_eq_residualize). The abstract
FWL coefficient lemma Weighted.WeightedSupport.scalar_fwl_of_normalEqs is thus
reusable through the bridge.
Unit weights. A weight function p assigning each unit a share that forms a probability vector: every unit's weight is strictly positive and the weights sum to one across units.
Definition (Lean source)
For a set of units, a finite set of periods, a panel array indexed by units and periods, and a unit, the unit mean is the arithmetic average of that unit's values over all periods.
Definition (Lean source)
For a finite set of units, a set of periods, unit weights that are strictly positive and sum to one, a panel array indexed by units and periods, and a period, the weighted time mean is the weighted average across units of the array at that period.
Definition (Lean source)
For a finite set of units, a finite set of periods, unit weights that are strictly positive and sum to one, and a panel array indexed by units and periods, the weighted grand mean is the weighted average across units of their arithmetic means over periods.
Definition (Lean source)
For a finite set of units, a finite set of periods, unit weights that are strictly positive and sum to one, a panel array indexed by units and periods, a unit, and a period, the double-demeaned value is that array value minus its unit mean and weighted time mean plus its weighted grand mean.
Definition (Lean source)
For a finite set of units, a finite set of periods, unit weights that are strictly positive and sum to one, and two panel arrays, the weighted panel inner product is the sum over every unit and period of the unit weight times the product of the arrays; no uniform-period normalizing factor is included.
Definition (Lean source)
For a set of units, a set of periods, and a panel array indexed by units and periods, the unit-time additive property holds exactly when there exist a real-valued unit-specific function and a real-valued time-specific function whose sum equals the array at every unit-period pair.
Definition (Lean source)
For a finite set of units, a finite set of periods, unit weights that are strictly positive and sum to one, a panel array indexed by units and periods, a unit, and a period, the unit-time component removed by double demeaning is the unit mean plus the weighted time mean minus the weighted grand mean.
Definition (Lean source)
Double-demeaned arrays are orthogonal to every unit/time additive nuisance function. For a probability-weighted panel of units and periods, any array that decomposes as the sum of a unit-specific term and a time-specific term is orthogonal, under the p-weighted inner product, to the double-demeaned residual of any panel array V: their weighted inner product is zero.
Formal statement
Proof (Lean source)
For finite, nonempty, distinguishable sets of units and periods and unit weights that are strictly positive and sum to one, the cell-indexed weighted support for the panel treats every unit-period pair as observed and assigns pair the weight given by unit 's weight divided by the number of periods.
Definition (Lean source)
Concrete ↔ abstract bridge. For unit weights w and an outcome array V, the closed-form two-way double-demeaned residual ddot w V i t equals the generic weighted-support residual against the two-axis additive span, evaluated at cell (i, t). Every cell is observed, so the identity holds pointwise.
Formal statement
Proof (Lean source)
9 supporting declarations (lemmas, instances)
-
ddot_reconstructtheorem — Reconstruction identity V_it = ddot V_it + unitMean + timeMean - grandMean.hypothesesUnit :sharedType u_1Time :sharedType u_2w :UnitWeights UnitV :Unit → Time → ℝi :Unitt :Timeconclusionddot w V i t + unitMean V i + timeMean w V t - grandMean w V = V i tProof (Lean source)
theorem ddot_reconstruct (w : UnitWeights Unit) (V : Unit → Time → ℝ) (i : Unit) (t : Time) : ddot w V i t + unitMean V i + timeMean w V t - grandMean w V = V i t := by unfold ddot ring -
unitTimeProjection_additivetheorem — The removed component is itself unit/time additive.hypothesesconclusionIsUnitTimeAdditive (unitTimeProjection w V)Proof (Lean source)
theorem unitTimeProjection_additive (w : UnitWeights Unit) (V : Unit → Time → ℝ) : IsUnitTimeAdditive (unitTimeProjection w V) := by refine ⟨unitMean V, fun t => timeMean w V t - grandMean w V, ?_⟩ intro i t unfold unitTimeProjection ring -
sub_ddot_eq_unitTimeProjectiontheorem — Pointwise residual decomposition V - ddot V into the unit/time projection.hypothesesUnit :sharedType u_1Time :sharedType u_2w :UnitWeights UnitV :Unit → Time → ℝi :Unitt :TimeconclusionV i t - ddot w V i t = unitTimeProjection w V i tProof (Lean source)
theorem sub_ddot_eq_unitTimeProjection (w : UnitWeights Unit) (V : Unit → Time → ℝ) (i : Unit) (t : Time) : V i t - ddot w V i t = unitTimeProjection w V i t := by unfold ddot unitTimeProjection ring -
ddot_orthogonal_unittheorem — Double-demeaned arrays are orthogonal (in the p-weighted inner product) to arbitrary unit-only functions.hypothesesconclusion∑ i, ∑ t, w.p i * (ddot w V i t * a i) = 0Proof (Lean source)
theorem ddot_orthogonal_unit (w : UnitWeights Unit) (V : Unit → Time → ℝ) (a : Unit → ℝ) : ∑ i, ∑ t, w.p i * (ddot w V i t * a i) = 0 := by classical cases isEmpty_or_nonempty Time with | inl h => letI : IsEmpty Time := h simp | inr h => letI : Nonempty Time := h exact ddot_orthogonal_unit_of_card_ne_zero w (by positivity) V a -
ddot_orthogonal_timetheorem — Double-demeaned arrays are orthogonal (in the p-weighted inner product) to arbitrary time-only functions: ∑_i ∑_t p_i · ddot V_{it} · b_t = 0. Per-period the p-weighted unit sum of ddot vanishes (∑ p = 1 cancels the time mean against the grand mean).hypothesesconclusion∑ i, ∑ t, w.p i * (ddot w V i t * b t) = 0Proof (Lean source)
theorem ddot_orthogonal_time (w : UnitWeights Unit) (V : Unit → Time → ℝ) (b : Time → ℝ) : ∑ i, ∑ t, w.p i * (ddot w V i t * b t) = 0 := by classical have hcol : ∀ t, ∑ i, w.p i * ddot w V i t = 0 := by intro t calc ∑ i, w.p i * ddot w V i t = ∑ i, (w.p i * V i t - w.p i * unitMean V i - w.p i * timeMean w V t + w.p i * grandMean w V) := by apply Finset.sum_congr rfl intro i _hi unfold ddot ring _ = ∑ i, w.p i * V i t - ∑ i, w.p i * unitMean V i - (∑ i, w.p i) * timeMean w V t + (∑ i, w.p i) * grandMean w V := by simp only [sum_algebra_simps] _ = 0 := by rw [w.sum_one] unfold timeMean grandMean ring calc ∑ i, ∑ t, w.p i * (ddot w V i t * b t) = ∑ t, (∑ i, w.p i * ddot w V i t) * b t := by rw [Finset.sum_comm] apply Finset.sum_congr rfl intro t _ht calc ∑ i, w.p i * (ddot w V i t * b t) = ∑ i, (w.p i * ddot w V i t) * b t := by apply Finset.sum_congr rfl intro i _hi ring _ = (∑ i, w.p i * ddot w V i t) * b t := by simp only [sum_algebra_simps] _ = 0 := by simp [hcol] -
cellSupport_weightlemma — The cell-support bridge assigns each unit-period cell its unit weight divided equally across periods.hypothesesconclusion(cellSupport w).weight r = w.p r.1 / (Fintype.card Time : ℝ)Proof (Lean source)
@[simp] lemma cellSupport_weight (w : UnitWeights Unit) (r : Unit × Time) : (cellSupport w).weight r = w.p r.1 / (Fintype.card Time : ℝ) := rfl -
cellSupport_observedlemma — Every unit-period cell is observed in the cell-support bridge.hypothesesProof (Lean source)
@[simp] lemma cellSupport_observed (w : UnitWeights Unit) : (cellSupport w).observed = (Finset.univ : Finset (Unit × Time)) := rfl -
mem_twoAxisAdditiveSpan_ifflemma — Membership in the two-axis additive span is exactly the panel's IsUnitTimeAdditive predicate after uncurrying.hypothesesUnit :sharedType u_1Time :sharedType u_2Unit × Time → ℝconclusionh ∈ twoAxisAdditiveSpan Unit Time ↔ IsUnitTimeAdditive (fun i t => h (i, t))Proof (Lean source)
lemma mem_twoAxisAdditiveSpan_iff {h : Unit × Time → ℝ} : h ∈ twoAxisAdditiveSpan Unit Time ↔ IsUnitTimeAdditive (fun i t => h (i, t)) := by unfold twoAxisAdditiveSpan IsUnitTimeAdditive rw [AdditiveSpan.mem_iff] constructor · rintro ⟨a, b, hab⟩ exact ⟨a, b, fun i t => hab (i, t)⟩ · rintro ⟨a, b, hab⟩ refine ⟨a, b, ?_⟩ intro r simpa using hab r.1 r.2 -
inner_eq_card_smul_iptheorem — The p-weighted panel inner product is |Time| times the generic weighted-support inner product on the cell support.hypothesesconclusioninner w V W= (Fintype.card Time : ℝ) * (cellSupport w).ip (fun r => V r.1 r.2) (fun r => W r.1 r.2)Proof (Lean source)
theorem inner_eq_card_smul_ip (w : UnitWeights Unit) (V W : Unit → Time → ℝ) : inner w V W = (Fintype.card Time : ℝ) * (cellSupport w).ip (fun r => V r.1 r.2) (fun r => W r.1 r.2) := by have hT : (Fintype.card Time : ℝ) ≠ 0 := by have h := Fintype.card_pos (α := Time) exact_mod_cast h.ne' simp only [inner, WeightedSupport.ip_def, cellSupport_observed, cellSupport_weight] rw [Fintype.sum_prod_type] simp only [sum_algebra_simps] refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun t _ => ?_ field_simp
AdoptionPath 9 core · 9 supporting This file provides finite-period adoption-path predicates for staggered-treatment designs, including eventual treatment, never treatment, and whether adoption has occurred by a period. ★ absorbingTreatment_eq
Adoption Path Helpers
This file provides finite-period adoption-path predicates for staggered-treatment designs, including eventual treatment, never treatment, and whether adoption has occurred by a period. The never-treated path is represented as an infinite adoption date, so absorbing treatment remains zero in every finite period for such units.
These paper-agnostic helpers are shared by staggered-adoption modules: Sun-Abraham path helpers wrap these declarations, and Goodman-Bacon uses the same raw infinite-date encoding for proof stability.
For a panel with a finite horizon of periods and a finite adoption period , the finite adoption path is the path whose adoption date is , rather than the never-treated date.
For a finite-period horizon, an adoption path , and a period in that horizon, the treated-by- predicate holds exactly when the adoption date is no later than .
For a finite-period horizon, an adoption path , and a period in that horizon, the untreated-at- predicate holds exactly when is strictly before the adoption date.
For a finite-period horizon and an adoption path , the finite-path predicate holds exactly when its adoption date is not the never-treated date.
For a finite-period horizon and an adoption path , the infinite-path predicate holds exactly when its adoption date is the never-treated date.
For a finite-period horizon and an adoption path , the never-treated predicate holds exactly when has the never-treated adoption date.
Definition (Lean source)
For a finite-period horizon and an adoption path , the eventually-treated predicate holds exactly when has a finite adoption date.
For a finite-period horizon, an adoption path , and a period in that horizon, the absorbing treatment indicator equals one exactly when has adopted by , and equals zero otherwise.
For an adoption date h and period t within a horizon of T periods, the absorbing treatment indicator equals one exactly when adoption has occurred by that period, and zero otherwise.
Formal statement
9 supporting declarations (lemmas, instances)
-
finite_eqtheorem — Embedding a finite adoption period into the shared adoption-path type is definitionally the ordinary finite-period inclusion. -
le_eqtheorem — The treated-by-period predicate is exactly the order comparison with the finite period viewed as an adoption date. -
lt_eqtheorem — The untreated-before-adoption predicate is exactly the strict order comparison with the finite period viewed as an adoption date. -
isInfinite_eqtheorem — A path is never treated exactly when its adoption date is infinite.Proof (Lean source)
-
isNeverTreated_eqtheorem — The Sun-Abraham-compatible never-treated name is the infinite adoption-date predicate.Proof (Lean source)
-
isEventuallyTreated_eqtheorem — The Sun-Abraham-compatible eventually-treated name is the finite adoption-date predicate.Proof (Lean source)
@[simp] theorem isEventuallyTreated_eq {T : ℕ} (h : WithTop (Fin T)) : isEventuallyTreated h = (h ≠ ⊤) := rfl -
lt_of_isInfinitetheorem — Never-treated paths are untreated in every finite period.Proof (Lean source)
theorem lt_of_isInfinite {T : ℕ} {a : WithTop (Fin T)} {t : Fin T} (ha : isInfinite a) : lt a t := AdoptionDate.lt_of_isInf ha
CellBridge 10 core · 6 supporting Provides measure-theoretic finite-cell bridge infrastructure for panel estimand characterizations. ★ integral_mul_twoAxisIndicatorSpan_eq_zero_of_axes
Provides measure-theoretic finite-cell bridge infrastructure for panel estimand characterizations. It defines cell indicators, indicator spans, cell masses, and finite-partition integral lemmas for observable cell maps.
For a collection of records, a set of cell labels with decidable equality, a cell map , and a cell label , the finite-cell indicator is the real-valued function that equals one for records assigned label and zero for all other records.
Definition (Lean source)
For a collection of records, a cell map , and a finite set of cell labels with decidable equality, the finite one-axis indicator span is the real vector space generated by the indicators of the cells of .
Definition (Lean source)
For a collection of records, cell maps and , and their finite label sets with decidable equality, the finite two-axis indicator span is the real vector space generated jointly by the indicators of the cells of and of .
Definition (Lean source)
For a sample space equipped with a σ-algebra, a set of cell labels, a cell-assignment map , and a cell label , the cell indicator is the real-valued function equal to one exactly on the event that equals , and zero elsewhere.
Definition (Lean source)
For a measurable sample space, a finite cell-label set with decidable equality and measurable singleton events, a finite measure , a measurable cell-assignment map , the one-axis indicator span is the class of square-integrable real functions that agree almost everywhere with a finite linear combination of the indicators of the cells of .
Definition (Lean source)
For a measurable sample space, finite cell-label sets with decidable equality and measurable singleton events, a finite measure , and measurable cell-assignment maps and , the two-axis indicator span is the class of square-integrable real functions that agree almost everywhere with the sum of a finite linear combination of -cell indicators and a finite linear combination of -cell indicators.
Definition (Lean source)
For a sample space equipped with a σ-algebra, a set of cell labels, a measure , a cell-assignment map , and a cell label , the cell mass is the real-valued mass that assigns to the event that equals .
Definition (Lean source)
For a sample space equipped with a σ-algebra, sets of labels for two cell maps, a measure , cell-assignment maps and , and labels and , the joint cell mass is the real-valued mass that assigns to the event that and .
Definition (Lean source)
For a sample space equipped with a σ-algebra, a set of cell labels, a measure , a real-valued function , a cell-assignment map , and a cell label , the cell mean is the integral of over the event , divided by that event's real-valued mass.
Definition (Lean source)
If a square-integrable residual V is orthogonal in expectation to the indicator of every level g of one axis G and orthogonal in expectation to the indicator of every level t of the other axis T, then it is orthogonal in expectation to every finite linear combination of those axis indicators, with coefficients cG and cT.
Formal statement
Proof (Lean source)
6 supporting declarations (lemmas, instances)
-
indicator_cell_memLptheorem — Cell indicators are in L² under a finite measure.hypothesesΩ 𝒢 :μ :G :Ω → 𝒢G_meas :g :𝒢Proof (Lean source)
theorem indicator_cell_memLp {Ω 𝒢 : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒢] [MeasurableSingletonClass 𝒢] (μ : Measure Ω) [IsFiniteMeasure μ] (G : Ω → 𝒢) (G_meas : Measurable G) (g : 𝒢) : MemLp (fun ω => indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) 2 μ := by let s : Set Ω := G ⁻¹' ({g} : Set 𝒢) have hMeas : MeasurableSet s := G_meas (measurableSet_singleton g) change MemLp (fun ω => indicator s (fun _ => (1 : ℝ)) ω) 2 μ exact (memLp_const (μ := μ) (1 : ℝ)).indicator hMeas -
integral_cell_indicator_one_eq_cellMasstheorem — Cell indicators integrate to their real cell mass.hypothesesconclusion∫ ω, indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ = cellMass μ G gProof (Lean source)
theorem integral_cell_indicator_one_eq_cellMass {Ω 𝒢 : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒢] [MeasurableSingletonClass 𝒢] (μ : Measure Ω) (G : Ω → 𝒢) (G_meas : Measurable G) (g : 𝒢) : ∫ ω, indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ = cellMass μ G g := by let s : Set Ω := {ω | G ω = g} have hs_meas : MeasurableSet s := G_meas (measurableSet_singleton g) change (∫ ω, indicator s (1 : Ω → ℝ) ω ∂μ) = cellMass μ G g rw [MeasureTheory.integral_indicator_one hs_meas] simp [Measure.real, cellMass, s] -
cell_integral_div_mul_cellMasstheorem — Dividing an indicator-weighted cell integral by a nonzero cell mass and multiplying back recovers the numerator; on zero-mass cells the numerator is zero because the indicator is a.e. zero.hypothesesProof (Lean source)
theorem cell_integral_div_mul_cellMass {Ω 𝒢 : Type*} [MeasurableSpace Ω] (μ : Measure Ω) (F : Ω → ℝ) (G : Ω → 𝒢) (g : 𝒢) (hμ : μ {ω | G ω = g} ≠ ⊤) : ((∫ ω, F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ) / cellMass μ G g) * cellMass μ G g = ∫ ω, F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ := by let s : Set Ω := {ω | G ω = g} let A : ℝ := ∫ ω, F ω * indicator s (fun _ => (1 : ℝ)) ω ∂μ have hs_top : μ s ≠ ⊤ := by simpa [s] using hμ by_cases hmass : cellMass μ G g = 0 · have hs_zero : μ s = 0 := by have hzero : (μ s).toReal = 0 := by simpa [cellMass, s] using hmass rcases (ENNReal.toReal_eq_zero_iff (μ s)).1 hzero with h0 | htop · exact h0 · exact elim (hs_top htop) have h_not_mem : ∀ᵐ ω ∂μ, ω ∉ s := by rw [MeasureTheory.ae_iff] simpa using hs_zero have h_ae : (fun ω => F ω * indicator s (fun _ => (1 : ℝ)) ω) =ᵐ[μ] 0 := by filter_upwards [h_not_mem] with ω hω simp [indicator, hω] have hA : A = 0 := by simpa [A] using (integral_eq_zero_of_ae h_ae) simp [cellMass, s, A, hA] · have hAdef : A = ∫ ω, F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ := by simp [A, s] rw [hAdef.symm] field_simp [hmass] -
cellMean_mul_cellMasstheorem — Cell mean multiplied by cell mass recovers the indicator-weighted raw integral.hypothesesconclusioncellMean μ F G g * cellMass μ G g= ∫ ω, F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μProof (Lean source)
theorem cellMean_mul_cellMass {Ω 𝒢 : Type*} [MeasurableSpace Ω] (μ : Measure Ω) (F : Ω → ℝ) (G : Ω → 𝒢) (g : 𝒢) (hμ : μ {ω | G ω = g} ≠ ⊤) : cellMean μ F G g * cellMass μ G g = ∫ ω, F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ := by simpa [cellMean] using cell_integral_div_mul_cellMass μ F G g hμ -
integral_mul_indicatorSpan_eq_zero_of_celltheorem — If a square-integrable residual is orthogonal to every cell indicator, it is orthogonal to every finite indicator-span member.hypothesesΩ 𝒢 :μ :V :Ω → ℝG :Ω → 𝒢G_meas :V_memLp :MemLp V 2 μc :𝒢 → ℝhcell :∀ g, ∫ ω, V ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ = 0conclusion∫ ω, V ω * (∑ g, c g * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) ∂μ = 0Proof (Lean source)
theorem integral_mul_indicatorSpan_eq_zero_of_cell {Ω 𝒢 : Type*} [MeasurableSpace Ω] [Fintype 𝒢] [MeasurableSpace 𝒢] [MeasurableSingletonClass 𝒢] (μ : Measure Ω) [IsFiniteMeasure μ] (V : Ω → ℝ) (G : Ω → 𝒢) (G_meas : Measurable G) (V_memLp : MemLp V 2 μ) (c : 𝒢 → ℝ) (hcell : ∀ g, ∫ ω, V ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ = 0) : ∫ ω, V ω * (∑ g, c g * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) ∂μ = 0 := by classical let term : 𝒢 → Ω → ℝ := fun g ω => V ω * (c g * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) have hterm_int : ∀ g ∈ (Finset.univ : Finset 𝒢), Integrable (term g) μ := by intro g _ have hI : MemLp (fun ω => indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) 2 μ := indicator_cell_memLp μ G G_meas g have hcI : MemLp (fun ω => c g * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) 2 μ := by simpa [mul_comm] using hI.const_mul (c g) exact V_memLp.integrable_mul hcI have hpoint : (fun ω => V ω * (∑ g, c g * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω)) = (fun ω => ∑ g, term g ω) := by funext ω simp [term, Finset.mul_sum] calc ∫ ω, V ω * (∑ g, c g * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) ∂μ = ∫ ω, ∑ g, term g ω ∂μ := by rw [hpoint] _ = ∑ g, ∫ ω, term g ω ∂μ := by simpa using (MeasureTheory.integral_finset_sum (Finset.univ : Finset 𝒢) (f := term) hterm_int) _ = 0 := by refine Finset.sum_eq_zero (fun g _ => ?_) calc ∫ ω, term g ω ∂μ = ∫ ω, c g * (V ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) ∂μ := by refine integral_congr_ae ?_ filter_upwards [] with ω simp [term] ring _ = c g * ∫ ω, V ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ := integral_const_mul (c g) _ _ = 0 := by simp [hcell g] -
integral_eq_sum_celltheorem — Integrate an integrable function by summing over a finite measurable partition generated by G.hypothesesconclusion∫ ω, F ω ∂μ = ∑ g, ∫ ω, F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μProof (Lean source)
theorem integral_eq_sum_cell {Ω 𝒢 : Type*} [MeasurableSpace Ω] [Fintype 𝒢] [MeasurableSpace 𝒢] [MeasurableSingletonClass 𝒢] (μ : Measure Ω) (F : Ω → ℝ) (G : Ω → 𝒢) (G_meas : Measurable G) (F_int : Integrable F μ) : ∫ ω, F ω ∂μ = ∑ g, ∫ ω, F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω ∂μ := by classical let term : 𝒢 → Ω → ℝ := fun g ω => F ω * indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω have hterm_int : ∀ g ∈ (Finset.univ : Finset 𝒢), Integrable (term g) μ := by intro g _ have hG : MeasurableSet {ω : Ω | G ω = g} := G_meas (measurableSet_singleton g) have hEq : term g = fun ω => indicator {ω' | G ω' = g} F ω := by funext ω by_cases hω : G ω = g · simp [term, indicator, hω] · simp [term, indicator, hω] rw [hEq] exact F_int.indicator hG have hsum_ind : ∀ ω, (∑ g, indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) = 1 := by intro ω rw [Finset.sum_eq_single (G ω)] · simp · intro b _ hb have hne : ¬ G ω = b := fun h => hb h.symm simp [indicator, hne] · intro hnot exact elim (hnot (Finset.mem_univ _)) calc ∫ ω, F ω ∂μ = ∫ ω, F ω * (∑ g, indicator {ω' | G ω' = g} (fun _ => (1 : ℝ)) ω) ∂μ := by refine integral_congr_ae ?_ filter_upwards [] with ω simp [hsum_ind ω] _ = ∫ ω, ∑ g, term g ω ∂μ := by refine integral_congr_ae ?_ filter_upwards [] with ω simp [term, Finset.mul_sum] _ = ∑ g, ∫ ω, term g ω ∂μ := by simpa using (MeasureTheory.integral_finset_sum (Finset.univ : Finset 𝒢) (f := term) hterm_int)
Subspace 6 core · 14 supporting This file exposes panel-level names for weighted orthogonal projection, residualization, and cell-array spaces. ★ residualize_in_orthogonal
Panel Subspace Aliases
This file exposes panel-level names for weighted orthogonal projection,
residualization, and cell-array spaces. It keeps the panel regression API
connected to the generic weighted subspace construction used throughout the
library while preserving convenient Cells.* names for projection,
residual-maker, residualized-regressor, orthogonality, and idempotence facts.
Cell-array space: scalar-valued arrays on I × T.
Definition (Lean source)
Bare-name alias for c.proj. Definitionally equal to Causalean.Panel.Weighted.WeightedSupport.proj.
Bare-name alias for c.residualize. Definitionally equal to Causalean.Panel.Weighted.WeightedSupport.residualize.
Bare-name alias for c.tildeX. Same body as Causalean.Panel.Weighted.WeightedSupport.tildeX (defined as residualize H X) so that unfold tildeX exposes the residualized form.
Bare-name alias for c.tildeXVec. Same body as Causalean.Panel.Weighted.WeightedSupport.tildeXVec so that unfold tildeXVec exposes the column-by-column form.
For an array h lying in the nuisance subspace H, the array X residualized against H is orthogonal to h under the panel weighted inner product c.ip.
Formal statement
Proof (Lean source)
14 supporting declarations (lemmas, instances)
-
proj_eq_weightedlemma — The panel projection alias is definitionally equal to the generic weighted support projection.hypothesesconclusionproj c H = proj c HProof (Lean source)
-
residualize_eq_weightedlemma — The panel residual-maker alias is definitionally equal to the generic weighted support residual maker.hypothesesconclusionresidualize c H = residualize c HProof (Lean source)
lemma residualize_eq_weighted (c : Cells I T) (H : Submodule ℝ (V I T)) : residualize c H = residualize c H := rfl -
tildeX_eq_weightedlemma — The panel residualized-array alias is definitionally equal to the generic weighted support residualized array.hypothesesconclusiontildeX c H X = tildeX c H XProof (Lean source)
lemma tildeX_eq_weighted (c : Cells I T) (H : Submodule ℝ (V I T)) (X : V I T) : tildeX c H X = tildeX c H X := rfl -
tildeXVec_eq_weightedlemma — The panel column-wise residualization alias is definitionally equal to the generic weighted support column-wise residualization. -
tildeX_eqlemma — Residualizing a panel array subtracts its nuisance-space projection.hypothesesconclusionc.tildeX H X = X - c.proj H X -
residualize_applylemma — Applying the panel residual maker subtracts the nuisance-space projection.hypothesesconclusionc.residualize H X = X - c.proj H XProof (Lean source)
@[simp] lemma residualize_apply (c : Cells I T) (H : Submodule ℝ (V I T)) (X : V I T) : c.residualize H X = X - c.proj H X := residualize_apply c H X -
tildeXVec_applylemma — Column-wise residualization residualizes each regressor column separately.hypothesesI :sharedType u_1T :sharedType u_2K :sharedℕc :Cells I TH :Submodule ℝ (V I T)X :Fin K → V I Tk :Fin Kconclusionc.tildeXVec H X k = c.tildeX H (X k)Proof (Lean source)
@[simp] lemma tildeXVec_apply (c : Cells I T) (H : Submodule ℝ (V I T)) (X : Fin K → V I T) (k : Fin K) : c.tildeXVec H X k = c.tildeX H (X k) := tildeXVec_apply c H X k -
residualize_self_of_memlemma — A nuisance-space array residualizes to zero on observed cells.hypothesesI :sharedType u_1T :sharedType u_2c :Cells I TH :Submodule ℝ (V I T)X :V I ThX :X ∈ Hr :I × Thr :r ∈ c.observedconclusionc.tildeX H X r = 0Proof (Lean source)
lemma residualize_self_of_mem (c : Cells I T) (H : Submodule ℝ (V I T)) {X : V I T} (hX : X ∈ H) (r : I × T) (hr : r ∈ c.observed) : c.tildeX H X r = 0 := residualize_self_of_mem c H hX r hr -
residualize_idem_applylemma — Applying the panel residual maker twice agrees with applying it once on observed cells.hypothesesI :sharedType u_1T :sharedType u_2c :Cells I TH :Submodule ℝ (V I T)X :V I Tr :I × Thr :r ∈ c.observedconclusionc.residualize H (c.residualize H X) r = c.residualize H X rProof (Lean source)
lemma residualize_idem_apply (c : Cells I T) (H : Submodule ℝ (V I T)) (X : V I T) (r : I × T) (hr : r ∈ c.observed) : c.residualize H (c.residualize H X) r = c.residualize H X r := residualize_idem_apply c H X r hr -
proj_memlemma — The chosen panel projection of an array lies in the nuisance subspace.hypothesesconclusionc.proj H X ∈ H -
proj_orthogonallemma — The projection residual is orthogonal to every nuisance-space array under the panel weighted inner product.hypothesesI :sharedType u_1T :sharedType u_2c :Cells I TH :Submodule ℝ (V I T)X :V I Th :V I ThH :h ∈ Hconclusionc.ip (X - c.proj H X) h = 0Proof (Lean source)
lemma proj_orthogonal (c : Cells I T) (H : Submodule ℝ (V I T)) (X : V I T) {h : V I T} (hH : h ∈ H) : c.ip (X - c.proj H X) h = 0 := proj_orthogonal c H X hH -
proj_apply_of_memlemma — Projecting a nuisance-space array returns the same values on observed cells.hypothesesI :sharedType u_1T :sharedType u_2c :Cells I TH :Submodule ℝ (V I T)Y :V I ThY :Y ∈ Hr :I × Thr :r ∈ c.observedconclusionc.proj H Y r = Y rProof (Lean source)
lemma proj_apply_of_mem (c : Cells I T) (H : Submodule ℝ (V I T)) {Y : V I T} (hY : Y ∈ H) (r : I × T) (hr : r ∈ c.observed) : c.proj H Y r = Y r := proj_apply_of_mem c H hY r hr -
proj_apply_eq_of_mem_orthogonallemma — Any nuisance-space candidate with the projection orthogonality condition matches the chosen projection on observed cells.hypothesesI :sharedType u_1T :sharedType u_2c :Cells I TH :Submodule ℝ (V I T)X :V I TY :V I ThY :Y ∈ Hhorth :∀ h ∈ H, c.ip (X - Y) h = 0r :I × Thr :r ∈ c.observedconclusionc.proj H X r = Y rProof (Lean source)
lemma proj_apply_eq_of_mem_orthogonal (c : Cells I T) (H : Submodule ℝ (V I T)) (X : V I T) {Y : V I T} (hY : Y ∈ H) (horth : ∀ h ∈ H, c.ip (X - Y) h = 0) (r : I × T) (hr : r ∈ c.observed) : c.proj H X r = Y r := proj_apply_eq_of_mem_orthogonal c H X hY horth r hr -
proj_idem_applylemma — Applying the chosen panel projection twice agrees with applying it once on observed cells.hypothesesI :sharedType u_1T :sharedType u_2c :Cells I TH :Submodule ℝ (V I T)X :V I Tr :I × Thr :r ∈ c.observedconclusionc.proj H (c.proj H X) r = c.proj H X rProof (Lean source)
lemma proj_idem_apply (c : Cells I T) (H : Submodule ℝ (V I T)) (X : V I T) (r : I × T) (hr : r ∈ c.observed) : c.proj H (c.proj H X) r = c.proj H X r := proj_idem_apply c H X r hr
UniformTwoWayPanel 12 core · 10 supporting This file provides finite-sum algebra for balanced unit-period panels under the uniform unit-period measure. ★ finite_residualized_coefficient_eq_of_normalEqs★ ddot_orthogonal_unit_time
Uniform Balanced Two-Way Panels
This file provides finite-sum algebra for balanced unit-period panels under the
uniform unit-period measure. It defines BalancedPanel, uniform unit weights,
unit means, time means, grand means, double demeaning ddot, the unnormalized
inner product, the finite residualized coefficient, and the unit/time additive
nuisance class. Its main results relate the uniform constructions to
WeightedTwoWayPanel, prove the finite residualized-coefficient handoff, and
show that double-demeaned arrays are orthogonal to unit-only, time-only, and
unit/time additive functions.
Balanced panel. The side conditions from the source definition that a panel counts as balanced: the unit index type has at least two elements and the time index type has at least two elements.
For a finite set of units whose cardinality is strictly positive, the uniform unit-weight vector assigns every unit the reciprocal of the number of units.
Definition (Lean source)
For a finite set of units, a finite set of periods, a real-valued unit-period array, and a unit, the unit mean is the arithmetic average of that unit's array values over all periods.
Definition (Lean source)
For a finite set of units, a finite set of periods, a real-valued unit-period array, and a period, the time mean is the arithmetic average of that period's array values over all units.
Definition (Lean source)
For a finite set of units, a finite set of periods, and a real-valued unit-period array, the grand mean is the arithmetic average of its values over all unit-period pairs.
Definition (Lean source)
For a finite set of units, a finite set of periods, a real-valued unit-period array, a unit, and a period, the double-demeaned value equals the array value minus its unit mean and period mean plus its grand mean.
Definition (Lean source)
For a finite set of units, a finite set of periods, and two real-valued unit-period arrays, the unnormalized uniform inner product is the sum, over all unit-period pairs, of the product of their values.
Definition (Lean source)
For a finite set of units, a finite set of periods, and a residualized regressor and residualized outcome array, the finite residualized coefficient is their unnormalized inner product divided by the regressor's unnormalized self-inner-product.
Finite scalar Frisch–Waugh–Lovell handoff. Suppose the outcome and regressor decompose as Y = Yproj + Ytilde and D = Dproj + Dtilde, where Dproj and the fitted nuisance term Hβ both satisfy the nuisance predicate H, Dtilde is orthogonal to every array satisfying H, Dtilde is orthogonal to Yproj, and Dtilde has strictly positive self-inner-product (a nondegenerate residualized regressor). If the coefficient β and nuisance fit Hβ satisfy the normal equation against the raw regressor D and the normal equation against its nuisance component Dproj, then β equals the finite residualized coefficient inner Dtilde Ytilde / inner Dtilde Dtilde.
Formal statement
Proof (Lean source)
For a set of units, a set of periods, and a real-valued unit-period array, the unit-time additive condition holds precisely when there exist a real-valued unit function and a real-valued period function whose sum equals the array at every unit-period pair.
Definition (Lean source)
For a finite set of units, a finite set of periods, a real-valued unit-period array, a unit, and a period, the unit-time projection is that unit's mean plus that period's mean minus the grand mean.
Definition (Lean source)
Assume at least one unit and at least one period. Then for any array h of unit/time additive form h_it = a_i + b_t, the double-demeaned array ddot V is orthogonal to h under the unnormalized uniform panel inner product.
Formal statement
Proof (Lean source)
10 supporting declarations (lemmas, instances)
-
timeMean_eq_weightedtheorem — In a finite balanced panel with uniformly weighted units, the usual time mean in any period equals the time mean computed under the uniform unit weights.hypothesesconclusiontimeMean V t = WeightedTwoWayPanel.timeMean (uniformWeights hU) V tProof (Lean source)
theorem timeMean_eq_weighted (hU : 0 < card Unit) (V : Unit → Time → ℝ) (t : Time) : timeMean V t = WeightedTwoWayPanel.timeMean (uniformWeights hU) V t := by unfold timeMean WeightedTwoWayPanel.timeMean uniformWeights rw [← Finset.mul_sum] -
grandMean_eq_weightedtheorem — In a finite balanced panel with uniform unit weights, the usual grand mean equals the grand mean computed under those weights.hypothesesconclusiongrandMean V = WeightedTwoWayPanel.grandMean (uniformWeights hU) VProof (Lean source)
theorem grandMean_eq_weighted (hU : 0 < Fintype.card Unit) (V : Unit → Time → ℝ) : grandMean V = WeightedTwoWayPanel.grandMean (uniformWeights hU) V := by unfold grandMean WeightedTwoWayPanel.grandMean uniformWeights change (((Fintype.card Unit : ℝ) * (Fintype.card Time : ℝ))⁻¹ * ∑ i, ∑ t, V i t) = ∑ i, (Fintype.card Unit : ℝ)⁻¹ * ((Fintype.card Time : ℝ)⁻¹ * ∑ t, V i t) calc (((Fintype.card Unit : ℝ) * (Fintype.card Time : ℝ))⁻¹ * ∑ i, ∑ t, V i t) = (Fintype.card Unit : ℝ)⁻¹ * ((Fintype.card Time : ℝ)⁻¹ * ∑ i, ∑ t, V i t) := by rw [mul_inv] ring _ = ∑ i, (Fintype.card Unit : ℝ)⁻¹ * ((Fintype.card Time : ℝ)⁻¹ * ∑ t, V i t) := by rw [Finset.mul_sum, Finset.mul_sum] -
ddot_eq_weightedtheorem — Uniform double-demeaning is weighted double-demeaning with uniform unit weights.hypothesesUnit :sharedType u_1Time :sharedType u_2V :Unit → Time → ℝi :Unitt :Timeconclusionddot V i t= WeightedTwoWayPanel.ddot (uniformWeights (Fintype.card_pos_iff.mpr ⟨i⟩)) V i tProof (Lean source)
theorem ddot_eq_weighted (V : Unit → Time → ℝ) (i : Unit) (t : Time) : ddot V i t = WeightedTwoWayPanel.ddot (uniformWeights (Fintype.card_pos_iff.mpr ⟨i⟩)) V i t := by have hU : 0 < card Unit := Fintype.card_pos_iff.mpr ⟨i⟩ unfold ddot WeightedTwoWayPanel.ddot rw [timeMean_eq_weighted hU V t, grandMean_eq_weighted hU V] rfl -
sum_eq_card_mul_uniform_weightedtheorem — In a finite balanced panel, the unweighted sum across all unit-period cells equals the number of units times the corresponding sum under uniform unit weights.hypothesesUnit :sharedType u_1Time :sharedType u_2hU :0 < Fintype.card UnitF :Unit → Time → ℝconclusion∑ i, ∑ t, F i t = (Fintype.card Unit : ℝ) * ∑ i, ∑ t, (uniformWeights hU).p i * F i tProof (Lean source)
theorem sum_eq_card_mul_uniform_weighted (hU : 0 < Fintype.card Unit) (F : Unit → Time → ℝ) : ∑ i, ∑ t, F i t = (Fintype.card Unit : ℝ) * ∑ i, ∑ t, (uniformWeights hU).p i * F i t := by have hU_ne : (Fintype.card Unit : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hU) unfold uniformWeights calc ∑ i, ∑ t, F i t = ((Fintype.card Unit : ℝ) * (Fintype.card Unit : ℝ)⁻¹) * ∑ i, ∑ t, F i t := by rw [mul_inv_cancel₀ hU_ne, one_mul] _ = (Fintype.card Unit : ℝ) * ((Fintype.card Unit : ℝ)⁻¹ * ∑ i, ∑ t, F i t) := by ring _ = (Fintype.card Unit : ℝ) * ∑ i, (Fintype.card Unit : ℝ)⁻¹ * ∑ t, F i t := by rw [Finset.mul_sum] _ = (Fintype.card Unit : ℝ) * ∑ i, ∑ t, (Fintype.card Unit : ℝ)⁻¹ * F i t := by congr 1 apply Finset.sum_congr rfl intro i _hi rw [Finset.mul_sum] -
inner_eq_card_smul_weightedtheorem — The unnormalized uniform inner product is the unit count times the weighted inner product under uniform unit weights.hypothesesUnit :sharedType u_1Time :sharedType u_2hU :0 < Fintype.card UnitV W :Unit → Time → ℝconclusioninner V W = (Fintype.card Unit : ℝ) * WeightedTwoWayPanel.inner (uniformWeights hU) V WProof (Lean source)
theorem inner_eq_card_smul_weighted (hU : 0 < Fintype.card Unit) (V W : Unit → Time → ℝ) : inner V W = (Fintype.card Unit : ℝ) * WeightedTwoWayPanel.inner (uniformWeights hU) V W := by simpa [inner, WeightedTwoWayPanel.inner] using sum_eq_card_mul_uniform_weighted (Unit := Unit) (Time := Time) hU (fun i t => V i t * W i t) -
ddot_reconstructtheorem — Reconstruction identity V_it = ddot V_it + unitMean V_i + timeMean V_t - grandMean V.hypothesesUnit :sharedType u_1Time :sharedType u_2V :Unit → Time → ℝi :Unitt :Timeconclusionddot V i t + unitMean V i + timeMean V t - grandMean V = V i t -
unitTimeProjection_additivetheorem — The removed component is itself unit/time additive.hypothesesUnit :sharedType u_1Time :sharedType u_2V :Unit → Time → ℝconclusionIsUnitTimeAdditive (unitTimeProjection V)Proof (Lean source)
theorem unitTimeProjection_additive (V : Unit → Time → ℝ) : IsUnitTimeAdditive (unitTimeProjection V) := by refine ⟨unitMean V, fun t => timeMean V t - grandMean V, ?_⟩ intro i t unfold unitTimeProjection ring -
sub_ddot_eq_unitTimeProjectiontheorem — Pointwise residual decomposition V - ddot V into the unit/time projection.hypothesesUnit :sharedType u_1Time :sharedType u_2V :Unit → Time → ℝi :Unitt :TimeconclusionV i t - ddot V i t = unitTimeProjection V i t -
ddot_orthogonal_unittheorem — Double-demeaned arrays are orthogonal to arbitrary unit-only functions.hypothesesUnit :sharedType u_1Time :sharedType u_2hU :0 < card UnithT :0 < card TimeV :Unit → Time → ℝa :Unit → ℝconclusion∑ i, ∑ t, ddot V i t * a i = 0Proof (Lean source)
theorem ddot_orthogonal_unit (hU : 0 < Fintype.card Unit) (hT : 0 < Fintype.card Time) (V : Unit → Time → ℝ) (a : Unit → ℝ) : ∑ i, ∑ t, ddot V i t * a i = 0 := by classical let w := uniformWeights (Unit := Unit) hU have hweighted : ∑ i, ∑ t, w.p i * (WeightedTwoWayPanel.ddot w V i t * a i) = 0 := WeightedTwoWayPanel.ddot_orthogonal_unit w V a calc ∑ i, ∑ t, ddot V i t * a i = (Fintype.card Unit : ℝ) * ∑ i, ∑ t, w.p i * (ddot V i t * a i) := by simpa [w] using sum_eq_card_mul_uniform_weighted (Unit := Unit) (Time := Time) hU (fun i t => ddot V i t * a i) _ = (Fintype.card Unit : ℝ) * ∑ i, ∑ t, w.p i * (WeightedTwoWayPanel.ddot w V i t * a i) := by congr 1 apply Finset.sum_congr rfl intro i _hi apply Finset.sum_congr rfl intro t _ht rw [ddot_eq_weighted V i t] _ = 0 := by rw [hweighted, mul_zero] -
ddot_orthogonal_timetheorem — Double-demeaned arrays are orthogonal to arbitrary time-only functions.hypothesesconclusion∑ i, ∑ t, ddot V i t * b t = 0Proof (Lean source)
theorem ddot_orthogonal_time (hU : 0 < Fintype.card Unit) (V : Unit → Time → ℝ) (b : Time → ℝ) : ∑ i, ∑ t, ddot V i t * b t = 0 := by classical let w := uniformWeights (Unit := Unit) hU have hweighted : ∑ i, ∑ t, w.p i * (WeightedTwoWayPanel.ddot w V i t * b t) = 0 := WeightedTwoWayPanel.ddot_orthogonal_time w V b calc ∑ i, ∑ t, ddot V i t * b t = (Fintype.card Unit : ℝ) * ∑ i, ∑ t, w.p i * (ddot V i t * b t) := by simpa [w] using sum_eq_card_mul_uniform_weighted (Unit := Unit) (Time := Time) hU (fun i t => ddot V i t * b t) _ = (Fintype.card Unit : ℝ) * ∑ i, ∑ t, w.p i * (WeightedTwoWayPanel.ddot w V i t * b t) := by congr 1 apply Finset.sum_congr rfl intro i _hi apply Finset.sum_congr rfl intro t _ht rw [ddot_eq_weighted V i t] _ = 0 := by rw [hweighted, mul_zero]
FWLInstanceL2 1 core · 4 supporting This file instantiates the abstract Frisch-Waugh-Lovell development on square-integrable real functions under a probability measure. ★ fwlCoef_eq_of_original_minimizer
L2 Frisch-Waugh-Lovell Instance
This file instantiates the abstract Frisch-Waugh-Lovell development on
square-integrable real functions under a probability measure. It supplies
orthogonal projections for finite-dimensional nuisance subspaces, identifies
the Lp inner product with the corresponding population integral, and exposes
the residualized normal equations, least-squares optimality, and uniqueness
statements for the L²(μ) specialization.
FWL uniqueness on L²(μ). Fix square-integrable regressors X and outcome Y, and a finite-dimensional nuisance subspace H of L²(μ), and assume the residualized regressor Gram matrix is invertible. If the nuisance term h lies in H and the pair (β, h) minimizes the original least-squares objective jointly over all coefficient vectors and nuisance terms in H, then β equals the Frisch–Waugh–Lovell coefficient computed by residualizing against H. Specialization of Causalean.Mathlib.FWL.fwlCoef_eq_of_original_minimizer.
Formal statement
Proof (Lean source)
4 supporting declarations (lemmas, instances)
-
hasOrthogonalProjection_of_finiteDimensionalinstance — For a measurable sample space, a measure on that sample space, and a finite-dimensional real linear subspace of the square-integrable real functions under that measure, an orthogonal projection onto that subspace exists.parametersH :instancehasOrthogonalProjection_of_finiteDimensional H :H.HasOrthogonalProjectiongiven by -
inner_eq_integraltheorem — L² inner product = integral pairing. For two square-integrable real random variables, the Hilbert-space inner product equals the integral of their product, independent of the chosen representatives. This is the bridge between abstract FWL inner products and the population second moments used in estimand papers.Proof (Lean source)
theorem inner_eq_integral (f g : Lp ℝ 2 μ) : inner ℝ f g = ∫ a, f a * g a ∂μ := by rw [L2.inner_def] refine integral_congr_ae (Filter.Eventually.of_forall (fun a => ?_)) change inner ℝ (f a) (g a) = f a * g a exact mul_comm _ _ -
gramResid_mulVec_fwlCoeftheorem — Residualized normal equations on L²(μ). The FWL coefficient solves gramResid H X *ᵥ fwlCoef H X Y = residInnerVec H X Y whenever the residualized Gram matrix is invertible. Specialization of Causalean.Mathlib.FWL.gramResid_mulVec_fwlCoef.Proof (Lean source)
theorem gramResid_mulVec_fwlCoef (hQ : IsUnit (gramResid H X).det) : (gramResid H X).mulVec (fwlCoef H X Y) = residInnerVec H X Y := gramResid_mulVec_fwlCoef H X Y hQ -
fwlCoef_original_minimizestheorem — FWL least-squares optimality on L²(μ). The FWL coefficient (paired with the nuisance projection of its raw residual) minimizes the original least-squares objective over coefficients and nuisance terms in H. Specialization of Causalean.Mathlib.FWL.fwlCoef_original_minimizes.hypothesesconclusionoriginalObjective X Y (fwlCoef H X Y) (H.orthogonalProjectionFn (Y - fittedValue X (fwlCoef H X Y)))≤ originalObjective X Y β hProof (Lean source)
theorem fwlCoef_original_minimizes (hQ : IsUnit (gramResid H X).det) (β : Fin K → ℝ) {h : Lp ℝ 2 μ} (hh : h ∈ H) : originalObjective X Y (fwlCoef H X Y) (H.orthogonalProjectionFn (Y - fittedValue X (fwlCoef H X Y))) ≤ originalObjective X Y β h := fwlCoef_original_minimizes H X Y hQ β hh