Stat.Sample
Sampling primitives: iid samples as measurable maps with their product-law identities.
Sample 3 core · 0 supporting This file provides the library's causal-agnostic model of an independent and identically distributed sample on a common ambient probability space. ★ map_eq
I.i.d. Samples
This file provides the library's causal-agnostic model of an independent and identically distributed sample on a common ambient probability space. It also defines sample means of real-valued statistics along the first sample points, supplying the base object used by the limit and inference modules.
An independent and identically distributed sample with marginal law P, realized as a sequence of sample points given by measurable maps on a single ambient probability space: the family is mutually independent, identically distributed, and the law of each point is the population law P.
Definition (Lean source)
Sample mean of a real-valued statistic f along the sample's first n points: (1/n) Σ_{i < n} f (Z i ω).
For an i.i.d. sample S and any sample index i, the pushforward law of the i-th sample point equals the population law P.
Formal statement
CollisionEstimator 4 core · 0 supporting This module defines an ordered-pair collision estimator for inverse-frequency functionals, together with cell-weighted moments and cross-sample averages for observations equipped with an explicit projection to their cell
Collision and cross-sample estimators
This module defines an ordered-pair collision estimator for inverse-frequency functionals, together with cell-weighted moments and cross-sample averages for observations equipped with an explicit projection to their cell labels.
The collision kernel contributes the inverse mass of a cell when two observations have the same label and zero otherwise.
Definition (Lean source)
The collision scale averages inverse-frequency collisions over distinct ordered pairs in a sample.
Definition (Lean source)
A cell moment is the sample average of a statistic within one projected cell, rescaled by that cell's inverse population frequency.
Definition (Lean source)
A cross-sample average evaluates source-sample cell moments at every target observation and averages the resulting values over the target sample.
Definition (Lean source)
EffectiveSampleSize 3 core · 2 supporting This module develops the empirical second-moment statistic used for weighted i.i.d. ★ empiricalKishDispersion_mean★ empiricalKishDispersion_lower_tail_le
Kish dispersion and effective sample size
This module develops the empirical second-moment statistic used for weighted i.i.d. samples. When weights have population mean one, their second moment is the Kish design effect; dividing the nominal sample size by this design effect gives the effective sample size. The results below establish its mean, a variance bound under a fourth-moment envelope, and a lower-tail bound.
Empirical Kish dispersion is the sample average of the squared observation-level weights.
Definition (Lean source)
Expected empirical Kish dispersion. Given a positive sample size and an integrable squared weight statistic under the population measure, the expectation of the empirical Kish dispersion — the sample average of the squared observation-level weights — under the -fold product sampling measure equals the population second moment .
Formal statement
Proof (Lean source)
Lower-tail bound for empirical Kish dispersion. Given a positive sample size , a positive population Kish dispersion , the empirical Kish dispersion is square-integrable under the sampling measure Q, its expectation under Q equals , and its variance under Q is at most for a weight envelope , then the probability that the empirical Kish dispersion falls below half its mean is at most .
Formal statement
Proof (Lean source)
2 supporting declarations (lemmas, instances)
-
one_le_secondMoment_of_mean_onelemma — A mean-one square-integrable weight has second moment at least one, so its Kish design effect cannot improve on an equally weighted sample.hypothesesconclusion1 ≤ ∫ x, w x ^ 2 ∂μProof (Lean source)
lemma one_le_secondMoment_of_mean_one {𝒳 : Type*} [MeasurableSpace 𝒳] (μ : Measure 𝒳) [IsProbabilityMeasure μ] (w : 𝒳 → ℝ) (hw : MemLp w 2 μ) (hmean : (∫ x, w x ∂μ) = 1) : 1 ≤ ∫ x, w x ^ 2 ∂μ := by have hv := variance_nonneg w μ rw [variance_eq_sub hw, hmean] at hv norm_num at hv ⊢ linarith -
empiricalKishDispersion_variance_lelemma — If the fourth power of a weight is bounded by four times a squared envelope times its second power, empirical Kish dispersion has variance at most four times the squared envelope and the population second moment, divided by sample size.hypothesesΩ :Type*μ :g :Ω → ℝn :ℕk kappa :ℝhn :0 < nhF :MemLp (fun o => g o ^ 2) 2 μhkappa :(∫ o, g o ^ 2 ∂μ) = kappahfourth :∀ᵐ o ∂μ, g o ^ 4 ≤ 4 * k ^ 2 * g o ^ 2conclusionvariance (fun sample : Fin n → Ω => empiricalKishDispersion g n sample) (Measure.pi (fun _ : Fin n => μ))≤ 4 * k ^ 2 * kappa / nProof (Lean source)
lemma empiricalKishDispersion_variance_le {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (g : Ω → ℝ) (n : ℕ) (k kappa : ℝ) (hn : 0 < n) (hF : MemLp (fun o => g o ^ 2) 2 μ) (hkappa : (∫ o, g o ^ 2 ∂μ) = kappa) (hfourth : ∀ᵐ o ∂μ, g o ^ 4 ≤ 4 * k ^ 2 * g o ^ 2) : variance (fun sample : Fin n → Ω => empiricalKishDispersion g n sample) (Measure.pi (fun _ : Fin n => μ)) ≤ 4 * k ^ 2 * kappa / n := by have hvar := iid_average_variance μ n (fun o => g o ^ 2) hF have hsingle : variance (fun o => g o ^ 2) μ ≤ 4 * k ^ 2 * kappa := by calc variance (fun o => g o ^ 2) μ ≤ ∫ o, (g o ^ 2) ^ 2 ∂μ := variance_le_expectation_sq hF.aestronglyMeasurable _ = ∫ o, g o ^ 4 ∂μ := by apply integral_congr_ae filter_upwards with o ring _ ≤ ∫ o, 4 * k ^ 2 * g o ^ 2 ∂μ := by have hleft : Integrable (fun o => g o ^ 4) μ := by have hpow : (fun o => g o ^ 4) = fun o => (g o ^ 2) ^ 2 := by funext o ring rw [hpow] exact hF.integrable_sq exact integral_mono_ae hleft (hF.integrable (by norm_num) |>.const_mul _) hfourth _ = 4 * k ^ 2 * kappa := by rw [integral_const_mul, hkappa] change variance (fun sample : Fin n → Ω => (n : ℝ)⁻¹ * ∑ i, g (sample i) ^ 2) (Measure.pi (fun _ : Fin n => μ)) ≤ _ rw [hvar] calc (n : ℝ)⁻¹ * variance (fun o => g o ^ 2) μ ≤ (n : ℝ)⁻¹ * (4 * k ^ 2 * kappa) := by gcongr _ = 4 * k ^ 2 * kappa / n := by ring
EmpiricalMass 3 core · 1 supporting This module defines the empirical frequency of one point in a finite i.i.d. ★ integral_empiricalMass★ integral_empiricalMass_sq
Empirical mass of a point
This module defines the empirical frequency of one point in a finite i.i.d. sample and establishes its range, expectation, and second moment.
The empirical mass of a point is the fraction of sample observations equal to that point.
Definition (Lean source)
Expected empirical mass. Given a positive sample size and a measurable singleton {a}, the expectation, under the -fold product sampling measure, of the empirical mass of the point a — the fraction of sample observations equal to a — equals the population probability of {a}.
Formal statement
Proof (Lean source)
Second moment of the empirical mass. Given a positive sample size and a measurable singleton {a}, the second moment, under the -fold product sampling measure, of the empirical mass of the point a equals the squared population probability of {a} plus the usual binomial sampling correction .
Formal statement
Proof (Lean source)
1 supporting declaration (lemmas, instances)
-
abs_empiricalMass_le_onelemma — The absolute empirical mass of any point is at most one, including for the empty sample.Proof (Lean source)
lemma abs_empiricalMass_le_one {N : ℕ} (sample : Fin N → 𝒳) (x : 𝒳) : |empiricalMass sample x| ≤ 1 := by by_cases hN : 0 < N · classical unfold empiricalMass have hcount_nonneg : 0 ≤ ∑ j : Fin N, if sample j = x then (1 : ℝ) else 0 := by positivity have hcount_le : ∑ j : Fin N, (if sample j = x then (1 : ℝ) else 0) ≤ N := by calc _ ≤ ∑ _j : Fin N, (1 : ℝ) := by apply Finset.sum_le_sum intro j hj split_ifs <;> norm_num _ = N := by simp have hNreal : 0 < (N : ℝ) := by exact_mod_cast hN rw [abs_of_nonneg (mul_nonneg (inv_nonneg.mpr hNreal.le) hcount_nonneg)] calc (N : ℝ)⁻¹ * ∑ j : Fin N, (if sample j = x then 1 else 0) ≤ (N : ℝ)⁻¹ * N := by gcongr _ = 1 := by field_simp · have hzero : N = 0 := Nat.eq_zero_of_not_pos hN subst N simp [empiricalMass]
PiTransport 4 core · 13 supporting This file proves that the joint observable of a finite independent identically distributed sample pushes the underlying probability measure forward to the corresponding finite product measure. ★ iidSample_finN_pushforward★ event_pullback_along_iidSample
Transport to Product Samples
This file proves that the joint observable of a finite independent identically distributed sample pushes the underlying probability measure forward to the corresponding finite product measure. It also transports high-probability events on product samples back to events on the original sample space.
Two further transports live here. First, forgetting part of an i.i.d. sample:
restricting a product sample to a sub-index (a cross-fitting fold, a sample
split, a Finset of coordinates) is measure preserving onto the product measure
over the sub-index, so integrals and pushforwards transport verbatim. Second,
the existence of an i.i.d. sample with a prescribed marginal, which is shown
to be equivalent to that marginal being a probability measure — i.e. to carry no
information at all.
The coordinate projections on an infinite product probability space form an i.i.d. sample with the common marginal law.
Definition (Lean source)
For an i.i.d. sample S and a fixed horizon n, the joint map of the first n sample points pushes μ forward to the product measure on Fin n → X.
Formal statement
Proof (Lean source)
Event transport along an IID sample (Fin n version). Given a measurable event E in the space of length-n outcome tuples whose product-measure probability under n independent copies of the population law is at least , the pullback of E along the joint observable built from the first n coordinates of the i.i.d. sample is a measurable event on the underlying sample space, with probability at least .
Proof (Lean source)
Existence of an i.i.d. sample with a given law: the assertion that some probability space carries an independent, identically distributed sample whose common marginal law is a given measure.
Definition (Lean source)
13 supporting declarations (lemmas, instances)
-
iidSample_finN_measurablelemma — The joint observable Ψ ω k = S.Z k ω is measurable Ω → (Fin n → X).hypothesesS :IIDSample Ω X μ Pn :ℕconclusionMeasurable (fun ω : Ω => fun k : Fin n => S.Z k ω)Proof (Lean source)
lemma iidSample_finN_measurable (S : IIDSample Ω X μ P) (n : ℕ) : Measurable (fun ω : Ω => fun k : Fin n => S.Z k ω) := measurable_pi_lambda _ (fun k => S.meas k) -
measurePreserving_pi_restrict_deptheorem — Dropping the coordinates outside a decidable sub-index of a product of probability measures leaves the product measure over that sub-index: the retained coordinates carry exactly their own product law, with no trace of the discarded ones.hypothesesX :ι → Type*∀ i, MeasurableSpace (X i)μ :∀ i, Measure (X i)∀ i, IsProbabilityMeasure (μ i)p :ι → PropconclusionMeasurePreserving (fun (s : ∀ i, X i) (i : Subtype p) => s i.1) (Measure.pi μ) (Measure.pi fun i : Subtype p => μ i.1)Proof (Lean source)
theorem measurePreserving_pi_restrict_dep {X : ι → Type*} [∀ i, MeasurableSpace (X i)] (μ : ∀ i, Measure (X i)) [∀ i, IsProbabilityMeasure (μ i)] (p : ι → Prop) [DecidablePred p] : MeasurePreserving (fun (s : ∀ i, X i) (i : Subtype p) => s i.1) (Measure.pi μ) (Measure.pi fun i : Subtype p => μ i.1) := by have hsplit := MeasureTheory.measurePreserving_piEquivPiSubtypeProd (μ := μ) p have hfst : MeasurePreserving fst ((Measure.pi fun i : Subtype p => μ i.1).prod (Measure.pi fun i : Subtype (fun i => ¬ p i) => μ i.1)) (Measure.pi fun i : Subtype p => μ i.1) := measurePreserving_fst simpa [MeasurableEquiv.piEquivPiSubtypeProd, Function.comp_def] using hfst.comp hsplit -
measurePreserving_pi_restricttheorem — Dropping the coordinates outside a decidable sub-index of an i.i.d. product sample leaves the i.i.d. product sample over that sub-index.hypothesesconclusionMeasurePreserving (fun (s : ι → X) (i : Subtype p) => s i.1) (Measure.pi fun _ : ι => μ) (Measure.pi fun _ : Subtype p => μ)Proof (Lean source)
theorem measurePreserving_pi_restrict {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ] (p : ι → Prop) [DecidablePred p] : MeasurePreserving (fun (s : ι → X) (i : Subtype p) => s i.1) (Measure.pi fun _ : ι => μ) (Measure.pi fun _ : Subtype p => μ) := measurePreserving_pi_restrict_dep (fun _ : ι => μ) p -
map_pi_restricttheorem — The law of the sub-index coordinates of an i.i.d. product sample is the product law over that sub-index; this is the pushforward packaging of the measure-preserving statement.hypothesesProof (Lean source)
theorem map_pi_restrict {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ] (p : ι → Prop) [DecidablePred p] : (Measure.pi fun _ : ι => μ).map (fun (s : ι → X) (i : Subtype p) => s i.1) = Measure.pi fun _ : Subtype p => μ := (measurePreserving_pi_restrict μ p).map_eq -
integral_comp_pi_restricttheorem — Averaging a function of the sub-index coordinates over the whole i.i.d. product sample is the same as averaging it over an i.i.d. product sample indexed by the sub-index alone.hypothesesProof (Lean source)
theorem integral_comp_pi_restrict {X E : Type*} [MeasurableSpace X] [NormedAddCommGroup E] [NormedSpace ℝ E] (μ : Measure X) [IsProbabilityMeasure μ] (p : ι → Prop) [DecidablePred p] (g : (Subtype p → X) → E) : ∫ s : ι → X, g (fun i : Subtype p => s i.1) ∂(Measure.pi fun _ : ι => μ) = ∫ z, g z ∂(Measure.pi fun _ : Subtype p => μ) := by classical have hmeasf : Measurable (fun (s : ι → X) (i : Subtype p) => s i.1) := measurable_pi_lambda _ fun i => measurable_pi_apply i.1 by_cases hg : AEStronglyMeasurable g (Measure.pi fun _ : Subtype p => μ) · have hmap := integral_map (f := g) hmeasf.aemeasurable (by rwa [map_pi_restrict μ p]) rw [map_pi_restrict μ p] at hmap exact hmap.symm · rw [integral_undef (fun h => hg h.aestronglyMeasurable), integral_undef fun h => hg ?_] -- Transport `L⁰`-measurability back across the product splitting. have hsplit := MeasureTheory.measurePreserving_piEquivPiSubtypeProd (μ := fun _ : ι => μ) p have hcomp := h.aestronglyMeasurable.comp_measurePreserving (hsplit.symm (MeasurableEquiv.piEquivPiSubtypeProd (fun _ : ι => X) p)) rw [show (fun s : ι → X => g fun i : Subtype p => s i.1) ∘ ⇑(MeasurableEquiv.piEquivPiSubtypeProd (fun _ : ι => X) p).symm = fun w => g w.1 by funext w simp only [Function.comp_apply] refine congrArg g ?_ funext i simp [MeasurableEquiv.piEquivPiSubtypeProd, Equiv.piEquivPiSubtypeProd, i.2]] at hcomp exact AEStronglyMeasurable.of_comp_fst hcomp (IsProbabilityMeasure.ne_zero _) -
measurePreserving_pi_restrict_finsettheorem — Dropping the coordinates outside a finite set of indices of an i.i.d. product sample leaves the i.i.d. product sample indexed by that finite set.hypothesesconclusionMeasurePreserving (fun (s : ι → X) (i : {i : ι // i ∈ S}) => s i.1) (Measure.pi fun _ : ι => μ) (Measure.pi fun _ : {i : ι // i ∈ S} => μ)Proof (Lean source)
theorem measurePreserving_pi_restrict_finset {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ] (S : Finset ι) : MeasurePreserving (fun (s : ι → X) (i : {i : ι // i ∈ S}) => s i.1) (Measure.pi fun _ : ι => μ) (Measure.pi fun _ : {i : ι // i ∈ S} => μ) := by classical convert measurePreserving_pi_restrict μ (· ∈ S) using 2 -
map_pi_restrict_finsettheorem — The law of the coordinates in a finite index set of an i.i.d. product sample is the product law over that finite set; this is the pushforward packaging of the measure-preserving statement.hypothesesconclusion(Measure.pi fun _ : ι => μ).map (fun (s : ι → X) (i : {i : ι // i ∈ S}) => s i.1)= Measure.pi fun _ : {i : ι // i ∈ S} => μProof (Lean source)
theorem map_pi_restrict_finset {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ] (S : Finset ι) : (Measure.pi fun _ : ι => μ).map (fun (s : ι → X) (i : {i : ι // i ∈ S}) => s i.1) = Measure.pi fun _ : {i : ι // i ∈ S} => μ := (measurePreserving_pi_restrict_finset μ S).map_eq -
integral_comp_pi_restrict_finsettheorem — Averaging a function of the coordinates in a finite index set over the whole i.i.d. product sample is the same as averaging it over an i.i.d. product sample indexed by that finite set.hypothesesconclusion∫ s : ι → X, g (fun i : {i : ι // i ∈ S} => s i.1) ∂(Measure.pi fun _ : ι => μ)= ∫ z, g z ∂(Measure.pi fun _ : {i : ι // i ∈ S} => μ)Proof (Lean source)
theorem integral_comp_pi_restrict_finset {X E : Type*} [MeasurableSpace X] [NormedAddCommGroup E] [NormedSpace ℝ E] (μ : Measure X) [IsProbabilityMeasure μ] (S : Finset ι) (g : ({i : ι // i ∈ S} → X) → E) : ∫ s : ι → X, g (fun i : {i : ι // i ∈ S} => s i.1) ∂(Measure.pi fun _ : ι => μ) = ∫ z, g z ∂(Measure.pi fun _ : {i : ι // i ∈ S} => μ) := by classical convert integral_comp_pi_restrict μ (· ∈ S) g using 2 congr 1 exact Subsingleton.elim _ _ -
hasIIDSample_of_isProbabilityMeasuretheorem — An i.i.d. sample with a given law always exists: every probability measure is the common marginal of some independent, identically distributed sample, realised on the infinite product space by the coordinate projections.hypothesesX :Type uP :conclusionProof (Lean source)
theorem hasIIDSample_of_isProbabilityMeasure {X : Type u} [MeasurableSpace X] (P : Measure X) [IsProbabilityMeasure P] : HasIIDSample P := ⟨ℕ → X, inferInstance, Measure.infinitePi fun _ : ℕ => P, ⟨iidSample_infinitePi P⟩⟩ -
hasIIDSample_iff_isProbabilityMeasuretheorem — The existence of an i.i.d. sample with a prescribed common marginal is equivalent to that marginal being a probability measure.Proof (Lean source)
theorem hasIIDSample_iff_isProbabilityMeasure {X : Type u} [MeasurableSpace X] (P : Measure X) : HasIIDSample P ↔ IsProbabilityMeasure P := by refine ⟨?_, fun _ => hasIIDSample_of_isProbabilityMeasure P⟩ rintro ⟨Ω, mΩ, μ, ⟨S⟩⟩ haveI : IsProbabilityMeasure μ := S.indep.isProbabilityMeasure rw [← S.map_eq 0] exact Measure.isProbabilityMeasure_map (S.meas 0).aemeasurable -
measurable_finCoordinatewisetheorem — Applying a measurable observation rule separately to every position of a finite sample produces a measurable recoded sample.hypothesesconclusionMeasurable (fun z : Fin n → X => fun i => phi (z i))Proof (Lean source)
theorem measurable_finCoordinatewise (n : ℕ) {phi : X → Y} (hphi : Measurable phi) : Measurable (fun z : Fin n → X => fun i => phi (z i)) := by exact measurable_pi_lambda _ fun i => hphi.comp (measurable_pi_apply i) -
map_pi_finCoordinatewisetheorem — Under a common probability law, applying a measurable observation rule coordinate by coordinate turns the finite product law into the finite product of the recoded marginal law.hypothesesProof (Lean source)
theorem map_pi_finCoordinatewise (n : ℕ) (mu : Measure X) [IsProbabilityMeasure mu] {phi : X → Y} (hphi : Measurable phi) : (Measure.pi (fun _ : Fin n => mu)).map (fun z : Fin n → X => fun i => phi (z i)) = Measure.pi (fun _ : Fin n => mu.map phi) := by let _ : IsProbabilityMeasure (mu.map phi) := Measure.isProbabilityMeasure_map hphi.aemeasurable exact Measure.pi_map_pi (fun _ : Fin n => hphi.aemeasurable) -
integral_comp_finCoordinatewisetheorem — Under a common probability law, if the observation rule is measurable and the real-valued statistic of the recoded sample is measurable, then its expectation after coordinatewise recoding equals its expectation under the product of the recoded marginal law.hypothesesProof (Lean source)
theorem integral_comp_finCoordinatewise (n : ℕ) (mu : Measure X) [IsProbabilityMeasure mu] {phi : X → Y} (hphi : Measurable phi) (g : (Fin n → Y) → ℝ) (hg : Measurable g) : (∫ z : Fin n → X, g (fun i => phi (z i)) ∂Measure.pi (fun _ : Fin n => mu)) = ∫ y, g y ∂Measure.pi (fun _ : Fin n => mu.map phi) := by let coord : (Fin n → X) → (Fin n → Y) := fun z i => phi (z i) have hcoord : Measurable coord := measurable_finCoordinatewise n hphi calc (∫ z : Fin n → X, g (fun i => phi (z i)) ∂Measure.pi (fun _ : Fin n => mu)) = ∫ y, g y ∂(Measure.pi (fun _ : Fin n => mu)).map coord := (integral_map hcoord.aemeasurable hg.aestronglyMeasurable).symm _ = ∫ y, g y ∂Measure.pi (fun _ : Fin n => mu.map phi) := by rw [map_pi_finCoordinatewise n mu hphi]