Stat.Bootstrap.EfronResampling
This directory provides the nonparametric bootstrap as an actual conditional resampling law: the empirical measure of a finite data vector, the product law for draws with replacement, exact finite representations and mom
Basic 4 core · 4 supporting This module defines the empirical distribution of a finite data vector, the product law of an equal-size sample drawn with replacement, and the pushforward bootstrap law of a statistic. ★ bootstrapLaw_isProbabilityMeasure
Efron bootstrap measures
This module defines the empirical distribution of a finite data vector, the product law of an equal-size sample drawn with replacement, and the pushforward bootstrap law of a statistic. The definitions follow Efron's nonparametric bootstrap literally: the resample coordinates are independent draws from the empirical distribution.
Given a data vector of length n, its empirical measure assigns mass 1/n to every indexed observation, counting repeated observations with their multiplicity.
Definition (Lean source)
Given a data vector, its Efron bootstrap resampling law is the finite product of its empirical measure, so its n coordinates are independent draws with replacement.
Given a real-valued sample statistic and observed data, the bootstrap law of the statistic is the pushforward of the Efron resampling law through that statistic.
Definition (Lean source)
Given a real-valued sample statistic and observed data, if the statistic is measurable and the data size is nonzero, its bootstrap law has total mass one.
Formal statement
Proof (Lean source)
4 supporting declarations (lemmas, instances)
-
empiricalMeasure_isProbabilityMeasuretheorem — For a data vector with nonzero length, its empirical measure has total mass one.hypothesesconclusionIsProbabilityMeasure (empiricalMeasure x)Proof (Lean source)
theorem empiricalMeasure_isProbabilityMeasure (x : Fin n → X) (hn : n ≠ 0) : IsProbabilityMeasure (empiricalMeasure x) := by exact finiteSampleMeasure_isProbabilityMeasure x (Nat.pos_of_ne_zero hn) -
instIsProbabilityMeasureinstance — Given a data vector whose length is known to be positive, its empirical measure is a probability measure.parametersinstancegiven byempiricalMeasure_isProbabilityMeasure x (NeZero.ne n) -
bootstrapResample_isProbabilityMeasuretheorem — For a data vector with nonzero length, the Efron resampling law has total mass one.hypothesesconclusionProof (Lean source)
theorem bootstrapResample_isProbabilityMeasure (x : Fin n → X) (hn : n ≠ 0) : IsProbabilityMeasure (bootstrapResample x) := by -- Proof plan: install `empiricalMeasure_isProbabilityMeasure x hn` locally and use -- Mathlib's `Measure.pi.instIsProbabilityMeasure`. let _ : IsProbabilityMeasure (empiricalMeasure x) := empiricalMeasure_isProbabilityMeasure x hn unfold bootstrapResample exact Measure.pi.instIsProbabilityMeasure (fun _ ↦ empiricalMeasure x) -
instIsProbabilityMeasureinstance — Given a data vector whose length is known to be positive, its Efron resampling law is a probability measure.
FiniteRepresentation 1 core · 1 supporting This module expands the product of empirical measures into the uniform atomic law on all index maps Fin n → Fin n. ★ bootstrapResample_eq_average_dirac
Finite atomic representation of the Efron bootstrap
This module expands the product of empirical measures into the uniform atomic law on all index
maps Fin n → Fin n. It also records the corresponding exact finite-average integration rule.
For a data vector, the Efron resampling law is the uniform atomic measure on all n^n index resamples, with duplicate data values retained through their index multiplicities.
Formal statement
Proof (Lean source)
1 supporting declaration (lemmas, instances)
-
integral_bootstrapResample_eq_averagetheorem — For a data vector and a measurable real function of a resample, its bootstrap expectation is the ordinary average over all index resamples.hypothesesProof (Lean source)
theorem integral_bootstrapResample_eq_average (x : Fin n → X) (f : (Fin n → X) → ℝ) (hf : Measurable f) : ∫ y, f y ∂bootstrapResample x = ((n : ℝ) ^ n)⁻¹ * ∑ j : Fin n → Fin n, f (x ∘ j) := by -- Proof plan: rewrite by `bootstrapResample_eq_average_dirac`, then use -- `integral_smul_measure`, `integral_finsetSum_measure`, and `integral_dirac'`. rw [bootstrapResample_eq_average_dirac, integral_smul_measure] rw [integral_finsetSum_measure] · simp only [integral_dirac' f _ hf.stronglyMeasurable, smul_eq_mul, ENNReal.toReal_inv, ENNReal.toReal_pow, ENNReal.toReal_natCast] · intro j hj exact integrable_dirac' hf.stronglyMeasurable (by simp)
IIDSampleLink 1 core · 0 supporting This module identifies Mathlib's variance of a statistic under the empirical measure of the first n observations with Causalean's existing plug-in empirical variance. ★ variance_empiricalMeasure_eq_empiricalVar
Empirical-measure variance and IIDSample.empiricalVar
This module identifies Mathlib's variance of a statistic under the empirical measure of the first
n observations with Causalean's existing plug-in empirical variance.
For an i.i.d. sample, a real statistic that is measurable, a sample size with nonzero length, and an outcome, the variance of the statistic under the empirical measure of the first observations equals the library's plug-in empirical variance.
Formal statement
Proof (Lean source)
Measurability 3 core · 5 supporting This module defines the data-dependent bootstrap CDF and lower quantile. ★ measurable_bootstrapLowerQuantile
Measurability of bootstrap distribution functions and quantiles
This module defines the data-dependent bootstrap CDF and lower quantile. The CDF is a finite average of measurable threshold indicators. Right-continuity reduces the quantile infimum to rational thresholds, yielding measurability as a function of the observed data.
Given a statistic, observed data, and a threshold, the bootstrap cumulative distribution value is the real mass that the bootstrap law assigns to (-∞,t].
Definition (Lean source)
Given a statistic, a quantile level, and observed data, the lower bootstrap quantile is the infimum of thresholds where the bootstrap CDF reaches that level.
Definition (Lean source)
For a statistic that is measurable, a nonzero sample size, and any real quantile level, the lower bootstrap quantile is measurable as a function of the data. Outside (0,1] the sInf convention makes the generalized inverse degenerate, but it remains measurable.
Formal statement
Proof (Lean source)
5 supporting declarations (lemmas, instances)
-
bootstrapCDF_eq_average_indicatorstheorem — For a statistic, observed data, and a threshold, if the statistic is measurable, the bootstrap CDF is the average of the threshold indicators over all index resamples.hypothesesconclusionProof (Lean source)
theorem bootstrapCDF_eq_average_indicators (T : (Fin n → X) → ℝ) (hT : Measurable T) (x : Fin n → X) (t : ℝ) : bootstrapCDF T x t = ((n : ℝ) ^ n)⁻¹ * ∑ j : Fin n → Fin n, if T (x ∘ j) ≤ t then 1 else 0 := by -- Proof plan: use `Measure.map_apply hT` on `Iic t`, rewrite the resampling measure by its -- atomic representation, and evaluate each Dirac mass; `hn` converts the ENNReal weight. classical unfold bootstrapCDF bootstrapLaw rw [Measure.map_apply hT measurableSet_Iic, bootstrapResample_eq_average_dirac, Measure.smul_apply, Measure.finsetSum_apply] simp only [Measure.dirac_apply' _ (hT measurableSet_Iic), smul_eq_mul] rw [ENNReal.toReal_mul, ENNReal.toReal_inv, ENNReal.toReal_pow, ENNReal.toReal_natCast] rw [ENNReal.toReal_sum (by intro j hj by_cases h : T (x ∘ j) ≤ t <;> simp [indicator, h])] congr 1 apply Finset.sum_congr rfl intro j hj by_cases h : T (x ∘ j) ≤ t <;> simp [indicator, h] -
measurable_bootstrapCDFtheorem — For a statistic that is measurable and a fixed threshold, the bootstrap CDF is measurable as a function of the data.hypothesesconclusionProof (Lean source)
theorem measurable_bootstrapCDF (T : (Fin n → X) → ℝ) (hT : Measurable T) (t : ℝ) : Measurable (fun x : Fin n → X ↦ bootstrapCDF T x t) := by -- Proof plan: rewrite by `bootstrapCDF_eq_average_indicators`; for fixed `j`, the map -- `x ↦ x ∘ j` is measurable coordinatewise, hence so is the threshold indicator. classical rw [show (fun x : Fin n → X ↦ bootstrapCDF T x t) = fun x ↦ ((n : ℝ) ^ n)⁻¹ * ∑ j : Fin n → Fin n, if T (x ∘ j) ≤ t then 1 else 0 by funext x exact bootstrapCDF_eq_average_indicators T hT x t] apply Measurable.const_mul apply Finset.measurable_sum Finset.univ intro j hj have hcomp : Measurable (fun x : Fin n → X ↦ x ∘ j) := by refine measurable_pi_iff.mpr fun i ↦ ?_ exact measurable_pi_apply (j i) exact Measurable.ite (measurableSet_le (hT.comp hcomp) measurable_const) measurable_const measurable_const -
bootstrapCDF_rightContinuoustheorem — For a statistic, observed data, and a threshold, if the statistic is measurable and the sample size is nonzero, the bootstrap CDF is right-continuous at that threshold.hypothesesconclusionProof (Lean source)
theorem bootstrapCDF_rightContinuous (T : (Fin n → X) → ℝ) (hT : Measurable T) (x : Fin n → X) (hn : n ≠ 0) (t : ℝ) : ContinuousWithinAt (bootstrapCDF T x) (Ici t) t := by -- Proof plan: install probability for `bootstrapLaw T x`, identify `bootstrapCDF` with -- `cdf` via `cdf_eq_real`, and use the Stieltjes CDF's `right_continuous`. let _ : IsProbabilityMeasure (bootstrapLaw T x) := bootstrapLaw_isProbabilityMeasure T x hn hT have hcdf : bootstrapCDF T x = cdf (bootstrapLaw T x) := by funext s unfold bootstrapCDF exact (ProbabilityTheory.cdf_eq_real (bootstrapLaw T x) s).symm rw [hcdf] exact (cdf (bootstrapLaw T x)).right_continuous t -
bootstrapLowerQuantile_eq_sInf_rattheorem — For a statistic, observed data, and a positive quantile level no greater than one, if the statistic is measurable and the sample size is nonzero, the lower bootstrap quantile can be computed by taking the infimum only over rational thresholds.hypothesesX :sharedType u_1n :sharedℕT :(Fin n → X) → ℝhT :x :Fin n → Xhn :n ≠ 0β :ℝhβ0 :0 < βhβ1 :β ≤ 1conclusionbootstrapLowerQuantile T β x= sInf ((fun q : ℚ ↦ (q : ℝ)) '' {q : ℚ | β ≤ bootstrapCDF T x (q : ℝ)})Proof (Lean source)
theorem bootstrapLowerQuantile_eq_sInf_rat (T : (Fin n → X) → ℝ) (hT : Measurable T) (x : Fin n → X) (hn : n ≠ 0) (β : ℝ) (hβ0 : 0 < β) (hβ1 : β ≤ 1) : bootstrapLowerQuantile T β x = sInf ((fun q : ℚ ↦ (q : ℝ)) '' {q : ℚ | β ≤ bootstrapCDF T x (q : ℝ)}) := by -- Proof plan: prove both candidate sets have the same greatest lower bound. Approximate any -- real candidate from above by rationals and pass the CDF inequality to the limit using -- `bootstrapCDF_rightContinuous`; `hβ0` bounds the sets below and `hβ1` plus finite support -- makes them nonempty. let A : Set ℝ := {t | β ≤ bootstrapCDF T x t} let B : Set ℝ := (fun q : ℚ ↦ (q : ℝ)) '' {q : ℚ | β ≤ bootstrapCDF T x (q : ℝ)} have hA_bdd : BddBelow A := bddBelow_bootstrapQuantileSet T hT x hn hβ0 have hA_ne : A.Nonempty := nonempty_bootstrapQuantileSet T hT x hn hβ1 have hBA : B ⊆ A := by intro y hy rcases hy with ⟨q, hq, rfl⟩ exact hq have hB_ne : B.Nonempty := by obtain ⟨a, ha⟩ := hA_ne obtain ⟨q, haq⟩ := exists_rat_gt a refine ⟨(q : ℝ), ⟨q, ?_, rfl⟩⟩ exact (bootstrapLowerQuantile_le_iff_aux T hT x hn β (q : ℝ) hβ0 hβ1).mp ((bootstrapLowerQuantile_le_iff_aux T hT x hn β a hβ0 hβ1).mpr ha |>.trans haq.le) have hB_bdd : BddBelow B := hA_bdd.mono hBA change sInf A = sInf B apply le_antisymm · exact le_csInf hB_ne fun b hb ↦ csInf_le hA_bdd (hBA hb) · apply le_csInf hA_ne intro a ha by_contra hnot have haB : a < sInf B := lt_of_not_ge hnot obtain ⟨q, haq, hqB⟩ := exists_rat_btwn haB have hqA : (q : ℝ) ∈ A := (bootstrapLowerQuantile_le_iff_aux T hT x hn β (q : ℝ) hβ0 hβ1).mp ((bootstrapLowerQuantile_le_iff_aux T hT x hn β a hβ0 hβ1).mpr ha |>.trans haq.le) have hqmem : (q : ℝ) ∈ B := ⟨q, hqA, rfl⟩ exact (not_le_of_gt hqB) (csInf_le hB_bdd hqmem) -
bootstrapLowerQuantile_le_ifftheorem — For a statistic, observed data, a positive quantile level no greater than one, and a threshold, if the statistic is measurable and the sample size is nonzero, a lower bootstrap quantile is at most that threshold exactly when the bootstrap CDF has reached the level there.hypothesesX :sharedType u_1n :sharedℕT :(Fin n → X) → ℝhT :x :Fin n → Xhn :n ≠ 0β t :ℝhβ0 :0 < βhβ1 :β ≤ 1conclusionbootstrapLowerQuantile T β x ≤ t ↔ β ≤ bootstrapCDF T x tProof (Lean source)
theorem bootstrapLowerQuantile_le_iff (T : (Fin n → X) → ℝ) (hT : Measurable T) (x : Fin n → X) (hn : n ≠ 0) (β t : ℝ) (hβ0 : 0 < β) (hβ1 : β ≤ 1) : bootstrapLowerQuantile T β x ≤ t ↔ β ≤ bootstrapCDF T x t := by -- Proof plan: the reverse direction is `csInf_le`; for the forward direction show the -- infimum attains the CDF level using right-continuity and upward closure. At `β = 1`, use -- the maximum of the finite set `T (x ∘ j)` to establish nonemptiness. exact bootstrapLowerQuantile_le_iff_aux T hT x hn β t hβ0 hβ1
Moments 1 core · 1 supporting This module computes the first moment of the bootstrap sample mean and the second moment of its square-root-n centered version. ★ integral_centered_finMean_sq_bootstrapResample
Exact bootstrap moments of the sample mean
This module computes the first moment of the bootstrap sample mean and the second moment of its
square-root-n centered version. Both identities are exact finite-sample statements.
For real data with nonzero length, the bootstrap second moment of the square-root-scaled centered resample mean equals the empirical centered second moment.
Formal statement
Proof (Lean source)
1 supporting declaration (lemmas, instances)
-
integral_finMean_bootstrapResampletheorem — For real data with nonzero length, the bootstrap expectation of the resample mean equals the original data mean.hypothesesProof (Lean source)
theorem integral_finMean_bootstrapResample (x : Fin n → ℝ) (hn : n ≠ 0) : ∫ y, finMean y ∂bootstrapResample x = finMean x := by let _ : IsProbabilityMeasure (empiricalMeasure x) := empiricalMeasure_isProbabilityMeasure x hn have hId : Integrable (fun z : ℝ => z) (empiricalMeasure x) := by unfold empiricalMeasure finiteSampleMeasure apply Integrable.smul_measure · rw [integrable_finsetSum_measure] intro i hi exact integrable_dirac' stronglyMeasurable_id (by simp) · simp [hn] rw [show bootstrapResample x = Measure.pi (fun _ : Fin n => empiricalMeasure x) by rfl] rw [show finMean = fun y : Fin n → ℝ => (n : ℝ)⁻¹ * ∑ i, id (y i) by funext y simp [finMean]] rw [iid_average_integral (empiricalMeasure x) n (Nat.pos_of_ne_zero hn) id hId] unfold empiricalMeasure rw [integral_finiteSampleMeasure x measurable_id] simp [one_div]