Stat.Sample.Occupancy­Weighted­Mean

This module provides totalized occupancy-weighted differences of within-group sample means and a weak-second-moment variance bound under fixed overlap.

Basic 15 core · 13 supporting 15 to review This module defines totalized group/arm counts and residual sample means for a finite product sample. ★ measurable_occupancyWeightedResidual

Occupancy-weighted residual means: design statistics

This module defines totalized group/arm counts and residual sample means for a finite product sample. Every zero-count boundary is part of the definition, including the completely empty sample and an empty group type. It also exposes the measurability API needed to integrate the statistics under a product law.

def armGroupEvent unreviewed
Causalean.Stat

The arm/group event consists of observations having the requested finite group label and Boolean arm label.

Definition (Lean source)
def armGroupEvent (group : Omega -> kappa) (arm : Omega -> Bool) (a : Bool) (k : kappa) : Set Omega := {omega | group omega = k ∧ arm omega = a}
def groupEvent unreviewed
Causalean.Stat

The group event consists of observations having the requested finite group label, irrespective of arm.

Definition (Lean source)
def groupEvent (group : Omega -> kappa) (k : kappa) : Set Omega := {omega | group omega = k}
def armGroupResidual unreviewed
Causalean.Stat

The residual at an arm/group label is the outcome minus its supplied arm/group center.

Definition (Lean source)
def armGroupResidual (Y : Omega -> Real) (center : Bool -> kappa -> Real) (a : Bool) (k : kappa) (omega : Omega) : Real := Y omega - center a k
def supportedArmGroupResidual unreviewed
Causalean.Stat

The supported residual equals the arm/group residual on its own label event and is zero elsewhere.

Definition (Lean source)
noncomputable def supportedArmGroupResidual (group : Omega -> kappa) (arm : Omega -> Bool) (Y : Omega -> Real) (center : Bool -> kappa -> Real) (a : Bool) (k : kappa) : Omega -> Real := (armGroupEvent group arm a k).indicator (armGroupResidual Y center a k)
Causalean.Stat.supportedArmGroupResidual · Causalean/Stat/Sample/OccupancyWeightedMean/Basic.lean:46
def sampleDesign unreviewed
Causalean.Stat

The finite design records only the group and arm label of each sample coordinate.

Definition (Lean source)
def sampleDesign {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (z : Fin n -> Omega) : Fin n -> kappa × Bool := fun i => (group (z i), arm (z i))
def groupArmCount unreviewed
Causalean.Stat

The arm/group count is the number of sample coordinates with both the requested group and requested arm.

Definition (Lean source)
def groupArmCount {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (z : Fin n -> Omega) (a : Bool) (k : kappa) : Nat := (Finset.univ.filter fun i => group (z i) = k ∧ arm (z i) = a).card
def groupCount unreviewed
Causalean.Stat

The group count is the sum of its control and treated arm counts.

Definition (Lean source)
def groupCount {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (z : Fin n -> Omega) (k : kappa) : Nat := groupArmCount group arm z false k + groupArmCount group arm z true k
def usableGroup unreviewed
Causalean.Stat

A sample group is usable exactly when both of its empirical arm counts are positive.

Definition (Lean source)
def usableGroup {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (z : Fin n -> Omega) (k : kappa) : Prop := 0 < groupArmCount group arm z false k ∧ 0 < groupArmCount group arm z true k
def usableGroupTotal unreviewed
Causalean.Stat

The usable-group total is the total empirical occupancy of groups having both arms represented.

Definition (Lean source)
noncomputable def usableGroupTotal {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (z : Fin n -> Omega) : Nat := by classical exact ∑ k, if usableGroup group arm z k then groupCount group arm z k else 0
def armResidualSum unreviewed
Causalean.Stat

The residual sum in an arm/group cell adds only coordinates belonging to that cell.

Definition (Lean source)
noncomputable def armResidualSum {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (Y : Omega -> Real) (center : Bool -> kappa -> Real) (z : Fin n -> Omega) (a : Bool) (k : kappa) : Real := ∑ i, supportedArmGroupResidual group arm Y center a k (z i)
def armResidualMean unreviewed
Causalean.Stat

The totalized arm residual mean is the cell residual sum divided by its count when that count is positive, and zero when the count is zero.

Definition (Lean source)
noncomputable def armResidualMean {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (Y : Omega -> Real) (center : Bool -> kappa -> Real) (z : Fin n -> Omega) (a : Bool) (k : kappa) : Real := if 0 < groupArmCount group arm z a k then (groupArmCount group arm z a k : Real)⁻¹ * armResidualSum group arm Y center z a k else 0
def occupancyWeightedResidual unreviewed
Causalean.Stat

The occupancy-weighted residual statistic averages, over usable groups, each group occupancy times the treated-minus-control residual mean. It is zero when no group is usable. The law argument fixes the intended public API but does not alter this sample statistic.

Definition (Lean source)
noncomputable def occupancyWeightedResidual {n : Nat} (_mu : Measure Omega) (group : Omega -> kappa) (arm : Omega -> Bool) (Y : Omega -> Real) (center : Bool -> kappa -> Real) (z : Fin n -> Omega) : Real := by classical exact if 0 < usableGroupTotal group arm z then (usableGroupTotal group arm z : Real)⁻¹ * ∑ k, if usableGroup group arm z k then (groupCount group arm z k : Real) * (armResidualMean group arm Y center z true k - armResidualMean group arm Y center z false k) else 0 else 0
Causalean.Stat.occupancyWeightedResidual · Causalean/Stat/Sample/OccupancyWeightedMean/Basic.lean:101
def inverseUsableGroupTotal unreviewed
Causalean.Stat

The inverse usable occupancy is the reciprocal of the usable-group total when positive, and zero at the empirical zero boundary.

Definition (Lean source)
noncomputable def inverseUsableGroupTotal {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (z : Fin n -> Omega) : Real := if 0 < usableGroupTotal group arm z then (usableGroupTotal group arm z : Real)⁻¹ else 0
Causalean.Stat.inverseUsableGroupTotal · Causalean/Stat/Sample/OccupancyWeightedMean/Basic.lean:118
def occupancyDesignVarianceFactor unreviewed
Causalean.Stat

The design variance factor is the usable-group sum of squared occupancy weights times the two reciprocal arm counts, totalized to zero when no group is usable.

Definition (Lean source)
noncomputable def occupancyDesignVarianceFactor {n : Nat} (group : Omega -> kappa) (arm : Omega -> Bool) (z : Fin n -> Omega) : Real := by classical exact if 0 < usableGroupTotal group arm z then (usableGroupTotal group arm z : Real)⁻¹ ^ 2 * ∑ k, if usableGroup group arm z k then (groupCount group arm z k : Real) ^ 2 * ((groupArmCount group arm z true k : Real)⁻¹ + (groupArmCount group arm z false k : Real)⁻¹) else 0 else 0
Causalean.Stat.occupancyDesignVarianceFactor · Causalean/Stat/Sample/OccupancyWeightedMean/Basic.lean:126
lemma measurable_occupancyWeightedResidual unreviewed
Causalean.Stat

Measurable group labels, arm labels, and outcomes make the zero-safe occupancy-weighted residual measurable on the finite product sample space.

Formal statement
n :
mu :
Measure Omega
group :
Omega -> kappa
arm :
Omega -> Bool
Y :
Omega -> Real
center :
Bool -> kappa -> Real
hgroup :
harm :
hY :
Measurable (occupancyWeightedResidual (n := n) mu group arm Y center)
Proof (Lean source)
lemma measurable_occupancyWeightedResidual {n : Nat} (mu : Measure Omega) (group : Omega -> kappa) (arm : Omega -> Bool) (Y : Omega -> Real) (center : Bool -> kappa -> Real) (hgroup : Measurable group) (harm : Measurable arm) (hY : Measurable Y) : Measurable (occupancyWeightedResidual (n := n) mu group arm Y center) := by classical have htotal : Measurable (fun z : Fin n -> Omega => usableGroupTotal group arm z) := measurable_usableGroupTotal group arm hgroup harm have hpos : MeasurableSet {z : Fin n -> Omega | 0 < usableGroupTotal group arm z} := measurableSet_lt measurable_const htotal have htotalCast : Measurable (fun z : Fin n -> Omega => (usableGroupTotal group arm z : Real)) := (Measurable.of_discrete : Measurable fun m : Nat => (m : Real)).comp htotal have hsum : Measurable (fun z : Fin n -> Omega => ∑ k, if usableGroup group arm z k then (groupCount group arm z k : Real) * (armResidualMean group arm Y center z true k - armResidualMean group arm Y center z false k) else 0) := by apply measurable_sum intro k hk have hgroupCount := measurable_groupCount (n := n) group arm hgroup harm k have hgroupCountCast : Measurable (fun z : Fin n -> Omega => (groupCount group arm z k : Real)) := (Measurable.of_discrete : Measurable fun m : Nat => (m : Real)).comp hgroupCount exact Measurable.ite (measurableSet_usableGroup group arm hgroup harm k) (hgroupCountCast.mul ((measurable_armResidualMean group arm Y center hgroup harm hY true k).sub (measurable_armResidualMean group arm Y center hgroup harm hY false k))) measurable_const unfold occupancyWeightedResidual exact Measurable.ite hpos (htotalCast.inv.mul hsum) measurable_const
Causalean.Stat.measurable_occupancyWeightedResidual · Causalean/Stat/Sample/OccupancyWeightedMean/Basic.lean:273 · uses occupancyWeightedResidual
13 supporting declarations (lemmas, instances)
Binomial­Design 3 core · 0 supporting 3 to review This module turns weighted sums over finite Boolean assignments into binomial sums and controls the inverse-arm contribution of one occupied group. ★ sum_bernoulli_local_variance_le_share

Bernoulli enumeration for occupancy-weighted design factors

This module turns weighted sums over finite Boolean assignments into binomial sums and controls the inverse-arm contribution of one occupied group. It is entirely algebraic and does not use conditional probability.

def inverseTwoCounts unreviewed
Causalean.Stat

The two-arm inverse-count contribution is the sum of the inverse success and failure counts when both are positive, and zero at either endpoint.

Definition (Lean source)
noncomputable def inverseTwoCounts (m j : Nat) : Real := if 0 < j ∧ j < m then (j : Real)⁻¹ + ((m - j : Nat) : Real)⁻¹ else 0
def interiorIndicator unreviewed
Causalean.Stat

The binomial interior indicator is one when both success and failure counts are positive, and zero at either endpoint.

Definition (Lean source)
def interiorIndicator (m j : Nat) : Real := if 0 < j ∧ j < m then 1 else 0
lemma sum_bernoulli_local_variance_le_share unreviewed
Causalean.Stat

If the overlap margin is positive and one group's success probability lies between the margin and one minus the margin, that group's expected inverse-arm variance contribution is controlled by its expected share of reciprocal usable occupancy.

Formal statement
ι :
r :
p epsilon :
hepsilon :
0 < epsilon
hlo :
epsilon ≤ p
hhi :
p ≤ 1 - epsilon
(∑ b : ι → Bool, (∏ i, if b i then p else 1 - p) * ((Fintype.card ι : Real) ^ 2 * (((r + Fintype.card ι : Nat) : Real)⁻¹ ^ 2) * inverseTwoCounts (Fintype.card ι) (Finset.univ.filter fun i => b i = true).card))
≤ (4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ b : ι → Bool, (∏ i, if b i then p else 1 - p) * ((Fintype.card ι : Real) * (((r + Fintype.card ι : Nat) : Real)⁻¹ ^ 2) * interiorIndicator (Fintype.card ι) (Finset.univ.filter fun i => b i = true).card)
Proof (Lean source)
lemma sum_bernoulli_local_variance_le_share {ι : Type*} [Fintype ι] [DecidableEq ι] (r : Nat) (p epsilon : Real) (hepsilon : 0 < epsilon) (hlo : epsilon ≤ p) (hhi : p ≤ 1 - epsilon) : (∑ b : ι → Bool, (∏ i, if b i then p else 1 - p) * ((Fintype.card ι : Real) ^ 2 * (((r + Fintype.card ι : Nat) : Real)⁻¹ ^ 2) * inverseTwoCounts (Fintype.card ι) (Finset.univ.filter fun i => b i = true).card)) ≤ (4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ b : ι → Bool, (∏ i, if b i then p else 1 - p) * ((Fintype.card ι : Real) * (((r + Fintype.card ι : Nat) : Real)⁻¹ ^ 2) * interiorIndicator (Fintype.card ι) (Finset.univ.filter fun i => b i = true).card) := by classical let m := Fintype.card ι by_cases hm : 2 ≤ m · have hnum := binomial_inverse_two_arms_interior_le m p epsilon hepsilon hlo hhi have hmass := sum_binomialWeight_interior_lower hm p epsilon hepsilon hlo hhi have heps1 : 0 < 1 - epsilon := by linarith have hmpos : (0 : Real) < (m + 1 : Nat) := by positivity have hA : (m : Real) * (∑ j ∈ range (m + 1), binomialWeight m p j * inverseTwoCounts m j) ≤ 4 / epsilon := by have hmle : (m : Real) ≤ (m + 1 : Nat) := by norm_num have hden : 0 < ((m + 1 : Nat) : Real) * epsilon := by positivity unfold inverseTwoCounts at hnum calc (m : Real) * (∑ j ∈ range (m + 1), binomialWeight m p j * inverseTwoCounts m j) ≤ (m : Real) * (4 / (((m + 1 : Nat) : Real) * epsilon)) := by gcongr simpa [inverseTwoCounts] using hnum _ ≤ 4 / epsilon := by have hratio : (m : Real) / ((m + 1 : Nat) : Real) ≤ 1 := (div_le_one hmpos).2 hmle calc (m : Real) * (4 / (((m + 1 : Nat) : Real) * epsilon)) = (4 / epsilon) * ((m : Real) / ((m + 1 : Nat) : Real)) := by field_simp <;> ring _ ≤ (4 / epsilon) * 1 := mul_le_mul_of_nonneg_left hratio (by positivity) _ = 4 / epsilon := by ring have hB : 4 / epsilon ≤ (4 / (epsilon ^ 2 * (1 - epsilon))) * (∑ j ∈ range (m + 1), binomialWeight m p j * interiorIndicator m j) := by dsimp [interiorIndicator] have hconst : 0 < epsilon ^ 2 * (1 - epsilon) := by positivity calc 4 / epsilon ≤ 8 / epsilon := by exact div_le_div_of_nonneg_right (by norm_num) hepsilon.le _ = (4 / (epsilon ^ 2 * (1 - epsilon))) * (2 * epsilon * (1 - epsilon)) := by field_simp <;> ring _ ≤ (4 / (epsilon ^ 2 * (1 - epsilon))) * (∑ j ∈ range (m + 1), binomialWeight m p j * (if 0 < j ∧ j < m then (1 : Real) else 0)) := by exact mul_le_mul_of_nonneg_left hmass (by positivity) rw [sum_bernoulli_eq_binomial p (fun j => (m : Real) ^ 2 * (((r + m : Nat) : Real)⁻¹ ^ 2) * inverseTwoCounts m j)] rw [sum_bernoulli_eq_binomial p (fun j => (m : Real) * (((r + m : Nat) : Real)⁻¹ ^ 2) * interiorIndicator m j)] simp only [m] have hscale : 0 ≤ (m : Real) * (((r + m : Nat) : Real)⁻¹ ^ 2) := by positivity calc (∑ j ∈ range (m + 1), binomialWeight m p j * ((m : Real) ^ 2 * (((r + m : Nat) : Real)⁻¹ ^ 2) * inverseTwoCounts m j)) = ((m : Real) * (((r + m : Nat) : Real)⁻¹ ^ 2)) * ((m : Real) * ∑ j ∈ range (m + 1), binomialWeight m p j * inverseTwoCounts m j) := by simp_rw [Finset.mul_sum] apply Finset.sum_congr rfl intro j hj ring_nf _ ≤ ((m : Real) * (((r + m : Nat) : Real)⁻¹ ^ 2)) * (4 / epsilon) := by gcongr _ ≤ ((m : Real) * (((r + m : Nat) : Real)⁻¹ ^ 2)) * ((4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ j ∈ range (m + 1), binomialWeight m p j * interiorIndicator m j) := by gcongr _ = (4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ j ∈ range (m + 1), binomialWeight m p j * ((m : Real) * (((r + m : Nat) : Real)⁻¹ ^ 2) * interiorIndicator m j) := by simp_rw [Finset.mul_sum] ring · have hmle : m ≤ 1 := by omega have hzero (j : Nat) : inverseTwoCounts (Fintype.card ι) j = 0 := by simp only [inverseTwoCounts] rw [if_neg] dsimp [m] at hmle omega rw [show (∑ b : ι → Bool, (∏ i, if b i then p else 1 - p) * ((Fintype.card ι : Real) ^ 2 * (((r + Fintype.card ι : Nat) : Real)⁻¹ ^ 2) * inverseTwoCounts (Fintype.card ι) (Finset.univ.filter fun i => b i = true).card)) = 0 by apply Finset.sum_eq_zero intro b hb rw [hzero] ring] apply mul_nonneg · have heps1 : 0 < 1 - epsilon := by linarith positivity · apply sum_nonneg intro b hb apply mul_nonneg · apply Finset.prod_nonneg intro i hi split · exact (hepsilon.trans_le hlo).le · linarith · dsimp [interiorIndicator] split <;> positivity
Finite­Design 1 core · 0 supporting 1 to review This module assembles groupwise inverse-arm bounds into an algebraic comparison between the expected occupancy design variance factor and reciprocal usable occupancy. ★ sum_jointWeight_variance_le_inverse

Finite enumeration for occupancy-weighted design factors

This module assembles groupwise inverse-arm bounds into an algebraic comparison between the expected occupancy design variance factor and reciprocal usable occupancy. Zero-mass group fibers vanish before any conditional arm probability is formed.

lemma sum_jointWeight_variance_le_inverse unreviewed
Causalean.Stat

If all joint group/arm masses are nonnegative, their two arm masses sum to the group mass, the overlap margin is positive and at most one half, and each positive-mass group gives both arms at least the overlap share, the joint-design average of the occupancy variance factor is bounded by a margin-dependent multiple of average reciprocal usable occupancy. Zero-mass groups contribute zero before any conditional arm probability is formed.

Formal statement
q :
κ → BoolReal
g :
κ → Real
epsilon :
hq :
∀ k a, 0 ≤ q k a
hsum :
∀ k, q k false + q k true = g k
hepsilon :
0 < epsilon
hepsilon_half :
epsilon ≤ (1 / 2 : Real)
hoverlap :
∀ k
if
0 < g k
then
∀ a, epsilon * g k ≤ q k a
(∑ d : Fin n → κ × Bool, (∏ i, q (d i).1 (d i).2) * occupancyDesignVarianceFactor fst snd d)
≤ (4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ d : Fin n → κ × Bool, (∏ i, q (d i).1 (d i).2) * inverseUsableGroupTotal fst snd d
Proof (Lean source)
lemma sum_jointWeight_variance_le_inverse (q : κ → BoolReal) (g : κ → Real) (epsilon : Real) (hq : ∀ k a, 0 ≤ q k a) (hsum : ∀ k, q k false + q k true = g k) (hepsilon : 0 < epsilon) (hepsilon_half : epsilon ≤ (1 / 2 : Real)) (hoverlap : ∀ k, 0 < g k → ∀ a, epsilon * g k ≤ q k a) : (∑ d : Fin n → κ × Bool, (∏ i, q (d i).1 (d i).2) * occupancyDesignVarianceFactor fst snd d) ≤ (4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ d : Fin n → κ × Bool, (∏ i, q (d i).1 (d i).2) * inverseUsableGroupTotal fst snd d := by classical rw [Fintype.sum_equiv fdDesignSplit (fun d => (∏ i, q (d i).1 (d i).2) * occupancyDesignVarianceFactor fst snd d) (fun xb => (∏ i, q (xb.1 i) (xb.2 i)) * fdVariance xb.1 xb.2) (fun d => by rw [canonical_variance_eq] rfl), Fintype.sum_prod_type] rw [Fintype.sum_equiv fdDesignSplit (fun d => (∏ i, q (d i).1 (d i).2) * inverseUsableGroupTotal fst snd d) (fun xb => (∏ i, q (xb.1 i) (xb.2 i)) * fdInverse xb.1 xb.2) (fun d => by rw [canonical_inverse_eq] rfl), Fintype.sum_prod_type] rw [Finset.mul_sum] apply Finset.sum_le_sum intro x hx by_cases hpos : ∀ i, 0 < g (x i) · let p : κ → Real := fun k => if 0 < g k then q k true / g k else epsilon let G : Real := ∏ i, g (x i) have hg0 (k : κ) : 0 ≤ g k := by rw [← hsum k] exact add_nonneg (hq k false) (hq k true) have hp_lo (k : κ) : epsilon ≤ p k := by by_cases hg : 0 < g k · dsimp [p] rw [if_pos hg] apply (le_div_iff₀ hg).2 exact hoverlap k hg true · simp [p, hg] have hp_hi (k : κ) : p k ≤ 1 - epsilon := by by_cases hg : 0 < g k · dsimp [p] rw [if_pos hg] apply (div_le_iff₀ hg).2 have hf := hoverlap k hg false calc q k true ≤ g k - epsilon * g k := by linarith [hsum k] _ = (1 - epsilon) * g k := by ring · simp [p, hg] linarith have hG : 0 ≤ G := by dsimp [G] exact Finset.prod_nonneg fun i _ => hg0 (x i) have hfactor (b : Fin n → Bool) : (∏ i, q (x i) (b i)) = G * fdWeight p x b := by dsimp [G, fdWeight] rw [← Finset.prod_mul_distrib] apply Finset.prod_congr rfl intro i hi have hg := hpos i by_cases hb : b i · simp [hb, p, hg] field_simp · simp [hb, p, hg] have hs := hsum (x i) field_simp linarith have hcond := sum_fdWeight_variance_le_inverse p x epsilon hepsilon hp_lo hp_hi calc (∑ b, (∏ i, q (x i) (b i)) * fdVariance x b) = G * ∑ b, fdWeight p x b * fdVariance x b := by rw [Finset.mul_sum] apply Finset.sum_congr rfl intro b hb rw [hfactor] ring _ ≤ G * ((4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ b, fdWeight p x b * fdInverse x b) := mul_le_mul_of_nonneg_left hcond hG _ = (4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ b, (∏ i, q (x i) (b i)) * fdInverse x b := by rw [show (∑ b, (∏ i, q (x i) (b i)) * fdInverse x b) = G * ∑ b, fdWeight p x b * fdInverse x b by rw [Finset.mul_sum] apply Finset.sum_congr rfl intro b hb rw [hfactor] ring] ring · push Not at hpos obtain ⟨i, hi⟩ := hpos have hg0 : 0 ≤ g (x i) := by rw [← hsum (x i)] exact add_nonneg (hq (x i) false) (hq (x i) true) have hgzero : g (x i) = 0 := le_antisymm hi hg0 have hqzero (a : Bool) : q (x i) a = 0 := by have hs := hsum (x i) have hfalse := hq (x i) false have htrue := hq (x i) true rw [hgzero] at hs cases a <;> nlinarith have hweight (b : Fin n → Bool) : (∏ j, q (x j) (b j)) = 0 := Finset.prod_eq_zero (Finset.mem_univ i) (hqzero (b i)) simp [hweight]
Moment­Bounds 1 core · 3 supporting 1 to review This module proves finite-product orthogonality, a one-coordinate second-moment comparison, and the design-only reciprocal-count estimate for occupancy-weighted differences of within-group residual means. ★ integral_occupancyDesignVarianceFactor_le_reciprocal

Product-moment bounds for occupancy-weighted residual means

This module proves finite-product orthogonality, a one-coordinate second-moment comparison, and the design-only reciprocal-count estimate for occupancy-weighted differences of within-group residual means. Outcomes are real-valued and need only the stated supported second-moment bounds.

lemma integral_occupancyDesignVarianceFactor_le_reciprocal unreviewed
Causalean.Stat

If group and arm labels are measurable, the overlap margin is positive and at most one half, and both arms receive at least that share in every positive-mass group, the expected design variance factor is at most sixteen divided by the squared margin times one minus the margin, multiplied by expected reciprocal usable occupancy. This includes zero-mass groups, empty samples, empty group types, and every zero-count boundary.

Formal statement
n :
group :
Omega -> kappa
arm :
Omega -> Bool
hgroup :
harm :
epsilon :
hepsilon :
0 < epsilon
hepsilon_half :
epsilon ≤ (1 / 2 : Real)
hoverlap :
∀ k,
0 < (mu (groupEvent group k)).toReal -> ∀ a, epsilon * (mu (groupEvent group k)).toReal
≤ (mu (armGroupEvent group arm a k)).toReal
∫ z : Fin n -> Omega, occupancyDesignVarianceFactor group arm z ∂(Measure.pi (fun _ : Fin n => mu))
≤ (16 / (epsilon ^ 2 * (1 - epsilon))) * ∫ z : Fin n -> Omega, inverseUsableGroupTotal group arm z ∂(Measure.pi (fun _ : Fin n => mu))
Proof (Lean source)
lemma integral_occupancyDesignVarianceFactor_le_reciprocal {n : Nat} (mu : Measure Omega) [IsProbabilityMeasure mu] (group : Omega -> kappa) (arm : Omega -> Bool) (hgroup : Measurable group) (harm : Measurable arm) (epsilon : Real) (hepsilon : 0 < epsilon) (hepsilon_half : epsilon ≤ (1 / 2 : Real)) (hoverlap : ∀ k, 0 < (mu (groupEvent group k)).toReal -> ∀ a, epsilon * (mu (groupEvent group k)).toReal ≤ (mu (armGroupEvent group arm a k)).toReal) : ∫ z : Fin n -> Omega, occupancyDesignVarianceFactor group arm z ∂(Measure.pi (fun _ : Fin n => mu)) ≤ (16 / (epsilon ^ 2 * (1 - epsilon))) * ∫ z : Fin n -> Omega, inverseUsableGroupTotal group arm z ∂(Measure.pi (fun _ : Fin n => mu)) := by -- Push the sample to its finite `(group,arm)` design. Enumerate group -- assignments and then arm subsets within each group. Conditional on a -- group count `m`, use `binomial_inverse_two_arms_interior_le`; compare the -- change in the global usable denominator at the two endpoint designs and -- sum over groups. Zero-mass fibers contribute zero before division. classical let q : kappa → BoolReal := fun k a => (mu (armGroupEvent group arm a k)).toReal let g : kappa → Real := fun k => (mu (groupEvent group k)).toReal have hq (k : kappa) (a : Bool) : 0 ≤ q k a := by dsimp [q] positivity have hsum (k : kappa) : q k false + q k true = g k := by have hpart : groupEvent group k = armGroupEvent group arm false k ∪ armGroupEvent group arm true k := by ext omega cases h : arm omega <;> simp [groupEvent, armGroupEvent, h] have hdisj : Disjoint (armGroupEvent group arm false k) (armGroupEvent group arm true k) := by rw [Set.disjoint_left] intro omega hf ht exact Bool.false_ne_true (hf.2.symm.trans ht.2) have hmeas : MeasurableSet (armGroupEvent group arm true k) := measurableSet_armGroupEvent group arm hgroup harm true k have hadd : mu (armGroupEvent group arm false k) + mu (armGroupEvent group arm true k) = mu (groupEvent group k) := by rw [← measure_union hdisj hmeas, hpart] dsimp [q, g] rw [← ENNReal.toReal_add (measure_ne_top mu _) (measure_ne_top mu _), hadd] have hoverlap' (k : kappa) (hk : 0 < g k) (a : Bool) : epsilon * g k ≤ q k a := by exact hoverlap k (by simpa [g] using hk) a let Wv : (Fin n → kappa × Bool) → Real := fun d => occupancyDesignVarianceFactor Prod.fst Prod.snd d let Wi : (Fin n → kappa × Bool) → Real := fun d => inverseUsableGroupTotal Prod.fst Prod.snd d have hone : ∀ i : Fin n, Integrable (fun _ : Omega => (1 : Real)) mu := by intro i exact integrable_const 1 have hformula (W : (Fin n → kappa × Bool) → Real) : (∫ z : Fin n → Omega, W (sampleDesign group arm z) ∂(Measure.pi (fun _ : Fin n => mu))) = ∑ d : Fin n → kappa × Bool, W d * ∏ i, q (d i).1 (d i).2 := by have h := integral_designWeight_mul_prod mu group arm hgroup harm W (fun _ _ => (1 : Real)) hone simpa [q, Measure.real] using h have hsample_v (z : Fin n → Omega) : Wv (sampleDesign group arm z) = occupancyDesignVarianceFactor group arm z := by rfl have hsample_i (z : Fin n → Omega) : Wi (sampleDesign group arm z) = inverseUsableGroupTotal group arm z := by rfl have hfinite := sum_jointWeight_variance_le_inverse (n := n) q g epsilon hq hsum hepsilon hepsilon_half hoverlap' have hsum_nonneg : 0 ≤ ∑ d : Fin n → kappa × Bool, (∏ i, q (d i).1 (d i).2) * Wi d := by apply sum_nonneg intro d hd apply mul_nonneg · exact Finset.prod_nonneg fun i _ => hq (d i).1 (d i).2 · unfold Wi inverseUsableGroupTotal split <;> positivity have heps1 : 0 < 1 - epsilon := by linarith have hden : 0 < epsilon ^ 2 * (1 - epsilon) := by positivity have hconst : 4 / (epsilon ^ 2 * (1 - epsilon)) ≤ 16 / (epsilon ^ 2 * (1 - epsilon)) := by exact div_le_div_of_nonneg_right (by norm_num) hden.le calc (∫ z : Fin n → Omega, occupancyDesignVarianceFactor group arm z ∂(Measure.pi (fun _ : Fin n => mu))) = ∑ d : Fin n → kappa × Bool, Wv d * ∏ i, q (d i).1 (d i).2 := by rw [← hformula Wv] apply integral_congr_ae filter_upwards [] with z exact (hsample_v z).symm _ = ∑ d : Fin n → kappa × Bool, (∏ i, q (d i).1 (d i).2) * Wv d := by apply Finset.sum_congr rfl intro d hd ring _ ≤ (4 / (epsilon ^ 2 * (1 - epsilon))) * ∑ d : Fin n → kappa × Bool, (∏ i, q (d i).1 (d i).2) * Wi d := hfinite _ ≤ (16 / (epsilon ^ 2 * (1 - epsilon))) * ∑ d : Fin n → kappa × Bool, (∏ i, q (d i).1 (d i).2) * Wi d := mul_le_mul_of_nonneg_right hconst hsum_nonneg _ = (16 / (epsilon ^ 2 * (1 - epsilon))) * ∫ z : Fin n → Omega, inverseUsableGroupTotal group arm z ∂(Measure.pi (fun _ : Fin n => mu)) := by have hi : (∫ z : Fin n → Omega, inverseUsableGroupTotal group arm z ∂(Measure.pi (fun _ : Fin n => mu))) = ∑ d : Fin n → kappa × Bool, Wi d * ∏ i, q (d i).1 (d i).2 := by calc (∫ z : Fin n → Omega, inverseUsableGroupTotal group arm z ∂(Measure.pi (fun _ : Fin n => mu))) = ∫ z : Fin n → Omega, Wi (sampleDesign group arm z) ∂(Measure.pi (fun _ : Fin n => mu)) := by apply integral_congr_ae filter_upwards [] with z exact (hsample_i z).symm _ = _ := hformula Wi rw [hi] congr 1 apply Finset.sum_congr rfl intro d hd ring
3 supporting declarations (lemmas, instances)
Variance 1 core · 1 supporting 1 to review This module represents the occupancy-weighted statistic as a finite sum of supported residuals, proves its square integrability, and bounds its second moment by expected reciprocal usable occupancy. ★ integral_occupancyWeightedResidual_sq_le_reciprocal

Weak-moment variance bound for occupancy-weighted residual means

This module represents the occupancy-weighted statistic as a finite sum of supported residuals, proves its square integrability, and bounds its second moment by expected reciprocal usable occupancy. Outcomes need only supported arm/group second moments; all empirical zero-count cases are totalized.

theorem integral_occupancyWeightedResidual_sq_le_reciprocal unreviewed
Causalean.Stat

If group labels, arm labels, and outcomes are measurable, every supported residual has a finite second moment, residuals are centered within every arm/group cell, their cellwise second moments obey the stated envelope, the overlap margin is positive and at most one half, and both arms receive at least that share in every positive-mass group, the squared occupancy-weighted residual has product-law expectation at most sixteen divided by the squared margin times one minus the margin, multiplied by the squared envelope and expected reciprocal usable occupancy.

Formal statement
n :
group :
Omega -> kappa
arm :
Omega -> Bool
Y :
Omega -> Real
center :
Bool -> kappa -> Real
V epsilon :
hgroup :
harm :
hY :
hmem :
∀ a k, MemLp (supportedArmGroupResidual group arm Y center a k) 2 mu
hcenter :
∀ a k, ∫ omega in armGroupEvent group arm a k, armGroupResidual Y center a k omega ∂mu = 0
hsq :
∀ a k,
∫ omega in armGroupEvent group arm a k, (armGroupResidual Y center a k omega) ^ 2 ∂mu
≤ (mu (armGroupEvent group arm a k)).toReal * V ^ 2
hepsilon :
0 < epsilon
hepsilon_half :
epsilon ≤ (1 / 2 : Real)
hoverlap :
∀ k,
0 < (mu (groupEvent group k)).toReal -> ∀ a, epsilon * (mu (groupEvent group k)).toReal
≤ (mu (armGroupEvent group arm a k)).toReal
∫ z : Fin n -> Omega, (occupancyWeightedResidual mu group arm Y center z) ^ 2 ∂(Measure.pi (fun _ : Fin n => mu))
≤ (16 / (epsilon ^ 2 * (1 - epsilon))) * V ^ 2 * ∫ z : Fin n -> Omega, (if 0 < usableGroupTotal group arm z then (usableGroupTotal group arm z : Real)⁻¹ else 0) ∂(Measure.pi (fun _ : Fin n => mu))
Proof (Lean source)
theorem integral_occupancyWeightedResidual_sq_le_reciprocal {n : Nat} (mu : Measure Omega) [IsProbabilityMeasure mu] (group : Omega -> kappa) (arm : Omega -> Bool) (Y : Omega -> Real) (center : Bool -> kappa -> Real) (V epsilon : Real) (hgroup : Measurable group) (harm : Measurable arm) (hY : Measurable Y) (hmem : ∀ a k, MemLp (supportedArmGroupResidual group arm Y center a k) 2 mu) (hcenter : ∀ a k, ∫ omega in armGroupEvent group arm a k, armGroupResidual Y center a k omega ∂mu = 0) (hsq : ∀ a k, ∫ omega in armGroupEvent group arm a k, (armGroupResidual Y center a k omega) ^ 2 ∂mu ≤ (mu (armGroupEvent group arm a k)).toReal * V ^ 2) (hepsilon : 0 < epsilon) (hepsilon_half : epsilon ≤ (1 / 2 : Real)) (hoverlap : ∀ k, 0 < (mu (groupEvent group k)).toReal -> ∀ a, epsilon * (mu (groupEvent group k)).toReal ≤ (mu (armGroupEvent group arm a k)).toReal) : ∫ z : Fin n -> Omega, (occupancyWeightedResidual mu group arm Y center z) ^ 2 ∂(Measure.pi (fun _ : Fin n => mu)) ≤ (16 / (epsilon ^ 2 * (1 - epsilon))) * V ^ 2 * ∫ z : Fin n -> Omega, (if 0 < usableGroupTotal group arm z then (usableGroupTotal group arm z : Real)⁻¹ else 0) ∂(Measure.pi (fun _ : Fin n => mu)) := by -- Expand the square into coordinate/label pairs. Different coordinates -- vanish by finite-product centering and different labels at one coordinate -- vanish pointwise. Bound the remaining diagonal terms by `hsq`, identify -- the resulting design factor, and apply the design-only reciprocal theorem. -- Concretely, reuse the finite-design coefficient `weight` from the preceding -- L2 proof and write the statistic as `sum k,a,i weight * supportedResidual`. -- Each summand is L2 (the same bounded-coefficient argument), so every pair -- product is integrable by `MemLp.integrable_mul` and the finite sums may pass -- through the integral. For `i != j`, apply -- `integral_designWeight_residual_cross_coordinates_eq_zero` with the product -- of the two design coefficients. For `i = j` but unequal labels, use -- `supportedArmGroupResidual_mul_eq_zero_of_ne`. Apply -- `integral_designWeight_residual_sq_le_indicator` to the equal-label terms -- with squared coefficient. The remaining pointwise finite sum is exactly -- `occupancyDesignVarianceFactor`; split on positive usable total and -- usability, and rewrite the coordinate indicator sums as arm/group counts. classical let weight : (Fin n → kappa × Bool) → Bool → kappa → Real := occupancyResidualWeight let bound : Real := ∑ d : Fin n → kappa × Bool, ∑ a : Bool, ∑ k : kappa, |weight d a k| have hweight_bound (d : Fin n → kappa × Bool) (a : Bool) (k : kappa) : |weight d a k| ≤ bound := by dsimp [bound] calc |weight d a k| ≤ ∑ k' : kappa, |weight d a k'| := Finset.single_le_sum (fun k' _ => abs_nonneg (weight d a k')) (Finset.mem_univ k) _ ≤ ∑ a' : Bool, ∑ k' : kappa, |weight d a' k'| := Finset.single_le_sum (fun a' _ => sum_nonneg fun k' _ => abs_nonneg (weight d a' k')) (Finset.mem_univ a) _ ≤ ∑ d' : Fin n → kappa × Bool, ∑ a' : Bool, ∑ k' : kappa, |weight d' a' k'| := Finset.single_le_sum (fun d' _ => sum_nonneg fun a' _ => sum_nonneg fun k' _ => abs_nonneg (weight d' a' k')) (Finset.mem_univ d) let term : (kappa × Bool × Fin n) → (Fin n → Omega) → Real := fun t z => weight (sampleDesign group arm z) t.2.1 t.1 * supportedArmGroupResidual group arm Y center t.2.1 t.1 (z t.2.2) have hterm (t : kappa × Bool × Fin n) : MemLp (term t) 2 (Measure.pi (fun _ : Fin n => mu)) := by have hr := (hmem t.2.1 t.1).comp_measurePreserving (measurePreserving_eval (fun _ : Fin n => mu) t.2.2) have hw : Measurable (fun d : Fin n → kappa × Bool => weight d t.2.1 t.1) := Measurable.of_discrete apply hr.of_le_mul · have hm : AEStronglyMeasurable (((fun d : Fin n → kappa × Bool => weight d t.2.1 t.1) ∘ sampleDesign group arm) * (supportedArmGroupResidual group arm Y center t.2.1 t.1 ∘ fun z => z t.2.2)) (Measure.pi (fun _ : Fin n => mu)) := ((hw.comp (measurable_sampleDesign group arm hgroup harm)).mul ((measurable_supportedArmGroupResidual group arm Y center hgroup harm hY t.2.1 t.1).comp (measurable_pi_apply t.2.2))).aestronglyMeasurable refine hm.congr ?_ filter_upwards [] with z rfl · filter_upwards [] with z rw [Real.norm_eq_abs, Real.norm_eq_abs, abs_mul] exact mul_le_mul_of_nonneg_right (hweight_bound _ _ _) (abs_nonneg _) have hpair_integrable (t u : kappa × Bool × Fin n) : Integrable (fun z => term t z * term u z) (Measure.pi (fun _ : Fin n => mu)) := by change Integrable (term t * term u) (Measure.pi (fun _ : Fin n => mu)) exact (hterm t).integrable_mul (hterm u) have hresidual_sum (z : Fin n → Omega) : occupancyWeightedResidual mu group arm Y center z = ∑ t, term t z := by rw [occupancyWeightedResidual_eq_sum_weight] simp only [term, weight, Fintype.sum_prod_type] have hpair_zero (t u : kappa × Bool × Fin n) (htu : u ≠ t) : ∫ z, term t z * term u z ∂(Measure.pi (fun _ : Fin n => mu)) = 0 := by by_cases hij : t.2.2 = u.2.2 · have hlabel : (t.2.1, t.1) ≠ (u.2.1, u.1) := by intro hlabel apply htu apply Prod.ext · exact (congrArg snd hlabel).symm · apply Prod.ext · exact (congrArg fst hlabel).symm · exact hij.symm apply integral_eq_zero_of_ae filter_upwards [] with z dsimp [term] rw [hij] have hzres := supportedArmGroupResidual_mul_eq_zero_of_ne group arm Y center t.2.1 u.2.1 t.1 u.1 hlabel (z u.2.2) calc weight (sampleDesign group arm z) t.2.1 t.1 * supportedArmGroupResidual group arm Y center t.2.1 t.1 (z u.2.2) * (weight (sampleDesign group arm z) u.2.1 u.1 * supportedArmGroupResidual group arm Y center u.2.1 u.1 (z u.2.2)) = (weight (sampleDesign group arm z) t.2.1 t.1 * weight (sampleDesign group arm z) u.2.1 u.1) * (supportedArmGroupResidual group arm Y center t.2.1 t.1 (z u.2.2) * supportedArmGroupResidual group arm Y center u.2.1 u.1 (z u.2.2)) := by ring _ = 0 := by rw [hzres]; ring · have hcross := integral_designWeight_residual_cross_coordinates_eq_zero mu group arm Y center hgroup harm hY hmem hcenter (fun d => weight d t.2.1 t.1 * weight d u.2.1 u.1) t.2.2 u.2.2 hij t.2.1 u.2.1 t.1 u.1 simpa [term, mul_assoc, mul_left_comm, mul_comm] using hcross have hdiagonal (t : kappa × Bool × Fin n) : (∫ z, term t z * term t z ∂(Measure.pi (fun _ : Fin n => mu))) ≤ V ^ 2 * ∫ z, weight (sampleDesign group arm z) t.2.1 t.1 ^ 2 * (armGroupEvent group arm t.2.1 t.1).indicator (fun _ => (1 : Real)) (z t.2.2) ∂(Measure.pi (fun _ : Fin n => mu)) := by have hdiag := integral_designWeight_residual_sq_le_indicator mu group arm Y center V hgroup harm hY hmem hsq (fun d => weight d t.2.1 t.1 ^ 2) (fun d => sq_nonneg _) t.2.2 t.2.1 t.1 simpa [term, pow_two, mul_assoc, mul_left_comm, mul_comm] using hdiag have hsum_bound : (∑ t : kappa × Bool × Fin n, ∑ u : kappa × Bool × Fin n, ∫ z, term t z * term u z ∂(Measure.pi (fun _ : Fin n => mu))) ≤ ∑ t : kappa × Bool × Fin n, V ^ 2 * ∫ z, weight (sampleDesign group arm z) t.2.1 t.1 ^ 2 * (armGroupEvent group arm t.2.1 t.1).indicator (fun _ => (1 : Real)) (z t.2.2) ∂(Measure.pi (fun _ : Fin n => mu)) := by apply Finset.sum_le_sum intro t ht calc (∑ u : kappa × Bool × Fin n, ∫ z, term t z * term u z ∂(Measure.pi (fun _ : Fin n => mu))) = ∫ z, term t z * term t z ∂(Measure.pi (fun _ : Fin n => mu)) := by rw [Finset.sum_eq_single t] · intro u hu hut exact hpair_zero t u hut · simp _ ≤ _ := hdiagonal t have hbound_nonneg : 0 ≤ bound := by dsimp [bound] positivity have hindicator_integrable (t : kappa × Bool × Fin n) : Integrable (fun z : Fin n → Omega => weight (sampleDesign group arm z) t.2.1 t.1 ^ 2 * (armGroupEvent group arm t.2.1 t.1).indicator (fun _ => (1 : Real)) (z t.2.2)) (Measure.pi (fun _ : Fin n => mu)) := by have hw : Measurable (fun d : Fin n → kappa × Bool => weight d t.2.1 t.1) := Measurable.of_discrete have hi : Measurable (fun z : Fin n → Omega => (armGroupEvent group arm t.2.1 t.1).indicator (fun _ => (1 : Real)) (z t.2.2)) := ((measurable_const : Measurable (fun _ : Omega => (1 : Real))).indicator (measurableSet_armGroupEvent group arm hgroup harm t.2.1 t.1)).comp (measurable_pi_apply t.2.2) apply Integrable.of_bound (((hw.comp (measurable_sampleDesign group arm hgroup harm)).pow measurable_const).mul hi).aestronglyMeasurable (bound ^ 2) filter_upwards [] with z change ‖weight (sampleDesign group arm z) t.2.1 t.1 ^ 2 * (armGroupEvent group arm t.2.1 t.1).indicator (fun _ => (1 : Real)) (z t.2.2)‖ ≤ bound ^ 2 have hwabs := hweight_bound (sampleDesign group arm z) t.2.1 t.1 have hwsq : weight (sampleDesign group arm z) t.2.1 t.1 ^ 2 ≤ bound ^ 2 := by exact (sq_le_sq).2 (by simpa [abs_of_nonneg hbound_nonneg] using hwabs) by_cases hz : z t.2.2 ∈ armGroupEvent group arm t.2.1 t.1 · rw [Set.indicator_of_mem hz, mul_one, Real.norm_eq_abs, abs_of_nonneg (sq_nonneg (weight (sampleDesign group arm z) t.2.1 t.1))] exact hwsq · simp [Set.indicator_of_notMem hz, sq_nonneg bound] have hsum_integral : (∑ t : kappa × Bool × Fin n, V ^ 2 * ∫ z, weight (sampleDesign group arm z) t.2.1 t.1 ^ 2 * (armGroupEvent group arm t.2.1 t.1).indicator (fun _ => (1 : Real)) (z t.2.2) ∂(Measure.pi (fun _ : Fin n => mu))) = V ^ 2 * ∫ z, occupancyDesignVarianceFactor group arm z ∂(Measure.pi (fun _ : Fin n => mu)) := by rw [← Finset.mul_sum] congr 1 rw [← integral_finsetSum univ] · apply integral_congr_ae filter_upwards [] with z exact sum_occupancyResidualWeight_sq_indicator_eq_factor group arm z · intro t ht exact hindicator_integrable t have hdesign := integral_occupancyDesignVarianceFactor_le_reciprocal (n := n) mu group arm hgroup harm epsilon hepsilon hepsilon_half hoverlap calc (∫ z : Fin n -> Omega, (occupancyWeightedResidual mu group arm Y center z) ^ 2 ∂(Measure.pi (fun _ : Fin n => mu))) = ∫ z : Fin n → Omega, ∑ t : kappa × Bool × Fin n, ∑ u : kappa × Bool × Fin n, term t z * term u z ∂(Measure.pi (fun _ : Fin n => mu)) := by apply integral_congr_ae filter_upwards [] with z rw [hresidual_sum z, pow_two, Finset.sum_mul] simp_rw [Finset.mul_sum] _ = ∑ t : kappa × Bool × Fin n, ∫ z : Fin n → Omega, ∑ u : kappa × Bool × Fin n, term t z * term u z ∂(Measure.pi (fun _ : Fin n => mu)) := by apply integral_finsetSum intro t ht exact integrable_finsetSum univ fun u hu => hpair_integrable t u _ = ∑ t : kappa × Bool × Fin n, ∑ u : kappa × Bool × Fin n, ∫ z : Fin n → Omega, term t z * term u z ∂(Measure.pi (fun _ : Fin n => mu)) := by apply Finset.sum_congr rfl intro t ht apply integral_finsetSum intro u hu exact hpair_integrable t u -- … truncated; follow the source link for the rest …
1 supporting declaration (lemmas, instances)
  • occupancyWeightedResidual_memLp_two theorem — If group labels, arm labels, and outcomes are measurable and every arm/group-supported residual has a finite second moment, the zero-safe occupancy-weighted residual has a finite second moment under every finite independent product sample.
    n :
    group :
    Omega -> kappa
    arm :
    Omega -> Bool
    Y :
    Omega -> Real
    center :
    Bool -> kappa -> Real
    hgroup :
    harm :
    hY :
    hmem :
    ∀ a k, MemLp (supportedArmGroupResidual group arm Y center a k) 2 mu
    MemLp (occupancyWeightedResidual (n := n) mu group arm Y center) 2 (Measure.pi (fun _ : Fin n => mu))
    Proof (Lean source)
    theorem occupancyWeightedResidual_memLp_two {n : Nat} (mu : Measure Omega) [IsProbabilityMeasure mu] (group : Omega -> kappa) (arm : Omega -> Bool) (Y : Omega -> Real) (center : Bool -> kappa -> Real) (hgroup : Measurable group) (harm : Measurable arm) (hY : Measurable Y) (hmem : ∀ a k, MemLp (supportedArmGroupResidual group arm Y center a k) 2 mu) : MemLp (occupancyWeightedResidual (n := n) mu group arm Y center) 2 (Measure.pi (fun _ : Fin n => mu)) := by -- Expand the statistic as a finite sum of supported residual coordinates. -- Its design coefficients range over a finite set, hence are bounded; -- close under finite sums and bounded scalar multiplication in `MemLp`. classical let weight : (Fin n → kappa × Bool) → Bool → kappa → Real := occupancyResidualWeight let bound : Real := ∑ d : Fin n → kappa × Bool, ∑ a : Bool, ∑ k : kappa, |weight d a k| have hweight_bound (d : Fin n → kappa × Bool) (a : Bool) (k : kappa) : |weight d a k| ≤ bound := by dsimp [bound] calc |weight d a k| ≤ ∑ k' : kappa, |weight d a k'| := Finset.single_le_sum (fun k' _ => abs_nonneg (weight d a k')) (Finset.mem_univ k) _ ≤ ∑ a' : Bool, ∑ k' : kappa, |weight d a' k'| := Finset.single_le_sum (fun a' _ => sum_nonneg fun k' _ => abs_nonneg (weight d a' k')) (Finset.mem_univ a) _ ≤ ∑ d' : Fin n → kappa × Bool, ∑ a' : Bool, ∑ k' : kappa, |weight d' a' k'| := Finset.single_le_sum (fun d' _ => sum_nonneg fun a' _ => sum_nonneg fun k' _ => abs_nonneg (weight d' a' k')) (Finset.mem_univ d) have hterm (i : Fin n) (a : Bool) (k : kappa) : MemLp (fun z : Fin n → Omega => weight (sampleDesign group arm z) a k * supportedArmGroupResidual group arm Y center a k (z i)) 2 (Measure.pi (fun _ : Fin n => mu)) := by have hr := (hmem a k).comp_measurePreserving (measurePreserving_eval (fun _ : Fin n => mu) i) have hw : Measurable (fun d : Fin n → kappa × Bool => weight d a k) := Measurable.of_discrete apply hr.of_le_mul · have hm : AEStronglyMeasurable (((fun d : Fin n → kappa × Bool => weight d a k) ∘ sampleDesign group arm) * (supportedArmGroupResidual group arm Y center a k ∘ fun z => z i)) (Measure.pi (fun _ : Fin n => mu)) := ((hw.comp (measurable_sampleDesign group arm hgroup harm)).mul ((measurable_supportedArmGroupResidual group arm Y center hgroup harm hY a k).comp (measurable_pi_apply i))).aestronglyMeasurable refine hm.congr ?_ filter_upwards [] with z rfl · filter_upwards [] with z rw [Real.norm_eq_abs, Real.norm_eq_abs, abs_mul] exact mul_le_mul_of_nonneg_right (hweight_bound _ _ _) (abs_nonneg _) have hsum : MemLp (fun z : Fin n → Omega => ∑ k : kappa, ∑ a : Bool, ∑ i : Fin n, weight (sampleDesign group arm z) a k * supportedArmGroupResidual group arm Y center a k (z i)) 2 (Measure.pi (fun _ : Fin n => mu)) := by exact memLp_finsetSum univ fun k _ => memLp_finsetSum univ fun a _ => memLp_finsetSum univ fun i _ => hterm i a k convert hsum using 1 funext z unfold occupancyWeightedResidual dsimp [weight, occupancyResidualWeight] change (if 0 < usableGroupTotal group arm z then (usableGroupTotal group arm z : Real)⁻¹ * ∑ k, if usableGroup group arm z k then (groupCount group arm z k : Real) * (armResidualMean group arm Y center z true k - armResidualMean group arm Y center z false k) else 0 else 0) = ∑ k : kappa, ∑ a : Bool, ∑ i : Fin n, (if 0 < usableGroupTotal group arm z then (usableGroupTotal group arm z : Real)⁻¹ * if usableGroup group arm z k then (groupCount group arm z k : Real) * (if a then (groupArmCount group arm z true k : Real)⁻¹ else -(groupArmCount group arm z false k : Real)⁻¹) else 0 else 0) * supportedArmGroupResidual group arm Y center a k (z i) split_ifs with htotal · rw [Finset.mul_sum] apply Finset.sum_congr rfl intro k hk by_cases huk : usableGroup group arm z k · have hf : 0 < groupArmCount group arm z false k := huk.1 have ht : 0 < groupArmCount group arm z true k := huk.2 simp only [huk, if_pos, Fintype.sum_bool, armResidualMean, armResidualSum, hf, ht] simp only [Bool.false_eq_true, if_false] rw [mul_sub] simp_rw [Finset.mul_sum] ring_nf simp_rw [Finset.mul_sum] rw [Finset.sum_neg_distrib] ring_nf · simp [huk] · simp
    Causalean.Stat.occupancyWeightedResidual_memLp_two · Causalean/Stat/Sample/OccupancyWeightedMean/Variance.lean:156