Stat.Quantile

Quantile processes: empirical quantiles, Bahadur representations, and joint sample-quantile asymptotics.

Sample­Quantile­Bahadur 7 core · 15 supporting · 3 submodules For an i.i.d. Atomic­Approximation 8 core · 5 supporting · 6 submodules Equally weighted atomic approximations of compactly supported finite real measures. Marked­Subsample­Empirical­CDF 18 core · 17 supporting · 4 submodules Uniform empirical-CDF confidence bands for one arm of an i.i.d.
Empirical­CDF 6 core · 14 supporting This file defines the empirical cumulative distribution function of a real i.i.d. ★ cdfIF_variance★ empiricalCDF_isAsymLinear★ empiricalCDF_tendsto_inProb

Empirical Distribution Functions

This file defines the empirical cumulative distribution function of a real i.i.d. sample and its pointwise influence function. It proves the boundedness, mean-zero, variance, weak-law, and asymptotic-linearity facts that support sample-quantile and quantile-treatment-effect inference.

def cdfStat reviewed
Causalean.Stat

For a real threshold, the lower-ray indicator statistic assigns one to each real-valued observation no greater than that threshold and zero to every other observation.

Definition (Lean source)
y :
ℝ
cdfStat y :
ℝ → ℝ
indicator (Iic y) (fun _ => (1 : ℝ))
def empiricalCDF reviewed
Causalean.Stat.IIDSample

For an independent and identically distributed real-valued sample and a real threshold, the empirical cumulative distribution function maps each nonnegative integer sample size and sample-space outcome to the average of the indicators that the first nn observations do not exceed that threshold.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
y :
ℝ
empiricalCDF S y :
ℕ → Ω → ℝ
S.sampleMean (cdfStat y)
Causalean.Stat.IIDSample.empiricalCDF · Causalean/Stat/Quantile/EmpiricalCDF.lean:107 · uses IIDSample
def cdfIF reviewed
Causalean.Stat

For a measure on the real line and a real threshold, the pointwise influence function of the cumulative distribution function assigns to an observation the lower-ray indicator at that threshold minus the measure-assigned cumulative value at that threshold.

Definition (Lean source)
P :
y :
ℝ
cdfIF P y :
ℝ → ℝ
fun z => cdfStat y z - cdf P y
lemma cdfIF_variance reviewed
Causalean.Stat

Variance of the empirical-cdf influence function. At a fixed threshold y, the population second moment of the cdf influence function equals F(y)(1 − F(y)), the Bernoulli variance of the indicator event {Z ≤ y}.

Formal statement
P :
shared
y :
ℝ
∫ z, (cdfIF P y z) ^ 2 ∂P = cdf P y * (1 - cdf P y)
Proof (Lean source)
lemma cdfIF_variance [IsProbabilityMeasure P] (y : ℝ) : ∫ z, (cdfIF P y z) ^ 2 ∂P = cdf P y * (1 - cdf P y) := by have hstat_int : Integrable (cdfStat y) P := integrable_cdfStat y -- `(1{·} − F)² = 1{·} − 2F·1{·} + F²` via idempotence of the indicator. have hexpand : (fun z => (cdfIF P y z) ^ 2) = (fun z => cdfStat y z - 2 * cdf P y * cdfStat y z + (cdf P y) ^ 2) := by funext z simp only [cdfIF] rw [show (cdfStat y z - cdf P y) ^ 2 = (cdfStat y z) ^ 2 - 2 * cdf P y * cdfStat y z + (cdf P y) ^ 2 from by ring, cdfStat_sq y z] have h1 : Integrable (fun z => cdfStat y z - 2 * cdf P y * cdfStat y z) P := by fun_prop rw [hexpand, integral_add h1 (integrable_const _), integral_sub hstat_int (hstat_int.const_mul (2 * cdf P y)), integral_const_mul] simp only [integral_cdfStat, integral_const, probReal_univ, one_smul] ring
Causalean.Stat.cdfIF_variance · Causalean/Stat/Quantile/EmpiricalCDF.lean:163 · uses cdfIF
lemma empiricalCDF_isAsymLinear reviewed
Causalean.Stat

Asymptotic linearity of the empirical cdf. For an i.i.d. real sample S at a fixed point y, the empirical cdf F̂ₙ(y) is asymptotically linear at F(y) with influence function cdfIF P y and an identically-zero remainder.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
y :
ℝ
IsAsymLinear (S.empiricalCDF y) (cdf P y) (cdfIF P y) S (fun m => range m) where mean_zero
Proof (Lean source)
lemma empiricalCDF_isAsymLinear (S : IIDSample Ω ℝ μ P) (y : ℝ) : IsAsymLinear (S.empiricalCDF y) (cdf P y) (cdfIF P y) S (fun m => range m) where mean_zero := cdfIF_mean_zero y finite_var := cdfIF_sq_integrable y remainder := by have hzero : (fun n (ω : Ω) => sqrt ((range n).card : ℝ) * (S.empiricalCDF y n ω - cdf P y) - (sqrt ((range n).card : ℝ))⁻¹ * ∑ i ∈ range n, cdfIF P y (S.Z i ω)) = (fun _ _ => (0 : ℝ)) := by funext n ω; rw [rescaledEmpiricalCDF_eq_normalizedSum S y n ω, sub_self] simpa only [hzero] using (isLittleOp_zero : IsLittleOp (fun _ (_ : Ω) => (0 : ℝ)) (fun _ => (1 : ℝ)) μ)
theorem empiricalCDF_tendsto_inProb reviewed
Causalean.Stat

Empirical-cdf consistency (WLLN). For an i.i.d. real sample S at a fixed point y, the empirical cdf F̂ₙ(y) converges to F(y) in probability.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
y :
ℝ
Modes.TendstoInProbability (fun _ : ℕ => μ) (S.empiricalCDF y) atTop (fun _ _ => cdf P y)
Proof (Lean source)
theorem empiricalCDF_tendsto_inProb (S : IIDSample Ω ℝ μ P) (y : ℝ) : Modes.TendstoInProbability (fun _ : ℕ => μ) (S.empiricalCDF y) atTop (fun _ _ => cdf P y) := by have h := S.sampleMean_tendsto_inProb (measurable_cdfStat y) (integrable_cdfStat y) rw [integral_cdfStat] at h exact h
14 supporting declarations (lemmas, instances)
Quantile 3 core · 7 supporting This file defines the lower quantile function of a real measure as the generalized inverse of its cumulative distribution function. ★ quantile_le_iff

Quantile Function

This file defines the lower quantile function of a real measure as the generalized inverse of its cumulative distribution function. It proves the basic order characterization that connects cumulative distribution functions and their quantiles away from the degenerate endpoints.

def quantileSet reviewed
Causalean.Stat

Given a measure on the real line and a real level, the super-level set of Mathlib's totalized cumulative-distribution function contains the real points where that function is at least the level.

Definition (Lean source)
μ :
shared
τ :
ℝ
quantileSet μ τ :
Set ℝ
{x : ℝ | τ ≤ cdf μ x}
Causalean.Stat.quantileSet · Causalean/Stat/Quantile/Quantile.lean:48
def quantile reviewed
Causalean.Stat

Given a measure on the real line and a real level, the lower generalized inverse of Mathlib's totalized cdf is the infimum of its super-level set at that level.

Definition (Lean source)
μ :
shared
τ :
ℝ
quantile μ τ :
ℝ
theorem quantile_le_iff reviewed
Causalean.Stat

Quantile / CDF Galois connection. For an interior probability level τ∈(0,1)\tau\in(0,1), the quantile of a real measure at level τ\tau is at most a point exactly when the CDF has reached τ\tau there.

Formal statement
μ :
shared
τ x :
ℝ
hτ0 :
0 < τ
hτ1 :
τ < 1
quantile μ τ ≤ x ↔ τ ≤ cdf μ x
Proof (Lean source)
theorem quantile_le_iff {τ x : ℝ} (hτ0 : 0 < τ) (hτ1 : τ < 1) : quantile μ τ ≤ x ↔ τ ≤ cdf μ x := ⟨le_cdf_of_quantile_le hτ1, quantile_le_of_le_cdf hτ0⟩
Causalean.Stat.quantile_le_iff · Causalean/Stat/Quantile/Quantile.lean:134 · uses quantile
7 supporting declarations (lemmas, instances)
  • quantileSet_up_closed lemma — If a point belongs to a quantile super-level set and a second point is no smaller, then the second point also belongs to that set.
    μ :
    shared
    τ x x' :
    ℝ
    hx :
    x ∈ quantileSet μ τ
    hxx' :
    x ≤ x'
    x' ∈ quantileSet μ τ
    Proof (Lean source)
    lemma quantileSet_up_closed {τ x x' : ℝ} (hx : x ∈ quantileSet μ τ) (hxx' : x ≤ x') : x' ∈ quantileSet μ τ := le_trans hx (monotone_cdf μ hxx')
    Causalean.Stat.quantileSet_up_closed · Causalean/Stat/Quantile/Quantile.lean:67
  • bddBelow_quantileSet lemma — At a strictly positive level, the quantile super-level set of a real measure is bounded below.
    μ :
    shared
    τ :
    ℝ
    hτ :
    0 < τ
    Proof (Lean source)
    lemma bddBelow_quantileSet {τ : ℝ} (hτ : 0 < τ) : BddBelow (quantileSet μ τ) := by obtain ⟨N, hN⟩ := Filter.eventually_atBot.mp ((tendsto_cdf_atBot μ).eventually_lt_const hτ) refine ⟨N, fun s hs => ?_⟩ by_contra hlt push Not at hlt exact absurd hs (not_le.mpr (hN s hlt.le))
    Causalean.Stat.bddBelow_quantileSet · Causalean/Stat/Quantile/Quantile.lean:74
  • nonempty_quantileSet lemma — At a level strictly below one, the quantile super-level set of a real measure is nonempty.
    μ :
    shared
    τ :
    ℝ
    hτ :
    τ < 1
    (quantileSet μ τ).Nonempty
    Proof (Lean source)
    lemma nonempty_quantileSet {τ : ℝ} (hτ : τ < 1) : (quantileSet μ τ).Nonempty := by obtain ⟨N, hN⟩ := Filter.eventually_atTop.mp ((tendsto_cdf_atTop μ).eventually_const_lt hτ) exact ⟨N, (hN N le_rfl).le⟩
    Causalean.Stat.nonempty_quantileSet · Causalean/Stat/Quantile/Quantile.lean:87
  • le_cdf_quantile lemma — Key membership lemma. At a level strictly below one, the CDF of a real measure at its lower quantile reaches that level.
    μ :
    shared
    τ :
    ℝ
    hτ1 :
    τ < 1
    τ ≤ cdf μ (quantile μ τ)
    Proof (Lean source)
    lemma le_cdf_quantile {τ : ℝ} (hτ1 : τ < 1) : τ ≤ cdf μ (quantile μ τ) := by set a := quantile μ τ with ha have hne : (quantileSet μ τ).Nonempty := nonempty_quantileSet hτ1 -- Every point strictly above the inf lies in the (up-closed) super-level set. have hgt : ∀ x, a < x → τ ≤ cdf μ x := by intro x hx obtain ⟨s, hs, hsx⟩ := exists_lt_of_csInf_lt hne hx exact quantileSet_up_closed hs hsx.le -- Right-continuity: cdf μ → cdf μ a along `𝓝[Ioi a] a`. have htends : Tendsto (cdf μ) (𝓝[Ioi a] a) (𝓝 (cdf μ a)) := ((cdf μ).right_continuous a).mono_left (nhdsWithin_mono a Ioi_subset_Ici_self) -- Along that filter we stay in the super-level set, so the limit dominates τ. have hev : ∀ᶠ x in 𝓝[Ioi a] a, τ ≤ cdf μ x := by filter_upwards [self_mem_nhdsWithin] with x hx using hgt x hx exact ge_of_tendsto htends hev
    Causalean.Stat.le_cdf_quantile · Causalean/Stat/Quantile/Quantile.lean:97
  • le_cdf_of_quantile_le lemma — Galois connection (one direction). If the level is below one and its quantile is at most a point, then the CDF at that point has reached the level.
    μ :
    shared
    τ x :
    ℝ
    hτ1 :
    τ < 1
    hx :
    quantile μ τ ≤ x
    τ ≤ cdf μ x
    Proof (Lean source)
    lemma le_cdf_of_quantile_le {τ x : ℝ} (hτ1 : τ < 1) (hx : quantile μ τ ≤ x) : τ ≤ cdf μ x := le_trans (le_cdf_quantile hτ1) (monotone_cdf μ hx)
    Causalean.Stat.le_cdf_of_quantile_le · Causalean/Stat/Quantile/Quantile.lean:119
  • quantile_le_of_le_cdf lemma — Galois connection (other direction). If the level is positive and the CDF at a point reaches that level, then the quantile is at most that point.
    μ :
    shared
    τ x :
    ℝ
    hτ0 :
    0 < τ
    hx :
    τ ≤ cdf μ x
    quantile μ τ ≤ x
    Proof (Lean source)
    lemma quantile_le_of_le_cdf {τ x : ℝ} (hτ0 : 0 < τ) (hx : τ ≤ cdf μ x) : quantile μ τ ≤ x := csInf_le (bddBelow_quantileSet hτ0) hx
    Causalean.Stat.quantile_le_of_le_cdf · Causalean/Stat/Quantile/Quantile.lean:126
  • quantile_mono lemma — If the lower level is positive, the upper level is below one, and the lower level is at most the upper, then the corresponding quantiles of a real measure are ordered.
    μ :
    shared
    τ τ' :
    ℝ
    hτ0 :
    0 < τ
    hτ'1 :
    τ' < 1
    hττ' :
    τ ≤ τ'
    quantile μ τ ≤ quantile μ τ'
    Proof (Lean source)
    lemma quantile_mono {τ τ' : ℝ} (hτ0 : 0 < τ) (hτ'1 : τ' < 1) (hττ' : τ ≤ τ') : quantile μ τ ≤ quantile μ τ' := quantile_le_of_le_cdf hτ0 (le_trans hττ' (le_cdf_quantile hτ'1))
    Causalean.Stat.quantile_mono · Causalean/Stat/Quantile/Quantile.lean:142
Empirical­Quantile 5 core · 4 supporting This file builds the sample quantile from the empirical measure of an i.i.d. ★ empiricalMeasure_cdf★ sampleQuantile_le_iff★ sampleQuantile_atom_bound

Empirical Measures and Sample Quantiles

This file builds the sample quantile from the empirical measure of an i.i.d. real sample. The central definitions are IIDSample.empiricalMeasure, the finite empirical probability measure, and IIDSample.sampleQuantile, the generalized inverse of that measure's cdf.

The main structural results are the cdf bridge IIDSample.empiricalMeasure_cdf, the switching relation IIDSample.sampleQuantile_le_iff, monotonicity of IIDSample.empiricalCDF in its real argument, and the atom bound IIDSample.sampleQuantile_atom_bound. Together these deterministic facts feed the derived Bahadur representation for the ordinary empirical sample quantile.

def empiricalMeasure reviewed
Causalean.Stat.IIDSample

For an independent and identically distributed real-valued sample, a nonnegative integer sample size, and a sample-space outcome, the empirical measure is the sum of point masses at the first nn observed values, multiplied by the reciprocal of nn; at sample size zero it is the zero measure.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
ω :
Ω
empiricalMeasure S n ω :
(n : ℝ≥0∞)⁻¹ • ∑ i ∈ range n, Measure.dirac (S.Z i ω)
Causalean.Stat.IIDSample.empiricalMeasure · Causalean/Stat/Quantile/EmpiricalQuantile.lean:60 · uses IIDSample
lemma empiricalMeasure_cdf reviewed
Causalean.Stat.IIDSample

cdf bridge. For a positive sample size nn, the cumulative distribution function of the empirical measure S.empiricalMeasure n ω built from an i.i.d. sample at outcome ω coincides pointwise, at every threshold y, with the empirical cdf S.empiricalCDF y n ω.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
hn :
0 < n
ω :
Ω
y :
ℝ
cdf (S.empiricalMeasure n ω) y = S.empiricalCDF y n ω
Proof (Lean source)
lemma IIDSample.empiricalMeasure_cdf (S : IIDSample Ω ℝ μ P) {n : ℕ} (hn : 0 < n) (ω : Ω) (y : ℝ) : cdf (S.empiricalMeasure n ω) y = S.empiricalCDF y n ω := by haveI := S.empiricalMeasure_isProbabilityMeasure hn ω rw [cdf_eq_real, S.empiricalMeasure_real_Iic hn ω y]
def sampleQuantile reviewed
Causalean.Stat.IIDSample

For an independent and identically distributed real-valued sample and a real quantile level, the sample quantile maps each nonnegative integer sample size and sample-space outcome to the lower generalized inverse, at that level, of the empirical cumulative distribution function.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
τ :
ℝ
sampleQuantile S τ :
ℕ → Ω → ℝ
fun n ω => quantile (S.empiricalMeasure n ω) τ
Causalean.Stat.IIDSample.sampleQuantile · Causalean/Stat/Quantile/EmpiricalQuantile.lean:118 · uses IIDSample
lemma sampleQuantile_le_iff reviewed
Causalean.Stat.IIDSample

Switching relation. For a positive sample size nn and an interior quantile level τ∈(0,1)\tau\in(0,1), the sample τ\tau-quantile q^n(τ)\hat q_n(\tau) is at most a given point x exactly when τ\tau is at most the empirical cdf at x.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
hn :
0 < n
ω :
Ω
τ :
ℝ
hτ0 :
0 < τ
hτ1 :
τ < 1
x :
ℝ
S.sampleQuantile τ n ω ≤ x ↔ τ ≤ S.empiricalCDF x n ω
Proof (Lean source)
lemma IIDSample.sampleQuantile_le_iff (S : IIDSample Ω ℝ μ P) {n : ℕ} (hn : 0 < n) (ω : Ω) {τ : ℝ} (hτ0 : 0 < τ) (hτ1 : τ < 1) (x : ℝ) : S.sampleQuantile τ n ω ≤ x ↔ τ ≤ S.empiricalCDF x n ω := by haveI := S.empiricalMeasure_isProbabilityMeasure hn ω rw [IIDSample.sampleQuantile, quantile_le_iff hτ0 hτ1, S.empiricalMeasure_cdf hn ω]
lemma sampleQuantile_atom_bound reviewed
Causalean.Stat.IIDSample

Local atom bound. If the population cdf is continuous on a closed neighborhood of the target quantile, the sample size is positive, and the quantile level is interior, then almost surely, whenever the sample quantile lies in the open neighborhood, its empirical-cdf overshoot is at most one observation.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
q₀ ρ :
ℝ
hcont :
ContinuousOn (fun y => cdf P y) (Icc (q₀ - ρ) (q₀ + ρ))
n :
ℕ
hn :
0 < n
τ :
ℝ
hτ0 :
0 < τ
hτ1 :
τ < 1
∀ᵐ ω ∂μ, S.sampleQuantile τ n ω ∈ Ioo (q₀ - ρ) (q₀ + ρ) → |S.empiricalCDF (S.sampleQuantile τ n ω) n ω
- τ|
≤ (n : ℝ)⁻¹
Proof (Lean source)
lemma IIDSample.sampleQuantile_atom_bound [IsProbabilityMeasure μ] (S : IIDSample Ω ℝ μ P) {q₀ ρ : ℝ} (hcont : ContinuousOn (fun y => cdf P y) (Icc (q₀ - ρ) (q₀ + ρ))) {n : ℕ} (hn : 0 < n) {τ : ℝ} (hτ0 : 0 < τ) (hτ1 : τ < 1) : ∀ᵐ ω ∂μ, S.sampleQuantile τ n ω ∈ Ioo (q₀ - ρ) (q₀ + ρ) → |S.empiricalCDF (S.sampleQuantile τ n ω) n ω - τ| ≤ (n : ℝ)⁻¹ := by -- Local continuity of the cdf makes each singleton in the open neighborhood null. haveI hP : IsProbabilityMeasure P := by rw [← S.law] exact isProbabilityMeasure_map (S.meas 0).aemeasurable have hsingleton : ∀ x ∈ Ioo (q₀ - ρ) (q₀ + ρ), P {x} = 0 := by intro x hx have hxnhds : Icc (q₀ - ρ) (q₀ + ρ) ∈ nhds x := by simpa using hx have hcx : ContinuousAt (fun y => cdf P y) x := hcont.continuousAt hxnhds have heq : P = (cdf P).measure := (measure_cdf P).symm rw [heq, StieltjesFunction.measure_singleton, ContinuousWithinAt.leftLim_eq hcx.continuousWithinAt, sub_self, ENNReal.ofReal_zero] -- Each coordinate has law `P`. have hlaw : ∀ i : ℕ, μ.map (S.Z i) = P := fun i => (S.identDist i).map_eq.symm.trans S.law -- Pairwise local distinctness follows from independence and the local singleton nullity. have hpair : ∀ i j : ℕ, i ≠ j → μ {ω | S.Z i ω = S.Z j ω ∧ S.Z i ω ∈ Ioo (q₀ - ρ) (q₀ + ρ)} = 0 := by intro i j hij have hind : IndepFun (S.Z i) (S.Z j) μ := S.indep.indepFun hij let A : Set (ℝ × ℝ) := {p | p.1 = p.2 ∧ p.1 ∈ Ioo (q₀ - ρ) (q₀ + ρ)} have hmeas : MeasurableSet A := (measurableSet_eq_fun measurable_fst measurable_snd).inter (measurableSet_Ioo.preimage measurable_fst) have hpre : {ω | S.Z i ω = S.Z j ω ∧ S.Z i ω ∈ Ioo (q₀ - ρ) (q₀ + ρ)} = (fun ω => (S.Z i ω, S.Z j ω)) ⁻¹' A := rfl rw [hpre, ← Measure.map_apply ((S.meas i).prodMk (S.meas j)) hmeas, (indepFun_iff_map_prod_eq_prod_map_map (S.meas i).aemeasurable (S.meas j).aemeasurable).mp hind, hlaw i, hlaw j, Measure.measure_prod_null hmeas] refine Filter.Eventually.of_forall (fun x => ?_) by_cases hx : x ∈ Ioo (q₀ - ρ) (q₀ + ρ) · have hsing : Prod.mk x ⁻¹' A = {x} := by ext y simp only [A, Set.mem_preimage, Set.mem_setOf_eq, Set.mem_singleton_iff] exact ⟨fun h => h.1.symm, fun h => ⟨h.symm, hx⟩⟩ change P (Prod.mk x ⁻¹' A) = 0 rw [hsing, hsingleton x hx] · have hempty : Prod.mk x ⁻¹' A = ∅ := by ext y simp only [A, Set.mem_preimage, Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] exact fun h => hx h.2 change P (Prod.mk x ⁻¹' A) = 0 rw [hempty, measure_empty] -- Assemble into one a.s. event with no ties whose common value is local. have hae : ∀ᵐ ω ∂μ, ∀ i ∈ (Finset.range n : Set ℕ), ∀ j ∈ (Finset.range n : Set ℕ), i ≠ j → ¬ (S.Z i ω = S.Z j ω ∧ S.Z i ω ∈ Ioo (q₀ - ρ) (q₀ + ρ)) := by rw [ae_ball_iff (Set.to_countable _)] intro i _ rw [ae_ball_iff (Set.to_countable _)] intro j _ by_cases hij : i = j · exact ae_of_all _ (fun ω hne => absurd hij hne) · rw [ae_iff] have heqset : {ω | ¬ (i ≠ j → ¬ (S.Z i ω = S.Z j ω ∧ S.Z i ω ∈ Ioo (q₀ - ρ) (q₀ + ρ)))} = {ω | S.Z i ω = S.Z j ω ∧ S.Z i ω ∈ Ioo (q₀ - ρ) (q₀ + ρ)} := by ext ω; simp [hij] rw [heqset, hpair i j hij] -- The empirical-cdf sum counts the sample points below the threshold. have hcard : ∀ (x : ℝ) (ω : Ω), ∑ i ∈ Finset.range n, cdfStat x (S.Z i ω) = (((Finset.range n).filter (fun i => S.Z i ω ≤ x)).card : ℝ) := by intro x ω rw [Finset.card_filter] push_cast refine Finset.sum_congr rfl (fun i _ => ?_) unfold cdfStat by_cases h : S.Z i ω ≤ x · rw [Set.indicator_of_mem (Set.mem_Iic.mpr h)]; simp [h] · rw [Set.indicator_of_notMem (by simpa using h)]; simp [h] have hnR : (0 : ℝ) < (n : ℝ) := by exact_mod_cast hn filter_upwards [hae] with ω haeω intro hq_local set q := S.sampleQuantile τ n ω with hq -- LOWER bound `τ ≤ F̂ₙ(q)` is deterministic (switching at `x = q`, reflexivity). have hlower : τ ≤ S.empiricalCDF q n ω := (S.sampleQuantile_le_iff hn ω hτ0 hτ1 q).mp (le_refl q) -- Strict switching: any `x < q` has `F̂ₙ(x) < τ`. have hstrict : ∀ x : ℝ, x < q → S.empiricalCDF x n ω < τ := by intro x hx by_contra hcon push_neg at hcon exact absurd ((S.sampleQuantile_le_iff hn ω hτ0 hτ1 x).mpr hcon) (not_le.mpr hx) -- Abbreviations for the three counts. set Cle : ℝ → Finset ℕ := fun x => (Finset.range n).filter (fun i => S.Z i ω ≤ x) with hCle set Clt : Finset ℕ := (Finset.range n).filter (fun i => S.Z i ω < q) with hClt set Ceq : Finset ℕ := (Finset.range n).filter (fun i => S.Z i ω = q) with hCeq -- `F̂ₙ(x) = (Cle x).card / n`. have hFcard : ∀ x : ℝ, S.empiricalCDF x n ω = (n : ℝ)⁻¹ * ((Cle x).card : ℝ) := by intro x rw [IIDSample.empiricalCDF, IIDSample.sampleMean, hcard x ω] -- `Cle q = Clt ∪ Ceq`, disjointly: `Zᵢ ≤ q ↔ Zᵢ < q ∨ Zᵢ = q`. have hdisj : Disjoint Clt Ceq := by rw [hClt, hCeq, Finset.disjoint_filter] intro i _ hlt heq; exact absurd heq (ne_of_lt hlt) have hunion : Cle q = Clt ∪ Ceq := by rw [hCle, hClt, hCeq, ← Finset.filter_or] refine Finset.filter_congr (fun i _ => ?_) exact ⟨fun h => h.lt_or_eq, fun h => h.elim le_of_lt le_of_eq⟩ have hcountsplit : (Cle q).card = Clt.card + Ceq.card := by rw [hunion, Finset.card_union_of_disjoint hdisj] -- Tie-free ⇒ at most one index equals `q`. have hCeq_le : Ceq.card ≤ 1 := by rw [Finset.card_le_one] intro a ha b hb rw [hCeq, mem_filter] at ha hb by_contra hab have hqlocalq : q ∈ Ioo (q₀ - ρ) (q₀ + ρ) := by simpa [hq] using hq_local exact haeω a (by simpa using ha.1) b (by simpa using hb.1) hab ⟨ha.2.trans hb.2.symm, by rw [ha.2]; exact hqlocalq⟩ -- Strict part: `(Clt.card : ℝ) ≤ n·τ`, via a threshold `x < q` with `Cle x = Clt`. have hClt_le : (Clt.card : ℝ) ≤ (n : ℝ) * τ := by rcases Finset.eq_empty_or_nonempty Clt with hempty | hne · rw [hempty, Finset.card_empty, Nat.cast_zero]; positivity · -- `m = max{Zᵢ : Zᵢ < q}`; choose threshold `x = m < q`, then `Cle m = Clt`. set T : Finset ℝ := Clt.image (fun i => S.Z i ω) with hT have hTne : T.Nonempty := hne.image _ set m : ℝ := T.max' hTne with hm have hmlt : m < q := by obtain ⟨a, haT, ham⟩ := Finset.mem_image.mp (T.max'_mem hTne) rw [hClt, mem_filter] at haT rw [hm, ← ham]; exact haT.2 have hCleq : Cle m = Clt := by rw [hCle, hClt] refine Finset.filter_congr (fun i hi => ?_) constructor · intro hle; exact lt_of_le_of_lt hle hmlt · intro hlt refine Finset.le_max' T _ ?_ rw [hT] exact Finset.mem_image.mpr ⟨i, by rw [hClt, mem_filter]; exact ⟨hi, hlt⟩, rfl⟩ have hlt2 : S.empiricalCDF m n ω < τ := hstrict m hmlt rw [hFcard m, hCleq] at hlt2 -- `(n)⁻¹ * card < τ` ⟹ `card < n·τ`. have hkey := (inv_mul_lt_iff₀ hnR).mp hlt2 linarith [hkey] -- Combine: `n·F̂ₙ(q) = (Cle q).card ≤ n·τ + 1`, so `F̂ₙ(q) ≤ τ + 1/n`. have hupper : S.empiricalCDF q n ω ≤ τ + (n : ℝ)⁻¹ := by rw [hFcard q, hcountsplit] push_cast rw [mul_add] have h1 : (n : ℝ)⁻¹ * (Clt.card : ℝ) ≤ τ := by rw [inv_mul_le_iff₀ hnR]; linarith [hClt_le] have h2 : (n : ℝ)⁻¹ * (Ceq.card : ℝ) ≤ (n : ℝ)⁻¹ := by have : (Ceq.card : ℝ) ≤ 1 := by exact_mod_cast hCeq_le nlinarith [inv_nonneg.mpr hnR.le, this] linarith rw [abs_le] exact ⟨by linarith [inv_nonneg.mpr hnR.le], by linarith⟩
Causalean.Stat.IIDSample.sampleQuantile_atom_bound · Causalean/Stat/Quantile/EmpiricalQuantile.lean:172 · uses IIDSample , empiricalCDF , sampleQuantile
4 supporting declarations (lemmas, instances)
  • empiricalMeasure_isProbabilityMeasure lemma — For 0 < n the empirical measure is a probability measure.
    Ω :
    Type u_1
    shared
    P :
    shared
    S :
    IIDSample Ω ℝ μ P
    n :
    ℕ
    hn :
    0 < n
    ω :
    Ω
    IsProbabilityMeasure (S.empiricalMeasure n ω)
    Proof (Lean source)
    lemma IIDSample.empiricalMeasure_isProbabilityMeasure (S : IIDSample Ω ℝ μ P) {n : ℕ} (hn : 0 < n) (ω : Ω) : IsProbabilityMeasure (S.empiricalMeasure n ω) := by constructor unfold IIDSample.empiricalMeasure rw [Measure.smul_apply, Measure.coe_finset_sum, Finset.sum_apply, smul_eq_mul] simp only [MeasureTheory.measure_univ, Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one] rw [ENNReal.inv_mul_cancel] · exact_mod_cast hn.ne' · exact ENNReal.natCast_ne_top n
    Causalean.Stat.IIDSample.empiricalMeasure_isProbabilityMeasure · Causalean/Stat/Quantile/EmpiricalQuantile.lean:68
  • empiricalMeasure_real_Iic lemma — The empirical measure and empirical CDF agree on lower rays: for an i.i.d. real sample, a positive sample size, an outcome, and a real threshold, the empirical mass of observations at or below the threshold equals the empirical CDF there.
    Ω :
    Type u_1
    shared
    P :
    shared
    S :
    IIDSample Ω ℝ μ P
    n :
    ℕ
    _hn :
    0 < n
    ω :
    Ω
    y :
    ℝ
    (S.empiricalMeasure n ω).real (Iic y) = S.empiricalCDF y n ω
    Proof (Lean source)
    lemma IIDSample.empiricalMeasure_real_Iic (S : IIDSample Ω ℝ μ P) {n : ℕ} (_hn : 0 < n) (ω : Ω) (y : ℝ) : (S.empiricalMeasure n ω).real (Iic y) = S.empiricalCDF y n ω := by unfold IIDSample.empiricalMeasure IIDSample.empiricalCDF IIDSample.sampleMean rw [Measure.real, Measure.smul_apply, Measure.coe_finset_sum, Finset.sum_apply, smul_eq_mul] simp only [Measure.dirac_apply' _ measurableSet_Iic] rw [ENNReal.toReal_mul, ENNReal.toReal_inv, ENNReal.toReal_natCast] congr 1 rw [ENNReal.toReal_sum (fun i _ => by by_cases h : S.Z i ω ∈ Iic y <;> simp [Set.indicator_of_mem, Set.indicator_of_notMem, h])] apply Finset.sum_congr rfl intro i _ unfold cdfStat by_cases h : S.Z i ω ∈ Iic y · rw [Set.indicator_of_mem h, Set.indicator_of_mem h, Pi.one_apply, ENNReal.toReal_one] · rw [Set.indicator_of_notMem h, Set.indicator_of_notMem h, ENNReal.toReal_zero]
    Causalean.Stat.IIDSample.empiricalMeasure_real_Iic · Causalean/Stat/Quantile/EmpiricalQuantile.lean:81
  • measurable_sampleQuantile lemma — Measurability of the sample quantile. For a positive sample size and an interior quantile level, the sample quantile is measurable.
    Ω :
    Type u_1
    shared
    P :
    shared
    S :
    IIDSample Ω ℝ μ P
    n :
    ℕ
    hn :
    0 < n
    τ :
    ℝ
    hτ0 :
    0 < τ
    hτ1 :
    τ < 1
    Measurable (S.sampleQuantile τ n)
    Proof (Lean source)
    @[fun_prop] lemma IIDSample.measurable_sampleQuantile (S : IIDSample Ω ℝ μ P) {n : ℕ} (hn : 0 < n) {τ : ℝ} (hτ0 : 0 < τ) (hτ1 : τ < 1) : Measurable (S.sampleQuantile τ n) := by apply measurable_of_Iic intro x have hpre : S.sampleQuantile τ n ⁻¹' Iic x = {ω | τ ≤ S.empiricalCDF x n ω} := by ext ω exact S.sampleQuantile_le_iff hn ω hτ0 hτ1 x rw [hpre] exact measurableSet_le measurable_const (S.measurable_sampleMean (measurable_cdfStat x) n)
    Causalean.Stat.IIDSample.measurable_sampleQuantile · Causalean/Stat/Quantile/EmpiricalQuantile.lean:138
  • empiricalCDF_monotone lemma — The empirical cdf is monotone in its real argument y (a sum of monotone lower-ray indicators).
    Ω :
    Type u_1
    shared
    P :
    shared
    S :
    IIDSample Ω ℝ μ P
    n :
    ℕ
    ω :
    Ω
    Monotone (fun y => S.empiricalCDF y n ω)
    Proof (Lean source)
    lemma IIDSample.empiricalCDF_monotone (S : IIDSample Ω ℝ μ P) (n : ℕ) (ω : Ω) : Monotone (fun y => S.empiricalCDF y n ω) := by intro y y' hyy' unfold IIDSample.empiricalCDF IIDSample.sampleMean apply mul_le_mul_of_nonneg_left _ (by positivity) apply Finset.sum_le_sum intro i _ unfold cdfStat by_cases h : S.Z i ω ≤ y · rw [Set.indicator_of_mem (Set.mem_Iic.mpr h), Set.indicator_of_mem (Set.mem_Iic.mpr (h.trans hyy'))] · rw [Set.indicator_of_notMem (by simp only [Set.mem_Iic]; exact h)] exact cdfStat_nonneg y' _
    Causalean.Stat.IIDSample.empiricalCDF_monotone · Causalean/Stat/Quantile/EmpiricalQuantile.lean:154
Sample­Quantile 4 core · 4 supporting This file develops the influence-function and asymptotic-normality layer for sample quantiles of an i.i.d. ★ QuantileRegularity★ isAsymLinear★ tendsto_normal

Sample Quantile Asymptotics

This file develops the influence-function and asymptotic-normality layer for sample quantiles of an i.i.d. real sample. It assumes the Bahadur representation as the regularity input and then derives the classical variance and Gaussian limit for the quantile estimator.

def quantileIF reviewed
Causalean.Stat

For a quantile index τ\tau, a population quantile q0q_0, and a density value f0f_0, the sample-quantile influence function maps a real observation zz to (τ−1{z≤q0})/f0(\tau-\mathbf{1}\{z\le q_0\})/f_0.

Definition (Lean source)
τ q₀ f₀ :
ℝ
quantileIF τ q₀ f₀ :
ℝ → ℝ
fun z => (τ - cdfStat q₀ z) / f₀
structure QuantileRegularity reviewed
Causalean.Stat

Quantile-estimator regularity. Bundles the analytic and empirical-process hypotheses under which a quantile-estimator sequence q^nq̂_n is n\sqrt n-asymptotically linear for the τ\tau-quantile q0q_0 of PP with density f0f_0: the level lies in the open unit interval τ∈(0,1)\tau \in (0,1), the density at the quantile is positive, q0q_0 is indeed the population τ\tau-quantile, i.e. the cdf satisfies F(q0)=τF(q_0) = \tau, the cdf is differentiable at q0q_0 with derivative f0f_0, so that τ(1−τ)/f02\tau(1-\tau)/f_0^2 is the genuine asymptotic variance, and the rescaled estimator matches the normalized influence-function sum up to a term vanishing in probability — the Bahadur remainder.

Definition (Lean source)
Ω :
Type u_1
shared
μ :
shared
P :
shared
S :
IIDSample Ω ℝ μ P
qn :
ℕ → Ω → ℝ
τ q₀ f₀ :
ℝ
tau_pos :
0 < τ
tau_lt_one :
τ < 1
density_pos :
0 < f₀
cdf_eq :
cdf P q₀ = τ
hasDeriv :
HasDerivAt (fun y => cdf P y) f₀ q₀
bahadur :
IsLittleOp (fun n ω => sqrt ((range n).card : ℝ) * (qn n ω - q₀) - (sqrt ((range n).card : ℝ))⁻¹ * ∑ i ∈ range n, quantileIF τ q₀ f₀ (S.Z i ω)) (fun _ => (1 : ℝ)) μ
Causalean.Stat.QuantileRegularity · Causalean/Stat/Quantile/SampleQuantile.lean:146 · uses IIDSample
lemma isAsymLinear reviewed
Causalean.Stat.QuantileRegularity

Regularity implies asymptotic linearity. Given a QuantileRegularity witness h for the estimator sequence qn, the estimator is asymptotically linear at the quantile q₀ with influence function ψ_τ.

Formal statement
Ω :
Type u_1
shared
P :
IIDSample Ω ℝ μ P
shared
qn :
ℕ → Ω → ℝ
τ q₀ f₀ :
ℝ
h :
QuantileRegularity S qn τ q₀ f₀
IsAsymLinear qn q₀ (quantileIF τ q₀ f₀) S (fun m => range m) where mean_zero
Proof (Lean source)
lemma QuantileRegularity.isAsymLinear {S : IIDSample Ω ℝ μ P} {qn : ℕ → Ω → ℝ} {τ q₀ f₀ : ℝ} (h : QuantileRegularity S qn τ q₀ f₀) : IsAsymLinear qn q₀ (quantileIF τ q₀ f₀) S (fun m => range m) where mean_zero := quantileIF_mean_zero h.cdf_eq finite_var := quantileIF_sq_integrable remainder := h.bahadur
theorem tendsto_normal reviewed
Causalean.Stat.QuantileRegularity

Sample-quantile asymptotic normality. Given a QuantileRegularity witness h for the estimator sequence qn — interior level τ∈(0,1)\tau\in(0,1), positive density f0f_0 at the population quantile q0q_0, cdf identification, and the exposed Bahadur/Donsker remainder — provided the rescaled estimator is almost-everywhere measurable at each sample size and the normalized influence-function sum is almost-everywhere measurable at each sample size, then n (q^n−q0)\sqrt n\,(\hat q_n-q_0) converges in distribution to the centered Gaussian law with variance τ(1−τ)/f02\tau(1-\tau)/f_0^2.

Formal statement
Ω :
Type u_1
shared
P :
IIDSample Ω ℝ μ P
shared
qn :
ℕ → Ω → ℝ
τ q₀ f₀ :
ℝ
h :
QuantileRegularity S qn τ q₀ f₀
hθn_meas :
∀ n : ℕ, AEMeasurable (IsAsymLinear.rescaledEstimator qn q₀ (fun m => range m) n) μ
_hSum_meas :
∀ n : ℕ,
AEMeasurable (IsAsymLinear.normalizedSum S (quantileIF τ q₀ f₀) (fun m => range m) n) μ
Modes.TendstoInLaw (fun _ : ℕ => μ) (IsAsymLinear.rescaledEstimator qn q₀ (fun m => range m)) atTop (gaussianMeasure 0 (τ * (1 - τ) / f₀ ^ 2))
Proof (Lean source)
theorem QuantileRegularity.tendsto_normal {S : IIDSample Ω ℝ μ P} {qn : ℕ → Ω → ℝ} {τ q₀ f₀ : ℝ} (h : QuantileRegularity S qn τ q₀ f₀) (hθn_meas : ∀ n : ℕ, AEMeasurable (IsAsymLinear.rescaledEstimator qn q₀ (fun m => range m) n) μ) (_hSum_meas : ∀ n : ℕ, AEMeasurable (IsAsymLinear.normalizedSum S (quantileIF τ q₀ f₀) (fun m => range m) n) μ) : Modes.TendstoInLaw (fun _ : ℕ => μ) (IsAsymLinear.rescaledEstimator qn q₀ (fun m => range m)) atTop (gaussianMeasure 0 (τ * (1 - τ) / f₀ ^ 2)) := by have hAL := h.isAsymLinear.tendsto_normal (measurable_quantileIF τ q₀ f₀) hθn_meas rwa [quantileIF_variance h.cdf_eq] at hAL
4 supporting declarations (lemmas, instances)
Cdf­Convergence 5 core · 12 supporting This module proves Pólya's theorem for real probability measures: weak convergence to a continuous distribution function gives uniform CDF convergence. ★ tendstoUniformly_cdf_of_tendsto★ tendsto_quantile_of_tendsto★ quantile_gaussianReal_zero

CDF and quantile convergence

This module proves Pólya's theorem for real probability measures: weak convergence to a continuous distribution function gives uniform CDF convergence. It then derives convergence of the existing lower generalized-inverse quantile, and identifies the quantile of every centered nondegenerate Gaussian by the standard-normal probit.

theorem tendstoUniformly_cdf_of_tendsto reviewed
Causalean.Stat

Pólya's theorem. Given weak convergence of real probability measures to a law with a continuous cumulative distribution function, their CDFs converge uniformly on the real line.

Formal statement
ι :
Type*
hν :
Tendsto νs l (𝓝 ν)
hcont :
Continuous (cdf (ν : Measure ℝ))
TendstoUniformly (fun i ↦ cdf (νs i : Measure ℝ)) (cdf (ν : Measure ℝ)) l
Proof (Lean source)
theorem tendstoUniformly_cdf_of_tendsto {ι : Type*} {l : Filter ι} {νs : ι → ProbabilityMeasure ℝ} {ν : ProbabilityMeasure ℝ} (hν : Tendsto νs l (𝓝 ν)) (hcont : Continuous (cdf (ν : Measure ℝ))) : TendstoUniformly (fun i ↦ cdf (νs i : Measure ℝ)) (cdf (ν : Measure ℝ)) l := by apply tendstoUniformly_of_monotone_of_tendsto_at_of_bounds (fun i ↦ monotone_cdf (νs i : Measure ℝ)) (fun i ↦ cdf_nonneg (νs i : Measure ℝ)) (fun i ↦ cdf_le_one (νs i : Measure ℝ)) (monotone_cdf (ν : Measure ℝ)) hcont (tendsto_cdf_atBot (ν : Measure ℝ)) (tendsto_cdf_atTop (ν : Measure ℝ)) intro t exact tendsto_cdf_at_of_tendsto hν hcont.continuousAt
Causalean.Stat.tendstoUniformly_cdf_of_tendsto · Causalean/Stat/Quantile/CdfConvergence.lean:162
def cdfKolmogorov reviewed
Causalean.Stat

Given two probability measures on the real line, their Kolmogorov CDF distance is the supremum of absolute CDF differences over all real thresholds.

Definition (Lean source)
μ ν :
cdfKolmogorov μ ν :
ℝ
⨆ t : ℝ, |cdf (μ : Measure ℝ) t - cdf (ν : Measure ℝ) t|
def StrictlyIncreasingAt reviewed
Causalean.Stat

Given a real-valued function and a reference point, strict increase at that point means every lower point has a smaller value and every higher point has a larger value.

Definition (Lean source)
f :
ℝ → ℝ
q :
ℝ
StrictlyIncreasingAt f q :
Prop
clause 1
x :
x < q
f x < f q
clause 2
x :
q < x
f q < f x
Causalean.Stat.StrictlyIncreasingAt · Causalean/Stat/Quantile/CdfConvergence.lean:237
theorem tendsto_quantile_of_tendsto reviewed
Causalean.Stat

Given weak convergence of real probability measures, an interior quantile level, a continuous limit CDF, and strict increase of that CDF at its lower quantile, the lower quantiles converge.

Formal statement
ι :
Type*
β :
ℝ
hν :
Tendsto νs l (𝓝 ν)
hβ0 :
0 < β
hβ1 :
β < 1
hcont :
Continuous (cdf (ν : Measure ℝ))
hstrict :
StrictlyIncreasingAt (cdf (ν : Measure ℝ)) (quantile (ν : Measure ℝ) β)
Tendsto (fun i ↦ quantile (νs i : Measure ℝ) β) l (𝓝 (quantile (ν : Measure ℝ) β))
Proof (Lean source)
theorem tendsto_quantile_of_tendsto {ι : Type*} {l : Filter ι} {νs : ι → ProbabilityMeasure ℝ} {ν : ProbabilityMeasure ℝ} {β : ℝ} (hν : Tendsto νs l (𝓝 ν)) (hβ0 : 0 < β) (hβ1 : β < 1) (hcont : Continuous (cdf (ν : Measure ℝ))) (hstrict : StrictlyIncreasingAt (cdf (ν : Measure ℝ)) (quantile (ν : Measure ℝ) β)) : Tendsto (fun i ↦ quantile (νs i : Measure ℝ) β) l (𝓝 (quantile (ν : Measure ℝ) β)) := by exact tendsto_quantile_of_tendstoUniformly hβ0 hβ1 (tendstoUniformly_cdf_of_tendsto hν hcont) hcont.continuousAt hstrict
Causalean.Stat.tendsto_quantile_of_tendsto · Causalean/Stat/Quantile/CdfConvergence.lean:329 · uses StrictlyIncreasingAt , quantile
theorem quantile_gaussianReal_zero reviewed
Causalean.Stat

Given a positive Gaussian variance and an interior probability level, the centered Gaussian lower quantile is its standard deviation times the standard-normal probit.

Formal statement
v :
hv :
0 < v
β :
ℝ
hβ0 :
0 < β
hβ1 :
β < 1
quantile (gaussianReal 0 v) β = sqrt (v : ℝ) * probit β
Proof (Lean source)
theorem quantile_gaussianReal_zero {v : NNReal} (hv : 0 < v) {β : ℝ} (hβ0 : 0 < β) (hβ1 : β < 1) : quantile (gaussianReal 0 v) β = sqrt (v : ℝ) * probit β := by have hvR : 0 < (v : ℝ) := by exact_mod_cast hv have hs : 0 < sqrt (v : ℝ) := Real.sqrt_pos.2 hvR have hcont := continuous_cdf_gaussianReal_zero hv have hquant : cdf (gaussianReal 0 v) (quantile (gaussianReal 0 v) β) = β := cdf_quantile_eq _ hβ0 hβ1 hcont.continuousAt have hcand : cdf (gaussianReal 0 v) (sqrt (v : ℝ) * probit β) = β := by rw [cdf_gaussianReal_zero hv] rw [mul_div_cancel_left₀ _ hs.ne'] exact stdNormalCDF_probit hβ0 hβ1 exact (strictMono_cdf_gaussianReal_zero hv).injective (hquant.trans hcand.symm)
Causalean.Stat.quantile_gaussianReal_zero · Causalean/Stat/Quantile/CdfConvergence.lean:387 · uses probit , quantile
12 supporting declarations (lemmas, instances)
Finite­Mass­Transport 2 core · 5 supporting This module extends the compact-support probability quantile/CDF identity to positive finite measures normalized to probability laws, with an explicit interval-length penalty for unequal total masses. ★ finite_mass_quantile_transport_le★ finite_mass_quantile_transport_eq_of_mass_eq

Unequal finite-mass quantile transport

This module extends the compact-support probability quantile/CDF identity to positive finite measures normalized to probability laws, with an explicit interval-length penalty for unequal total masses.

theorem finite_mass_quantile_transport_le reviewed
Causalean.Stat.Quantile.FiniteMassTransport

Two finite measures with an ordered common compact interval, positive masses, and concentration on that interval have smaller-mass-scaled normalized quantile cost bounded by raw CDF distance plus interval length times their mass difference.

Formal statement
μ ν :
a b :
ℝ
hab :
a ≤ b
hp :
0 < (μ.mass : ℝ)
hq :
0 < (ν.mass : ℝ)
hμ :
(μ : Measure ℝ) (Icc a b)ᶜ = 0
hν :
(ν : Measure ℝ) (Icc a b)ᶜ = 0
min (μ.mass : ℝ) (ν.mass : ℝ) * (∫ u in (0 : ℝ)..1, |quantile (μ.normalize : Measure ℝ) u - quantile (ν.normalize : Measure ℝ) u|)
≤ (∫ t in a..b, |((μ : Measure ℝ) (Iic t)).toReal - ((ν : Measure ℝ) (Iic t)).toReal|)
+ (b - a) * |(μ.mass : ℝ)
- (ν.mass : ℝ)|
Proof (Lean source)
theorem finite_mass_quantile_transport_le (μ ν : FiniteMeasure ℝ) {a b : ℝ} (hab : a ≤ b) (hp : 0 < (μ.mass : ℝ)) (hq : 0 < (ν.mass : ℝ)) (hμ : (μ : Measure ℝ) (Icc a b)ᶜ = 0) (hν : (ν : Measure ℝ) (Icc a b)ᶜ = 0) : min (μ.mass : ℝ) (ν.mass : ℝ) * (∫ u in (0 : ℝ)..1, |quantile (μ.normalize : Measure ℝ) u - quantile (ν.normalize : Measure ℝ) u|) ≤ (∫ t in a..b, |((μ : Measure ℝ) (Iic t)).toReal - ((ν : Measure ℝ) (Iic t)).toReal|) + (b - a) * |(μ.mass : ℝ) - (ν.mass : ℝ)| := by /- Apply `quantile_transport_eq_cdf_distance` to the two normalized probability measures. Their support follows from `hμ,hν` and `normalize_eq_of_nonzero`. Rewrite normalized CDFs with `cdf_normalize_eq_div`, then apply the integrated algebra bound. For each raw CDF, `measure_mono (Set.subset_univ _)` followed by `ENNReal.toReal_mono` gives the upper mass bound; the lower bound is `ENNReal.toReal_nonneg`. Use `intervalIntegrable_abs_cdf_sub` for the normalized difference and `intervalIntegrable_abs_raw_cdf_sub` for the raw difference. -/ have hμ' := normalize_support_Icc μ hp hμ have hν' := normalize_support_Icc ν hq hν have htransport := quantile_transport_eq_cdf_distance (μ.normalize : Measure ℝ) (ν.normalize : Measure ℝ) hab hμ' hν' have hμbound (t : ℝ) : 0 ≤ ((μ : Measure ℝ) (Iic t)).toReal ∧ ((μ : Measure ℝ) (Iic t)).toReal ≤ (μ.mass : ℝ) := by exact ⟨ENNReal.toReal_nonneg, ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (subset_univ _))⟩ have hνbound (t : ℝ) : 0 ≤ ((ν : Measure ℝ) (Iic t)).toReal ∧ ((ν : Measure ℝ) (Iic t)).toReal ≤ (ν.mass : ℝ) := by exact ⟨ENNReal.toReal_nonneg, ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (subset_univ _))⟩ have hnorm := intervalIntegrable_abs_cdf_sub (μ.normalize : Measure ℝ) (ν.normalize : Measure ℝ) a b have hraw := intervalIntegrable_abs_raw_cdf_sub μ ν a b have hnorm' : IntervalIntegrable (fun t => |((μ : Measure ℝ) (Iic t)).toReal / (μ.mass : ℝ) - ((ν : Measure ℝ) (Iic t)).toReal / (ν.mass : ℝ)|) volume a b := by simpa only [cdf_normalize_eq_div μ hp, cdf_normalize_eq_div ν hq] using hnorm rw [htransport] have hrewrite : (∫ t in a..b, |cdf (μ.normalize : Measure ℝ) t - cdf (ν.normalize : Measure ℝ) t|) = ∫ t in a..b, |((μ : Measure ℝ) (Iic t)).toReal / (μ.mass : ℝ) - ((ν : Measure ℝ) (Iic t)).toReal / (ν.mass : ℝ)| := by apply intervalIntegral.integral_congr intro t _ change |cdf (μ.normalize : Measure ℝ) t - cdf (ν.normalize : Measure ℝ) t| = _ rw [cdf_normalize_eq_div μ hp, cdf_normalize_eq_div ν hq] rw [hrewrite] exact min_mul_integral_abs_div_sub_div_le hab hp hq (fun t _ => hμbound t) (fun t _ => hνbound t) hnorm' hraw
Causalean.Stat.Quantile.FiniteMassTransport.finite_mass_quantile_transport_le · Causalean/Stat/Quantile/FiniteMassTransport.lean:145 · uses quantile
theorem finite_mass_quantile_transport_eq_of_mass_eq reviewed
Causalean.Stat.Quantile.FiniteMassTransport

Two finite measures with an ordered common compact interval, equal positive mass, and concentration on that interval have a mass-scaled normalized quantile cost equal to their raw CDF distance.

Formal statement
μ ν :
a b :
ℝ
hab :
a ≤ b
hm :
μ.mass = ν.mass
hp :
0 < (μ.mass : ℝ)
hμ :
(μ : Measure ℝ) (Icc a b)ᶜ = 0
hν :
(ν : Measure ℝ) (Icc a b)ᶜ = 0
(μ.mass : ℝ) * (∫ u in (0 : ℝ)..1, |quantile (μ.normalize : Measure ℝ) u - quantile (ν.normalize : Measure ℝ) u|)
= ∫ t in a..b, |((μ : Measure ℝ) (Iic t)).toReal - ((ν : Measure ℝ) (Iic t)).toReal|
Proof (Lean source)
theorem finite_mass_quantile_transport_eq_of_mass_eq (μ ν : FiniteMeasure ℝ) {a b : ℝ} (hab : a ≤ b) (hm : μ.mass = ν.mass) (hp : 0 < (μ.mass : ℝ)) (hμ : (μ : Measure ℝ) (Icc a b)ᶜ = 0) (hν : (ν : Measure ℝ) (Icc a b)ᶜ = 0) : (μ.mass : ℝ) * (∫ u in (0 : ℝ)..1, |quantile (μ.normalize : Measure ℝ) u - quantile (ν.normalize : Measure ℝ) u|) = ∫ t in a..b, |((μ : Measure ℝ) (Iic t)).toReal - ((ν : Measure ℝ) (Iic t)).toReal| := by /- Normalize support, apply `quantile_transport_eq_cdf_distance`, rewrite both CDFs with `cdf_normalize_eq_div`, then pull out the common positive mass through absolute value and interval integration. `hm` identifies the denominators. Pointwise, positive `p` gives `p * |x / p - y / p| = |x - y|`; use this inside `intervalIntegral.integral_congr` after `integral_const_mul`. -/ have hq : 0 < (ν.mass : ℝ) := by simpa [hm] using hp have hμ' := normalize_support_Icc μ hp hμ have hν' := normalize_support_Icc ν hq hν have htransport := quantile_transport_eq_cdf_distance (μ.normalize : Measure ℝ) (ν.normalize : Measure ℝ) hab hμ' hν' rw [htransport] have hrewrite : (∫ t in a..b, |cdf (μ.normalize : Measure ℝ) t - cdf (ν.normalize : Measure ℝ) t|) = ∫ t in a..b, |((μ : Measure ℝ) (Iic t)).toReal / (μ.mass : ℝ) - ((ν : Measure ℝ) (Iic t)).toReal / (ν.mass : ℝ)| := by apply intervalIntegral.integral_congr intro t _ change |cdf (μ.normalize : Measure ℝ) t - cdf (ν.normalize : Measure ℝ) t| = _ rw [cdf_normalize_eq_div μ hp, cdf_normalize_eq_div ν hq] rw [hrewrite] rw [hm] rw [← intervalIntegral.integral_const_mul] apply intervalIntegral.integral_congr intro t _ change (ν.mass : ℝ) * |((μ : Measure ℝ) (Iic t)).toReal / (ν.mass : ℝ) - ((ν : Measure ℝ) (Iic t)).toReal / (ν.mass : ℝ)| = |((μ : Measure ℝ) (Iic t)).toReal - ((ν : Measure ℝ) (Iic t)).toReal| rw [← sub_div, abs_div, abs_of_pos hq] exact mul_div_cancel₀ _ (ne_of_gt hq)
Causalean.Stat.Quantile.FiniteMassTransport.finite_mass_quantile_transport_eq_of_mass_eq · Causalean/Stat/Quantile/FiniteMassTransport.lean:208 · uses quantile
5 supporting declarations (lemmas, instances)
  • min_mul_abs_div_sub_div_le lemma — Positive total masses and their nonnegative bounded cumulative mass values give a normalized discrepancy times the smaller mass bounded by the raw discrepancy plus the mass mismatch.
    p q x y :
    ℝ
    hp :
    0 < p
    hq :
    0 < q
    hx :
    0 ≤ x
    hxp :
    x ≤ p
    hy :
    0 ≤ y
    hyq :
    y ≤ q
    min p q * |x / p - y / q| ≤ |x - y| + |p - q|
    Proof (Lean source)
    lemma min_mul_abs_div_sub_div_le {p q x y : ℝ} (hp : 0 < p) (hq : 0 < q) (hx : 0 ≤ x) (hxp : x ≤ p) (hy : 0 ≤ y) (hyq : y ≤ q) : min p q * |x / p - y / q| ≤ |x - y| + |p - q| := by /- Split on `p ≤ q`. In that branch rewrite `p*(x/p-y/q) = (x-y)+(q-p)*(y/q)` and use `0 ≤ y/q ≤ 1`. The other branch is symmetric. -/ have hp0 : p ≠ 0 := ne_of_gt hp have hq0 : q ≠ 0 := ne_of_gt hq have hydiv : 0 ≤ y / q ∧ y / q ≤ 1 := ⟨div_nonneg hy hq.le, (div_le_one hq).2 hyq⟩ have hxdiv : 0 ≤ x / p ∧ x / p ≤ 1 := ⟨div_nonneg hx hp.le, (div_le_one hp).2 hxp⟩ rcases le_total p q with hpq | hqp · rw [min_eq_left hpq] have hid : p * (x / p - y / q) = (x - y) + (q - p) * (y / q) := by field_simp ring calc p * |x / p - y / q| = |p * (x / p - y / q)| := by rw [abs_mul, abs_of_pos hp] _ = |(x - y) + (q - p) * (y / q)| := by rw [hid] _ ≤ |x - y| + |(q - p) * (y / q)| := abs_add_le _ _ _ ≤ |x - y| + |p - q| := by have h : |(q - p) * (y / q)| ≤ |p - q| := by rw [abs_mul, abs_of_nonneg (sub_nonneg.mpr hpq), abs_of_nonneg hydiv.1, abs_sub_comm] simpa [abs_of_nonneg (sub_nonneg.mpr hpq)] using mul_le_of_le_one_right (sub_nonneg.mpr hpq) hydiv.2 linarith · rw [min_eq_right hqp] have hid : q * (x / p - y / q) = (x - y) - (p - q) * (x / p) := by field_simp ring calc q * |x / p - y / q| = |q * (x / p - y / q)| := by rw [abs_mul, abs_of_pos hq] _ = |(x - y) - (p - q) * (x / p)| := by rw [hid] _ ≤ |x - y| + |(p - q) * (x / p)| := by simpa [sub_eq_add_neg] using (abs_add_le (x - y) (-((p - q) * (x / p)))) _ ≤ |x - y| + |p - q| := by have h : |(p - q) * (x / p)| ≤ |p - q| := by rw [abs_mul, abs_of_nonneg (sub_nonneg.mpr hqp), abs_of_nonneg hxdiv.1] simpa [abs_of_nonneg (sub_nonneg.mpr hqp)] using mul_le_of_le_one_right (sub_nonneg.mpr hqp) hxdiv.2 linarith
    Causalean.Stat.Quantile.FiniteMassTransport.min_mul_abs_div_sub_div_le · Causalean/Stat/Quantile/FiniteMassTransport.lean:20
  • min_mul_integral_abs_div_sub_div_le lemma — An ordered interval, positive masses, bounded cumulative functions, and integrability of both discrepancies give the integrated normalized discrepancy bound with a mass-mismatch penalty.
    a b p q :
    ℝ
    F G :
    ℝ → ℝ
    hab :
    a ≤ b
    hp :
    0 < p
    hq :
    0 < q
    hF :
    ∀ t ∈ Icc a b, 0 ≤ F t ∧ F t ≤ p
    hG :
    ∀ t ∈ Icc a b, 0 ≤ G t ∧ G t ≤ q
    hnorm :
    IntervalIntegrable (fun t => |F t / p - G t / q|) volume a b
    hraw :
    IntervalIntegrable (fun t => |F t - G t|) volume a b
    min p q * (∫ t in a..b, |F t / p - G t / q|)
    ≤ (∫ t in a..b, |F t - G t|) + (b - a) * |p - q|
    Proof (Lean source)
    lemma min_mul_integral_abs_div_sub_div_le {a b p q : ℝ} {F G : ℝ → ℝ} (hab : a ≤ b) (hp : 0 < p) (hq : 0 < q) (hF : ∀ t ∈ Icc a b, 0 ≤ F t ∧ F t ≤ p) (hG : ∀ t ∈ Icc a b, 0 ≤ G t ∧ G t ≤ q) (hnorm : IntervalIntegrable (fun t => |F t / p - G t / q|) volume a b) (hraw : IntervalIntegrable (fun t => |F t - G t|) volume a b) : min p q * (∫ t in a..b, |F t / p - G t / q|) ≤ (∫ t in a..b, |F t - G t|) + (b - a) * |p - q| := by /- Integrate the preceding pointwise bound with `integral_mono_on`; `intervalIntegral.integral_const` gives exactly `(b-a)*|p-q|`. -/ have hconst : IntervalIntegrable (fun _ : ℝ => |p - q|) volume a b := intervalIntegrable_const have hleft : IntervalIntegrable (fun t => min p q * |F t / p - G t / q|) volume a b := hnorm.const_mul _ have hright : IntervalIntegrable (fun t => |F t - G t| + |p - q|) volume a b := hraw.add hconst have hmono := intervalIntegral.integral_mono_on hab hleft hright (fun t ht => min_mul_abs_div_sub_div_le hp hq (hF t ht).1 (hF t ht).2 (hG t ht).1 (hG t ht).2) rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_add hraw hconst, intervalIntegral.integral_const] at hmono simpa only [smul_eq_mul] using hmono
    Causalean.Stat.Quantile.FiniteMassTransport.min_mul_integral_abs_div_sub_div_le · Causalean/Stat/Quantile/FiniteMassTransport.lean:68
  • cdf_normalize_eq_div lemma — A finite measure with positive total mass has a normalized CDF equal to raw cumulative mass divided by total mass.
    μ :
    hp :
    0 < (μ.mass : ℝ)
    t :
    ℝ
    cdf (μ.normalize : Measure ℝ) t = ((μ : Measure ℝ) (Iic t)).toReal / (μ.mass : ℝ)
    Proof (Lean source)
    lemma cdf_normalize_eq_div (μ : FiniteMeasure ℝ) (hp : 0 < (μ.mass : ℝ)) (t : ℝ) : cdf (μ.normalize : Measure ℝ) t = ((μ : Measure ℝ) (Iic t)).toReal / (μ.mass : ℝ) := by /- Use `cdf_eq_real` and `FiniteMeasure.normalize_eq_of_nonzero`, then convert the finite-measure values from `ℝ≥0` to `ℝ`. -/ have hne : μ ≠ 0 := by intro h simp [h] at hp rw [ProbabilityTheory.cdf_eq_real] rw [Measure.real, μ.toMeasure_normalize_eq_of_nonzero hne, Measure.smul_apply] change (((μ.mass⁻¹ : NNReal) : ENNReal) * (μ : Measure ℝ) (Iic t)).toReal = _ rw [ENNReal.toReal_mul] simp [inv_mul_eq_div]
    Causalean.Stat.Quantile.FiniteMassTransport.cdf_normalize_eq_div · Causalean/Stat/Quantile/FiniteMassTransport.lean:97
  • normalize_support_Icc lemma — A finite measure with positive total mass concentrated on a closed interval has a normalized probability law concentrated on the same interval.
    μ :
    a b :
    ℝ
    hp :
    0 < (μ.mass : ℝ)
    hμ :
    (μ : Measure ℝ) (Icc a b)ᶜ = 0
    (μ.normalize : Measure ℝ) (Icc a b)ᶜ = 0
    Proof (Lean source)
    lemma normalize_support_Icc (μ : FiniteMeasure ℝ) {a b : ℝ} (hp : 0 < (μ.mass : ℝ)) (hμ : (μ : Measure ℝ) (Icc a b)ᶜ = 0) : (μ.normalize : Measure ℝ) (Icc a b)ᶜ = 0 := by /- Apply `FiniteMeasure.normalize_eq_of_nonzero` to the complement. -/ have hne : μ ≠ 0 := by intro h simp [h] at hp rw [μ.toMeasure_normalize_eq_of_nonzero hne, Measure.smul_apply] simp [hμ]
    Causalean.Stat.Quantile.FiniteMassTransport.normalize_support_Icc · Causalean/Stat/Quantile/FiniteMassTransport.lean:114
  • intervalIntegrable_abs_raw_cdf_sub lemma — Two finite measures have an integrable raw cumulative-mass difference on the given finite interval.
    μ ν :
    a b :
    ℝ
    IntervalIntegrable (fun t : ℝ => |((μ : Measure ℝ) (Iic t)).toReal - ((ν : Measure ℝ) (Iic t)).toReal|) volume a b
    Proof (Lean source)
    lemma intervalIntegrable_abs_raw_cdf_sub (μ ν : FiniteMeasure ℝ) (a b : ℝ) : IntervalIntegrable (fun t : ℝ => |((μ : Measure ℝ) (Iic t)).toReal - ((ν : Measure ℝ) (Iic t)).toReal|) volume a b := by /- Each raw cumulative mass is monotone and bounded by the finite total mass; monotone real functions are measurable and bounded on `Icc a b`. -/ have hμ : Monotone (fun t : ℝ => ((μ : Measure ℝ) (Iic t)).toReal) := by intro s t hst exact ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (Iic_subset_Iic.mpr hst)) have hν : Monotone (fun t : ℝ => ((ν : Measure ℝ) (Iic t)).toReal) := by intro s t hst exact ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (Iic_subset_Iic.mpr hst)) exact (hμ.intervalIntegrable.sub hν.intervalIntegrable).abs
    Causalean.Stat.Quantile.FiniteMassTransport.intervalIntegrable_abs_raw_cdf_sub · Causalean/Stat/Quantile/FiniteMassTransport.lean:128
Pushforward 2 core · 8 supporting This module proves that applying a measurable Lipschitz transformation to two compactly supported real probability laws cannot increase their shared-uniform quantile transport cost by more than the Lipschitz factor. ★ quantile_pushforward_lipschitzOn★ quantile_pushforward_lipschitz

Lipschitz pushforwards of one-dimensional quantile transport

This module proves that applying a measurable Lipschitz transformation to two compactly supported real probability laws cannot increase their shared-uniform quantile transport cost by more than the Lipschitz factor. The proof works through arbitrary couplings, so it applies unchanged to atomic laws and to decreasing transformations.

theorem quantile_pushforward_lipschitzOn reviewed
Causalean.Stat.Quantile.Pushforward

Two probability laws concentrated on an ordered common closed interval, and a measurable transformation with a Lipschitz factor that is nonnegative and controls the transformation on that interval, have image quantile transport cost at most that factor times their source cost. This conclusion allows atoms and decreasing transformations.

Formal statement
a b L :
ℝ
hab :
a ≤ b
hμ :
μ (Icc a b)ᶜ = 0
hν :
ν (Icc a b)ᶜ = 0
hL :
0 ≤ L
f :
ℝ → ℝ
hf :
hLip :
∀ x ∈ Icc a b, ∀ y ∈ Icc a b, |f x - f y| ≤ L * |x - y|
(∫ u in (0 : ℝ)..1, |quantile (μ.map f) u - quantile (ν.map f) u|)
≤ L * ∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|
Proof (Lean source)
theorem quantile_pushforward_lipschitzOn (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b L : ℝ} (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) (hL : 0 ≤ L) (f : ℝ → ℝ) (hf : Measurable f) (hLip : ∀ x ∈ Icc a b, ∀ y ∈ Icc a b, |f x - f y| ≤ L * |x - y|) : (∫ u in (0 : ℝ)..1, |quantile (μ.map f) u - quantile (ν.map f) u|) ≤ L * ∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u| := by letI : IsProbabilityMeasure (μ.map f) := Measure.isProbabilityMeasure_map hf.aemeasurable letI : IsProbabilityMeasure (ν.map f) := Measure.isProbabilityMeasure_map hf.aemeasurable let c := f a - L * (b - a) let d := f a + L * (b - a) have hcd : c ≤ d := by dsimp [c, d] have hba : 0 ≤ b - a := sub_nonneg.mpr hab nlinarith [mul_nonneg hL hba] have hμ' : (μ.map f) (Icc c d)ᶜ = 0 := map_supported_in_lipschitz_range μ hab hμ hL f hf hLip have hν' : (ν.map f) (Icc c d)ᶜ = 0 := map_supported_in_lipschitz_range ν hab hν hL f hf hLip let π := comonotoneCoupling μ ν have hπ : IsCoupling π μ ν := isCoupling_comonotoneCoupling μ ν have hπ' : IsCoupling (π.map (fun z : ℝ × ℝ => (f z.1, f z.2))) (μ.map f) (ν.map f) := map_pair_isCoupling μ ν f hf hπ have hopt := quantile_cost_le_coupling_cost (μ.map f) (ν.map f) hcd hμ' hν' hπ' have hcost := mapped_coupling_cost_le μ ν hμ hν f hf hLip hπ have hquant : (∫ z : ℝ × ℝ, |z.1 - z.2| ∂π) = ∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u| := by have hpair : AEMeasurable (fun u : ℝ => (quantile μ u, quantile ν u)) unifOI := (aemeasurable_quantile_unifOI μ).prodMk (aemeasurable_quantile_unifOI ν) have hmeas : AEStronglyMeasurable (fun z : ℝ × ℝ => |z.1 - z.2|) π := by fun_prop change (∫ z : ℝ × ℝ, |z.1 - z.2| ∂ (unifOI.map (fun u : ℝ => (quantile μ u, quantile ν u)))) = _ rw [integral_map hpair hmeas] have hrest : volume.restrict (Ioc (0 : ℝ) 1) = unifOI := by rw [unifOI, restrict_Ioo_eq_restrict_Ioc] rw [intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1), hrest] exact hopt.trans (hcost.trans_eq (congrArg (L * ·) hquant))
Causalean.Stat.Quantile.Pushforward.quantile_pushforward_lipschitzOn · Causalean/Stat/Quantile/Pushforward.lean:311 · uses quantile
theorem quantile_pushforward_lipschitz reviewed
Causalean.Stat.Quantile.Pushforward

Two probability laws concentrated on an ordered common closed interval, and a measurable globally Lipschitz transformation, have image quantile transport cost at most the global Lipschitz factor times their source cost.

Formal statement
a b L :
ℝ
hab :
a ≤ b
hμ :
μ (Icc a b)ᶜ = 0
hν :
ν (Icc a b)ᶜ = 0
hL :
0 ≤ L
f :
ℝ → ℝ
hf :
hLip :
∀ x y : ℝ, |f x - f y| ≤ L * |x - y|
(∫ u in (0 : ℝ)..1, |quantile (μ.map f) u - quantile (ν.map f) u|)
≤ L * ∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|
Proof (Lean source)
theorem quantile_pushforward_lipschitz (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b L : ℝ} (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) (hL : 0 ≤ L) (f : ℝ → ℝ) (hf : Measurable f) (hLip : ∀ x y : ℝ, |f x - f y| ≤ L * |x - y|) : (∫ u in (0 : ℝ)..1, |quantile (μ.map f) u - quantile (ν.map f) u|) ≤ L * ∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u| := by exact quantile_pushforward_lipschitzOn μ ν hab hμ hν hL f hf (fun x _ y _ => hLip x y)
Causalean.Stat.Quantile.Pushforward.quantile_pushforward_lipschitz · Causalean/Stat/Quantile/Pushforward.lean:361 · uses quantile
8 supporting declarations (lemmas, instances)
  • coupling_abs_cost_integrable lemma — Two probability laws concentrated on the common closed interval from a to b and a coupling of them have an integrable absolute coordinate difference.
    a b :
    ℝ
    hμ :
    μ (Icc a b)ᶜ = 0
    hν :
    ν (Icc a b)ᶜ = 0
    π :
    Measure (ℝ × ℝ)
    hπ :
    IsCoupling π μ ν
    Integrable (fun z : ℝ × ℝ => |z.1 - z.2|) π
    Proof (Lean source)
    lemma coupling_abs_cost_integrable (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) {π : Measure (ℝ × ℝ)} (hπ : IsCoupling π μ ν) : Integrable (fun z : ℝ × ℝ => |z.1 - z.2|) π := by letI : IsProbabilityMeasure π := hπ.isProbabilityMeasure have h₁ : ∀ᵐ z ∂π, z.1 ∈ Icc a b := by have hh : ∀ᵐ x ∂μ, x ∈ Icc a b := by rw [ae_iff] exact hμ rw [← hπ.map_fst] at hh exact (ae_map_iff measurable_fst.aemeasurable measurableSet_Icc).mp hh have h₂ : ∀ᵐ z ∂π, z.2 ∈ Icc a b := by have hh : ∀ᵐ x ∂ν, x ∈ Icc a b := by rw [ae_iff] exact hν rw [← hπ.map_snd] at hh exact (ae_map_iff measurable_snd.aemeasurable measurableSet_Icc).mp hh apply Integrable.of_bound (by fun_prop) (b - a) filter_upwards [h₁, h₂] with z hz₁ hz₂ rw [Real.norm_eq_abs, abs_abs] exact abs_le.mpr ⟨by linarith [hz₁.1, hz₂.2], by linarith [hz₁.2, hz₂.1]⟩
    Causalean.Stat.Quantile.Pushforward.coupling_abs_cost_integrable · Causalean/Stat/Quantile/Pushforward.lean:21
  • cdf_distance_le_threshold_disagreement lemma — Two probability laws, a coupling of them, and a threshold have a CDF difference at that threshold bounded by the coupling's expected lower-ray-indicator disagreement.
    π :
    Measure (ℝ × ℝ)
    hπ :
    IsCoupling π μ ν
    t :
    ℝ
    |cdf μ t - cdf ν t|
    ≤ ∫ z : ℝ × ℝ, |(if z.1 ≤ t then (1 : ℝ) else 0) - (if z.2 ≤ t then 1 else 0)| ∂π
    Proof (Lean source)
    lemma cdf_distance_le_threshold_disagreement (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {π : Measure (ℝ × ℝ)} (hπ : IsCoupling π μ ν) (t : ℝ) : |cdf μ t - cdf ν t| ≤ ∫ z : ℝ × ℝ, |(if z.1 ≤ t then (1 : ℝ) else 0) - (if z.2 ≤ t then 1 else 0)| ∂π := by letI : IsProbabilityMeasure π := hπ.isProbabilityMeasure have hind (ρ : Measure ℝ) [IsProbabilityMeasure ρ] : (∫ x : ℝ, (if x ≤ t then (1 : ℝ) else 0) ∂ρ) = cdf ρ t := by have heq : (fun x : ℝ => if x ≤ t then (1 : ℝ) else 0) = (Iic t).indicator (fun _ => (1 : ℝ)) := by funext x simp [indicator, Set.mem_Iic] rw [heq, integral_indicator measurableSet_Iic, setIntegral_const, cdf_eq_real] simp [measureReal_def] have hm : Measurable (fun x : ℝ => if x ≤ t then (1 : ℝ) else 0) := by convert (measurable_const.indicator measurableSet_Iic : Measurable ((Iic t).indicator (fun _ : ℝ => (1 : ℝ)))) using 1 funext x by_cases hx : x ≤ t <;> simp [indicator, hx] have h₁ : Integrable (fun z : ℝ × ℝ => if z.1 ≤ t then (1 : ℝ) else 0) π := by apply Integrable.of_bound (hm.comp measurable_fst).aestronglyMeasurable 1 filter_upwards with z change ‖if z.1 ≤ t then (1 : ℝ) else 0‖ ≤ 1 split_ifs <;> norm_num have h₂ : Integrable (fun z : ℝ × ℝ => if z.2 ≤ t then (1 : ℝ) else 0) π := by apply Integrable.of_bound (hm.comp measurable_snd).aestronglyMeasurable 1 filter_upwards with z change ‖if z.2 ≤ t then (1 : ℝ) else 0‖ ≤ 1 split_ifs <;> norm_num have hμ' : (∫ z : ℝ × ℝ, (if z.1 ≤ t then (1 : ℝ) else 0) ∂π) = cdf μ t := by calc _ = ∫ x : ℝ, (if x ≤ t then (1 : ℝ) else 0) ∂μ := by rw [← hπ.map_fst, integral_map measurable_fst.aemeasurable hm.aestronglyMeasurable] _ = cdf μ t := hind μ have hν' : (∫ z : ℝ × ℝ, (if z.2 ≤ t then (1 : ℝ) else 0) ∂π) = cdf ν t := by calc _ = ∫ x : ℝ, (if x ≤ t then (1 : ℝ) else 0) ∂ν := by rw [← hπ.map_snd, integral_map measurable_snd.aemeasurable hm.aestronglyMeasurable] _ = cdf ν t := hind ν rw [← hμ', ← hν', ← integral_sub h₁ h₂] exact abs_integral_le_integral_abs
    Causalean.Stat.Quantile.Pushforward.cdf_distance_le_threshold_disagreement · Causalean/Stat/Quantile/Pushforward.lean:47
  • coupling_indicator_integral_eq_cost lemma — Two probability laws concentrated on the ordered common closed interval from a to b and a coupling have integrated lower-ray disagreement equal to expected absolute coordinate distance.
    a b :
    ℝ
    hab :
    a ≤ b
    hμ :
    μ (Icc a b)ᶜ = 0
    hν :
    ν (Icc a b)ᶜ = 0
    π :
    Measure (ℝ × ℝ)
    hπ :
    IsCoupling π μ ν
    (∫ t in a..b, ∫ z : ℝ × ℝ, |(if z.1 ≤ t then (1 : ℝ) else 0) - (if z.2 ≤ t then 1 else 0)| ∂π)
    = ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π
    Proof (Lean source)
    lemma coupling_indicator_integral_eq_cost (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) {π : Measure (ℝ × ℝ)} (hπ : IsCoupling π μ ν) : (∫ t in a..b, ∫ z : ℝ × ℝ, |(if z.1 ≤ t then (1 : ℝ) else 0) - (if z.2 ≤ t then 1 else 0)| ∂π) = ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π := by letI : IsProbabilityMeasure π := hπ.isProbabilityMeasure let ρ : Measure ℝ := volume.restrict (Ioc a b) haveI : IsFiniteMeasure ρ := by dsimp [ρ] exact isFiniteMeasure_restrict.mpr measure_Ioc_lt_top.ne let k : ℝ → (ℝ × ℝ) → ℝ := fun t z => |(if z.1 ≤ t then (1 : ℝ) else 0) - (if z.2 ≤ t then 1 else 0)| have hk : Integrable (fun p : ℝ × (ℝ × ℝ) => k p.1 p.2) (ρ.prod π) := by have h₁ : Measurable (fun p : ℝ × (ℝ × ℝ) => if p.2.1 ≤ p.1 then (1 : ℝ) else 0) := by exact measurable_const.ite (measurableSet_le measurable_snd.fst measurable_fst) measurable_const have h₂ : Measurable (fun p : ℝ × (ℝ × ℝ) => if p.2.2 ≤ p.1 then (1 : ℝ) else 0) := by exact measurable_const.ite (measurableSet_le measurable_snd.snd measurable_fst) measurable_const have hm : Measurable (fun p : ℝ × (ℝ × ℝ) => k p.1 p.2) := by simpa [k, Real.norm_eq_abs] using (h₁.sub h₂).norm apply Integrable.of_bound hm.aestronglyMeasurable 1 filter_upwards with p change ‖|(if p.2.1 ≤ p.1 then (1 : ℝ) else 0) - (if p.2.2 ≤ p.1 then 1 else 0)|‖ ≤ 1 split_ifs <;> norm_num have hswap : (∫ t in a..b, ∫ z : ℝ × ℝ, k t z ∂π) = ∫ z : ℝ × ℝ, (∫ t in a..b, k t z) ∂π := by simp_rw [intervalIntegral.integral_of_le hab] simpa only [ρ] using (integral_integral_swap (f := k) hk) have h₁ : ∀ᵐ z ∂π, z.1 ∈ Icc a b := by have hh : ∀ᵐ x ∂μ, x ∈ Icc a b := by rw [ae_iff] exact hμ rw [← hπ.map_fst] at hh exact (ae_map_iff measurable_fst.aemeasurable measurableSet_Icc).mp hh have h₂ : ∀ᵐ z ∂π, z.2 ∈ Icc a b := by have hh : ∀ᵐ x ∂ν, x ∈ Icc a b := by rw [ae_iff] exact hν rw [← hπ.map_snd] at hh exact (ae_map_iff measurable_snd.aemeasurable measurableSet_Icc).mp hh change (∫ t in a..b, ∫ z : ℝ × ℝ, k t z ∂π) = ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π rw [hswap] apply integral_congr_ae filter_upwards [h₁, h₂] with z hz₁ hz₂ exact (abs_sub_eq_integral_Icc_indicator hz₁ hz₂).symm
    Causalean.Stat.Quantile.Pushforward.coupling_indicator_integral_eq_cost · Causalean/Stat/Quantile/Pushforward.lean:94
  • cdf_distance_le_coupling_cost theorem — Two probability laws concentrated on the ordered common closed interval from a to b and a coupling have integrated CDF distance no larger than the coupling's expected absolute coordinate distance.
    a b :
    ℝ
    hab :
    a ≤ b
    hμ :
    μ (Icc a b)ᶜ = 0
    hν :
    ν (Icc a b)ᶜ = 0
    π :
    Measure (ℝ × ℝ)
    hπ :
    IsCoupling π μ ν
    (∫ t in a..b, |cdf μ t - cdf ν t|) ≤ ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π
    Proof (Lean source)
    theorem cdf_distance_le_coupling_cost (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) {π : Measure (ℝ × ℝ)} (hπ : IsCoupling π μ ν) : (∫ t in a..b, |cdf μ t - cdf ν t|) ≤ ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π := by letI : IsProbabilityMeasure π := hπ.isProbabilityMeasure let ρ : Measure ℝ := volume.restrict (Ioc a b) haveI : IsFiniteMeasure ρ := by dsimp [ρ] exact isFiniteMeasure_restrict.mpr measure_Ioc_lt_top.ne let k : ℝ → (ℝ × ℝ) → ℝ := fun t z => |(if z.1 ≤ t then (1 : ℝ) else 0) - (if z.2 ≤ t then 1 else 0)| have hk : Integrable (fun p : ℝ × (ℝ × ℝ) => k p.1 p.2) (ρ.prod π) := by have h₁ : Measurable (fun p : ℝ × (ℝ × ℝ) => if p.2.1 ≤ p.1 then (1 : ℝ) else 0) := by exact measurable_const.ite (measurableSet_le measurable_snd.fst measurable_fst) measurable_const have h₂ : Measurable (fun p : ℝ × (ℝ × ℝ) => if p.2.2 ≤ p.1 then (1 : ℝ) else 0) := by exact measurable_const.ite (measurableSet_le measurable_snd.snd measurable_fst) measurable_const have hm : Measurable (fun p : ℝ × (ℝ × ℝ) => k p.1 p.2) := by simpa [k, Real.norm_eq_abs] using (h₁.sub h₂).norm apply Integrable.of_bound hm.aestronglyMeasurable 1 filter_upwards with p change ‖|(if p.2.1 ≤ p.1 then (1 : ℝ) else 0) - (if p.2.2 ≤ p.1 then 1 else 0)|‖ ≤ 1 split_ifs <;> norm_num have hg : IntervalIntegrable (fun t : ℝ => ∫ z : ℝ × ℝ, k t z ∂π) volume a b := by apply (intervalIntegrable_iff_integrableOn_Ioc_of_le hab).2 change Integrable (fun t : ℝ => ∫ z : ℝ × ℝ, k t z ∂π) ρ exact hk.integral_prod_left calc (∫ t in a..b, |cdf μ t - cdf ν t|) ≤ ∫ t in a..b, ∫ z : ℝ × ℝ, k t z ∂π := by apply intervalIntegral.integral_mono hab (intervalIntegrable_abs_cdf_sub μ ν a b) hg intro t exact cdf_distance_le_threshold_disagreement μ ν hπ t _ = ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π := coupling_indicator_integral_eq_cost μ ν hab hμ hν hπ
    Causalean.Stat.Quantile.Pushforward.cdf_distance_le_coupling_cost · Causalean/Stat/Quantile/Pushforward.lean:153
  • quantile_cost_le_coupling_cost theorem — Two probability laws concentrated on the ordered common closed interval from a to b and a coupling have shared-uniform quantile cost no larger than the coupling's expected absolute coordinate distance.
    a b :
    ℝ
    hab :
    a ≤ b
    hμ :
    μ (Icc a b)ᶜ = 0
    hν :
    ν (Icc a b)ᶜ = 0
    π :
    Measure (ℝ × ℝ)
    hπ :
    IsCoupling π μ ν
    (∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|) ≤ ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π
    Proof (Lean source)
    theorem quantile_cost_le_coupling_cost (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) {π : Measure (ℝ × ℝ)} (hπ : IsCoupling π μ ν) : (∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|) ≤ ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π := by rw [quantile_transport_eq_cdf_distance μ ν hab hμ hν] exact cdf_distance_le_coupling_cost μ ν hab hμ hν hπ
    Causalean.Stat.Quantile.Pushforward.quantile_cost_le_coupling_cost · Causalean/Stat/Quantile/Pushforward.lean:202
  • map_pair_isCoupling lemma — A measurable transformation sends a coupling of two real laws to a coupling of their transformed laws by acting on both coordinates.
    μ ν :
    f :
    ℝ → ℝ
    hf :
    π :
    Measure (ℝ × ℝ)
    hπ :
    IsCoupling π μ ν
    IsCoupling (π.map (fun z : ℝ × ℝ => (f z.1, f z.2))) (μ.map f) (ν.map f)
    Proof (Lean source)
    lemma map_pair_isCoupling (μ ν : Measure ℝ) (f : ℝ → ℝ) (hf : Measurable f) {π : Measure (ℝ × ℝ)} (hπ : IsCoupling π μ ν) : IsCoupling (π.map (fun z : ℝ × ℝ => (f z.1, f z.2))) (μ.map f) (ν.map f) := by letI : IsProbabilityMeasure π := hπ.isProbabilityMeasure have hp : Measurable (fun z : ℝ × ℝ => (f z.1, f z.2)) := (hf.comp measurable_fst).prodMk (hf.comp measurable_snd) refine ⟨Measure.isProbabilityMeasure_map hp.aemeasurable, ?_, ?_⟩ · calc (π.map (fun z : ℝ × ℝ => (f z.1, f z.2))).map fst = π.map (f ∘ fst) := by rw [Measure.map_map measurable_fst hp]; rfl _ = μ.map f := by rw [← hπ.map_fst, Measure.map_map hf measurable_fst] · calc (π.map (fun z : ℝ × ℝ => (f z.1, f z.2))).map snd = π.map (f ∘ snd) := by rw [Measure.map_map measurable_snd hp]; rfl _ = ν.map f := by rw [← hπ.map_snd, Measure.map_map hf measurable_snd]
    Causalean.Stat.Quantile.Pushforward.map_pair_isCoupling · Causalean/Stat/Quantile/Pushforward.lean:217
  • map_supported_in_lipschitz_range lemma — A law concentrated on the ordered interval from a to b, mapped by a measurable transformation with a Lipschitz factor that is nonnegative and controls the transformation on that interval, is concentrated on the corresponding bounded image interval.
    μ :
    a b L :
    ℝ
    hab :
    a ≤ b
    hμ :
    μ (Icc a b)ᶜ = 0
    hL :
    0 ≤ L
    f :
    ℝ → ℝ
    hf :
    hLip :
    ∀ x ∈ Icc a b, ∀ y ∈ Icc a b, |f x - f y| ≤ L * |x - y|
    (μ.map f) (Icc (f a - L * (b - a)) (f a + L * (b - a)))ᶜ = 0
    Proof (Lean source)
    lemma map_supported_in_lipschitz_range (μ : Measure ℝ) {a b L : ℝ} (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (hL : 0 ≤ L) (f : ℝ → ℝ) (hf : Measurable f) (hLip : ∀ x ∈ Icc a b, ∀ y ∈ Icc a b, |f x - f y| ≤ L * |x - y|) : (μ.map f) (Icc (f a - L * (b - a)) (f a + L * (b - a)))ᶜ = 0 := by let J := Icc (f a - L * (b - a)) (f a + L * (b - a)) have hpre : f ⁻¹' Jᶜ ⊆ (Icc a b)ᶜ := by intro x hx hxab have hax := hLip x hxab a ⟨le_refl a, hab⟩ have hdist : |x - a| ≤ b - a := by rw [abs_of_nonneg (sub_nonneg.mpr hxab.1)] linarith [hxab.2] have hbound : |f x - f a| ≤ L * (b - a) := hax.trans (mul_le_mul_of_nonneg_left hdist hL) have hj : f x ∈ J := by dsimp [J] have hh := abs_le.mp hbound exact ⟨by linarith [hh.1], by linarith [hh.2]⟩ exact hx hj change (μ.map f) Jᶜ = 0 rw [Measure.map_apply hf measurableSet_Icc.compl] exact measure_mono_null hpre hμ
    Causalean.Stat.Quantile.Pushforward.map_supported_in_lipschitz_range · Causalean/Stat/Quantile/Pushforward.lean:237
  • mapped_coupling_cost_le lemma — A coupling of two probability laws concentrated on the interval from a to b, mapped by a measurable transformation with a Lipschitz factor that controls the transformation there, has image absolute cost at most that factor times its source cost.
    a b L :
    ℝ
    hμ :
    μ (Icc a b)ᶜ = 0
    hν :
    ν (Icc a b)ᶜ = 0
    f :
    ℝ → ℝ
    hf :
    hLip :
    ∀ x ∈ Icc a b, ∀ y ∈ Icc a b, |f x - f y| ≤ L * |x - y|
    π :
    Measure (ℝ × ℝ)
    hπ :
    IsCoupling π μ ν
    (∫ z : ℝ × ℝ, |z.1 - z.2| ∂(π.map (fun z : ℝ × ℝ => (f z.1, f z.2))))
    ≤ L * ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π
    Proof (Lean source)
    lemma mapped_coupling_cost_le (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b L : ℝ} (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) (f : ℝ → ℝ) (hf : Measurable f) (hLip : ∀ x ∈ Icc a b, ∀ y ∈ Icc a b, |f x - f y| ≤ L * |x - y|) {π : Measure (ℝ × ℝ)} (hπ : IsCoupling π μ ν) : (∫ z : ℝ × ℝ, |z.1 - z.2| ∂(π.map (fun z : ℝ × ℝ => (f z.1, f z.2)))) ≤ L * ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π := by letI : IsProbabilityMeasure π := hπ.isProbabilityMeasure have hp : Measurable (fun z : ℝ × ℝ => (f z.1, f z.2)) := (hf.comp measurable_fst).prodMk (hf.comp measurable_snd) have h₁ : ∀ᵐ z ∂π, z.1 ∈ Icc a b := by have hh : ∀ᵐ x ∂μ, x ∈ Icc a b := by rw [ae_iff]; exact hμ rw [← hπ.map_fst] at hh exact (ae_map_iff measurable_fst.aemeasurable measurableSet_Icc).mp hh have h₂ : ∀ᵐ z ∂π, z.2 ∈ Icc a b := by have hh : ∀ᵐ x ∂ν, x ∈ Icc a b := by rw [ae_iff]; exact hν rw [← hπ.map_snd] at hh exact (ae_map_iff measurable_snd.aemeasurable measurableSet_Icc).mp hh have hle : ∀ᵐ z ∂π, |f z.1 - f z.2| ≤ L * |z.1 - z.2| := by filter_upwards [h₁, h₂] with z hz₁ hz₂ exact hLip z.1 hz₁ z.2 hz₂ have hsrc := coupling_abs_cost_integrable μ ν hμ hν hπ have hrhs : Integrable (fun z : ℝ × ℝ => L * |z.1 - z.2|) π := hsrc.const_mul L have hlhs : Integrable (fun z : ℝ × ℝ => |f z.1 - f z.2|) π := by apply hrhs.mono' · exact ((hf.comp measurable_fst).sub (hf.comp measurable_snd)).norm.aestronglyMeasurable · filter_upwards [hle] with z hz rw [Real.norm_eq_abs, abs_abs] exact hz rw [integral_map hp.aemeasurable (by fun_prop : AEStronglyMeasurable (fun z : ℝ × ℝ => |z.1 - z.2|) (π.map (fun z : ℝ × ℝ => (f z.1, f z.2))))] calc (∫ z : ℝ × ℝ, |f z.1 - f z.2| ∂π) ≤ ∫ z : ℝ × ℝ, L * |z.1 - z.2| ∂π := integral_mono_ae hlhs hrhs hle _ = L * ∫ z : ℝ × ℝ, |z.1 - z.2| ∂π := by rw [integral_const_mul]
    Causalean.Stat.Quantile.Pushforward.mapped_coupling_cost_le · Causalean/Stat/Quantile/Pushforward.lean:266
Quantile­Band 4 core · 2 supporting This module inverts a uniform empirical-CDF band through the lower generalized inverse. ★ quantileBand_coverage

Simultaneous quantile bands by CDF inversion

This module inverts a uniform empirical-CDF band through the lower generalized inverse. Its headline confidence band is data-computable: on every covered sample path, the unknown population quantile at an interior level τ lies between the sample quantiles at τ - ε and τ + ε. The reverse inclusion of the sample quantile between shifted population quantiles is retained as a supporting lemma.

def populationQuantileBand reviewed
Causalean.Stat

Given a population law, a band radius, and a quantile level, the supporting population-quantile band is the interval from the population quantile at τ - ε to the population quantile at τ + ε.

Definition (Lean source)
P :
ε :
ℝ
τ :
ℝ
populationQuantileBand P ε τ :
Set ℝ
Icc (quantile P (τ - ε)) (quantile P (τ + ε))
Causalean.Stat.populationQuantileBand · Causalean/Stat/Quantile/QuantileBand.lean:27
def quantileBand reviewed
Causalean.Stat.IIDSample

Given an i.i.d. real sample, a band radius, a sample size, an outcome, and a quantile level, the data-computable quantile confidence band is the interval between the sample quantiles at τ - ε and τ + ε.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
ε :
ℝ
n :
ℕ
ω :
Ω
τ :
ℝ
quantileBand S ε n ω τ :
Set ℝ
Icc (S.sampleQuantile (τ - ε) n ω) (S.sampleQuantile (τ + ε) n ω)
Causalean.Stat.IIDSample.quantileBand · Causalean/Stat/Quantile/QuantileBand.lean:33 · uses IIDSample
def quantileBandCoverageEvent reviewed
Causalean.Stat.IIDSample

Given an i.i.d. real sample, a confidence level, and a sample size, the simultaneous quantile-band coverage event consists of outcomes whose data-computable band contains the population quantile at every level for which both shifted sample-quantile levels are interior.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
α :
ℝ
n :
ℕ
quantileBandCoverageEvent S α n :
Set Ω
{ω | ∀ τ : ℝ, 0 < τ - vcMcDiarmidRadius α n → τ + vcMcDiarmidRadius α n < 1 → quantile P τ ∈ S.quantileBand (vcMcDiarmidRadius α n) n ω τ}
Causalean.Stat.IIDSample.quantileBandCoverageEvent · Causalean/Stat/Quantile/QuantileBand.lean:41 · uses IIDSample
theorem quantileBand_coverage reviewed
Causalean.Stat.IIDSample

Simultaneous data-computable quantile confidence band from VC--McDiarmid. Given an i.i.d. real sample, a positive sample size, and a confidence level between zero and one, with probability at least 1 - α, every unknown population quantile whose VC--McDiarmid-shifted level remains in (0,1) lies between the corresponding lower and upper sample quantiles.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
hn :
0 < n
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
μ (S.quantileBandCoverageEvent α n) ≥ 1 - ofReal α
Proof (Lean source)
theorem IIDSample.quantileBand_coverage (S : IIDSample Ω ℝ μ P) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : μ (S.quantileBandCoverageEvent α n) ≥ 1 - ofReal α := by have hCDF := S.cdfBand_coverage hn hα hα_one exact hCDF.trans (measure_mono fun ω hω => by intro τ hτ_lower hτ_upper apply S.quantile_mem_quantileBand_of_cdfBand (vcMcDiarmidRadius_nonneg α n) hn ω hτ_lower hτ_upper intro x have hx := hω x change cdf P x ∈ Icc (max 0 (S.empiricalCDF x n ω - vcMcDiarmidRadius α n)) (min 1 (S.empiricalCDF x n ω + vcMcDiarmidRadius α n)) at hx exact ⟨(le_max_right _ _).trans hx.1, hx.2.trans (min_le_right _ _)⟩)
Causalean.Stat.IIDSample.quantileBand_coverage · Causalean/Stat/Quantile/QuantileBand.lean:123 · uses IIDSample , quantileBandCoverageEvent
2 supporting declarations (lemmas, instances)
  • sampleQuantile_mem_populationQuantileBand_of_cdfBand theorem — Quantile-band inversion. Given an i.i.d. real sample, a nonnegative uniform-CDF radius, a positive sample size, an outcome, and a quantile level whose lower and upper shifts are interior, if the population CDF lies in the radius-ε empirical band at every threshold, then the sample quantile lies between the population quantiles at τ - ε and τ + ε.
    Ω :
    Type u_1
    shared
    P :
    shared
    S :
    IIDSample Ω ℝ μ P
    ε :
    ℝ
    hε :
    0 ≤ ε
    n :
    ℕ
    hn :
    0 < n
    ω :
    Ω
    τ :
    ℝ
    hτ_lower :
    0 < τ - ε
    hτ_upper :
    τ + ε < 1
    hband :
    ∀ x : ℝ, cdf P x ∈ Icc (S.empiricalCDF x n ω - ε) (S.empiricalCDF x n ω + ε)
    S.sampleQuantile τ n ω ∈ populationQuantileBand P ε τ
    Proof (Lean source)
    theorem IIDSample.sampleQuantile_mem_populationQuantileBand_of_cdfBand (S : IIDSample Ω ℝ μ P) [IsProbabilityMeasure P] {ε : ℝ} (hε : 0 ≤ ε) {n : ℕ} (hn : 0 < n) (ω : Ω) {τ : ℝ} (hτ_lower : 0 < τ - ε) (hτ_upper : τ + ε < 1) (hband : ∀ x : ℝ, cdf P x ∈ Icc (S.empiricalCDF x n ω - ε) (S.empiricalCDF x n ω + ε)) : S.sampleQuantile τ n ω ∈ populationQuantileBand P ε τ := by have hτ0 : 0 < τ := lt_of_lt_of_le hτ_lower (by linarith) have hτ1 : τ < 1 := lt_of_le_of_lt (by linarith) hτ_upper let qhat := S.sampleQuantile τ n ω have hFn_qhat : τ ≤ S.empiricalCDF qhat n ω := (S.sampleQuantile_le_iff hn ω hτ0 hτ1 qhat).mp le_rfl have hband_qhat := hband qhat have hpop_qhat : τ - ε ≤ cdf P qhat := by exact le_trans (by linarith [hFn_qhat]) hband_qhat.1 have hlower : quantile P (τ - ε) ≤ qhat := quantile_le_of_le_cdf hτ_lower hpop_qhat let qupper := quantile P (τ + ε) have hpop_upper : τ + ε ≤ cdf P qupper := le_cdf_quantile hτ_upper have hband_upper := hband qupper have hFn_upper : τ ≤ S.empiricalCDF qupper n ω := by linarith [hpop_upper, hband_upper.2] have hupper : qhat ≤ quantile P (τ + ε) := by change S.sampleQuantile τ n ω ≤ qupper exact (S.sampleQuantile_le_iff hn ω hτ0 hτ1 qupper).mpr hFn_upper exact ⟨hlower, hupper⟩
    Causalean.Stat.IIDSample.sampleQuantile_mem_populationQuantileBand_of_cdfBand · Causalean/Stat/Quantile/QuantileBand.lean:50
  • quantile_mem_quantileBand_of_cdfBand theorem — Data-computable quantile-band inversion. Given an i.i.d. real sample, a nonnegative uniform-CDF radius, a positive sample size, an outcome, and a quantile level whose lower and upper shifts are interior, if the population CDF lies in the radius-ε empirical band at every threshold, then the population quantile at τ lies between the sample quantiles at τ - ε and τ + ε.
    Ω :
    Type u_1
    shared
    P :
    shared
    S :
    IIDSample Ω ℝ μ P
    ε :
    ℝ
    hε :
    0 ≤ ε
    n :
    ℕ
    hn :
    0 < n
    ω :
    Ω
    τ :
    ℝ
    hτ_lower :
    0 < τ - ε
    hτ_upper :
    τ + ε < 1
    hband :
    ∀ x : ℝ, cdf P x ∈ Icc (S.empiricalCDF x n ω - ε) (S.empiricalCDF x n ω + ε)
    quantile P τ ∈ S.quantileBand ε n ω τ
    Proof (Lean source)
    theorem IIDSample.quantile_mem_quantileBand_of_cdfBand (S : IIDSample Ω ℝ μ P) [IsProbabilityMeasure P] {ε : ℝ} (hε : 0 ≤ ε) {n : ℕ} (hn : 0 < n) (ω : Ω) {τ : ℝ} (hτ_lower : 0 < τ - ε) (hτ_upper : τ + ε < 1) (hband : ∀ x : ℝ, cdf P x ∈ Icc (S.empiricalCDF x n ω - ε) (S.empiricalCDF x n ω + ε)) : quantile P τ ∈ S.quantileBand ε n ω τ := by have hτ0 : 0 < τ := lt_of_lt_of_le hτ_lower (by linarith) have hτ1 : τ < 1 := lt_of_le_of_lt (by linarith) hτ_upper let q := quantile P τ have hpop_q : τ ≤ cdf P q := le_cdf_quantile hτ1 have hband_q := hband q have hemp_q : τ - ε ≤ S.empiricalCDF q n ω := by linarith [hpop_q, hband_q.2] have hlower : S.sampleQuantile (τ - ε) n ω ≤ q := (S.sampleQuantile_le_iff hn ω hτ_lower (by linarith) q).mpr hemp_q let qhat := S.sampleQuantile (τ + ε) n ω have hemp_qhat : τ + ε ≤ S.empiricalCDF qhat n ω := (S.sampleQuantile_le_iff hn ω (by linarith) hτ_upper qhat).mp le_rfl have hband_qhat := hband qhat have hpop_qhat : τ ≤ cdf P qhat := by linarith [hemp_qhat, hband_qhat.1] have hupper : q ≤ S.sampleQuantile (τ + ε) n ω := by change quantile P τ ≤ qhat exact quantile_le_of_le_cdf hτ0 hpop_qhat exact ⟨hlower, hupper⟩
    Causalean.Stat.IIDSample.quantile_mem_quantileBand_of_cdfBand · Causalean/Stat/Quantile/QuantileBand.lean:87
Sample­Quantile­Joint 6 core · 7 supporting This file packages coordinatewise Bahadur representations into vector asymptotic linearity and proves weak convergence to a supplied probability law whose characteristic function has the required quadratic exponential fo ★ quantileIF_cross★ sampleQuantileVec_isAsymLinearVec★ sampleQuantileVec_tendsto_of_charFun

Characteristic-Function Limit of a Quantile Vector

This file packages coordinatewise Bahadur representations into vector asymptotic linearity and proves weak convergence to a supplied probability law whose characteristic function has the required quadratic exponential form. It also computes the pairwise quantile influence-function cross-moments.

abbrev eucl reviewed
Causalean.Stat

For a nonnegative integer kk specifying a finite collection of coordinates and a real-valued vector indexed by those coordinates, the Euclidean representation of that vector is the corresponding point of the kk-dimensional Euclidean space.

Definition (Lean source)
k :
ℕ
shared
v :
Fin k → ℝ
eucl v :
(EuclideanSpace.equiv (Fin k) ℝ).symm v
def quantileIFVec reviewed
Causalean.Stat

For a nonnegative integer kk specifying a finite collection of quantile coordinates and coordinatewise quantile levels, population quantiles, and density values, the joint quantile influence function maps each real-valued observation zz to the Euclidean vector whose jjth coordinate is (τj−1{z≤qj})/fj(\tau_j-\mathbf{1}\{z\le q_j\})/f_j.

Definition (Lean source)
k :
ℕ
shared
τ q f :
Fin k → ℝ
quantileIFVec τ q f :
ℝ → EuclideanSpace ℝ (Fin k)
fun z => eucl (fun j => quantileIF (τ j) (q j) (f j) z)
def sampleQuantileVec reviewed
Causalean.Stat.IIDSample

For a measurable sample space carrying a measure, a population measure on the real line, a nonnegative integer kk specifying a finite collection of quantile coordinates, an independent and identically distributed real-valued sample from that population, and a vector of quantile levels, the sample-quantile vector maps every nonnegative integer sample size and sample-space outcome to the Euclidean vector of the corresponding coordinatewise sample quantiles.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
k :
ℕ
shared
S :
IIDSample Ω ℝ μ P
τ :
Fin k → ℝ
sampleQuantileVec S τ :
ℕ → Ω → EuclideanSpace ℝ (Fin k)
fun n ω => eucl (fun j => S.sampleQuantile (τ j) n ω)
Causalean.Stat.IIDSample.sampleQuantileVec · Causalean/Stat/Quantile/SampleQuantileJoint.lean:73 · uses IIDSample
lemma quantileIF_cross reviewed
Causalean.Stat

Covariance entry. Given qⱼ is the population τⱼ-quantile: F(qj)=τjF(q_j)=\tau_j and qₗ is the population τₗ-quantile: F(ql)=τlF(q_l)=\tau_l, the cross-moment of the two quantile influence functions ψτj\psi_{\tau_j} and ψτl\psi_{\tau_l} under the population measure equals (min⁡(τj,τl)−τjτl)/(fjfl)(\min(\tau_j,\tau_l)-\tau_j\tau_l)/(f_jf_l).

Formal statement
P :
shared
τj qj fj τl ql fl :
ℝ
hj :
cdf P qj = τj
hl :
cdf P ql = τl
∫ z, quantileIF τj qj fj z * quantileIF τl ql fl z ∂P = (min τj τl - τj * τl) / (fj * fl)
Proof (Lean source)
lemma quantileIF_cross [IsProbabilityMeasure P] {τj qj fj τl ql fl : ℝ} (hj : cdf P qj = τj) (hl : cdf P ql = τl) : ∫ z, quantileIF τj qj fj z * quantileIF τl ql fl z ∂P = (min τj τl - τj * τl) / (fj * fl) := by -- Product of two lower-ray indicators is the indicator of the smaller ray. have hprod : ∀ z, cdfStat qj z * cdfStat ql z = cdfStat (min qj ql) z := by intro z simp only [cdfStat, Set.indicator_apply, Set.mem_Iic, le_min_iff] by_cases hzj : z ≤ qj <;> by_cases hzl : z ≤ ql <;> simp [hzj, hzl] -- The cdf of the min equals the min of the cdfs (by monotonicity). have hmin : cdf P (min qj ql) = min τj τl := by rcases le_total qj ql with hq | hq · rw [min_eq_left hq, hj, min_eq_left] rw [← hj, ← hl]; exact monotone_cdf P hq · rw [min_eq_right hq, hl, min_eq_right] rw [← hj, ← hl]; exact monotone_cdf P hq -- Expand the product of influence functions. have hexpand : (fun z => quantileIF τj qj fj z * quantileIF τl ql fl z) = (fun z => (τj * τl - τj * cdfStat ql z - τl * cdfStat qj z + cdfStat (min qj ql) z) / (fj * fl)) := by funext z unfold quantileIF rw [div_mul_div_comm, ← hprod z]; ring rw [hexpand] have hil : Integrable (cdfStat ql) P := integrable_cdfStat ql have hij : Integrable (cdfStat qj) P := integrable_cdfStat qj have him : Integrable (cdfStat (min qj ql)) P := integrable_cdfStat (min qj ql) rw [integral_div] have e1 : ∫ z, (τj * τl - τj * cdfStat ql z - τl * cdfStat qj z + cdfStat (min qj ql) z) ∂P = τj * τl - τj * cdf P ql - τl * cdf P qj + cdf P (min qj ql) := by have hB : Integrable (fun z => τj * τl - τj * cdfStat ql z) P := (integrable_const (τj * τl)).sub (hil.const_mul τj) have hC : Integrable (fun z => τl * cdfStat qj z) P := hij.const_mul τl have hA : Integrable (fun z => τj * τl - τj * cdfStat ql z - τl * cdfStat qj z) P := hB.sub hC rw [integral_add hA him, integral_sub hB hC, integral_sub (integrable_const (τj * τl)) (hil.const_mul τj)] simp only [integral_const, probReal_univ, one_smul, integral_const_mul, integral_cdfStat] rw [e1, hl, hj, hmin] ring
theorem sampleQuantileVec_isAsymLinearVec reviewed
Causalean.Stat.IIDSample

The sample-quantile vector is asymptotically linear with the joint influence function ψ. Given a SampleQuantileReg regularity bundle at every coordinate j: interior level τj\tau_j, positive density fjf_j at the population quantile qjq_j, cdf identification, differentiability of the population cdf, and cdf continuity on a positive-radius neighborhood of each target quantile, the vector of sample τ\tau-quantiles is jointly asymptotically linear at the vector of population quantiles, with influence function the joint quantile influence function ψ\psi.

Formal statement
Ω :
Type u_1
shared
P :
shared
k :
ℕ
shared
S :
IIDSample Ω ℝ μ P
τ q f :
Fin k → ℝ
hreg :
∀ j, SampleQuantileReg P (τ j) (q j) (f j)
IsAsymLinearVec (S.sampleQuantileVec τ) (eucl q) (quantileIFVec τ q f) S (fun m => range m)
Proof (Lean source)
theorem IIDSample.sampleQuantileVec_isAsymLinearVec (S : IIDSample Ω ℝ μ P) {τ q f : Fin k → ℝ} (hreg : ∀ j, SampleQuantileReg P (τ j) (q j) (f j)) : IsAsymLinearVec (S.sampleQuantileVec τ) (eucl q) (quantileIFVec τ q f) S (fun m => range m) := by -- Per-coordinate scalar asymptotic linearity. set AL : ∀ j, IsAsymLinear (S.sampleQuantile (τ j)) (q j) (quantileIF (τ j) (q j) (f j)) S (fun m => range m) := fun j => S.sampleQuantile_isAsymLinear (hreg j) with hAL -- The coordinate influence functions, packaged as `g x = (fun j => quantileIF…)`. set g : ℝ → Fin k → ℝ := fun x j => quantileIF (τ j) (q j) (f j) x with hg -- Coordinatewise bound used throughout. have hcoordbound : ∀ x j, |g x j| ≤ (|τ j| + 1) / |f j| := by intro x j have hc0 : 0 ≤ cdfStat (q j) x := cdfStat_nonneg (q j) x have hc1 : cdfStat (q j) x ≤ 1 := cdfStat_le_one (q j) x have hnum : |τ j - cdfStat (q j) x| ≤ |τ j| + 1 := by rw [abs_le] exact ⟨by have := neg_abs_le (τ j); linarith, by have := le_abs_self (τ j); linarith⟩ change |quantileIF (τ j) (q j) (f j) x| ≤ _ unfold quantileIF rw [abs_div, div_eq_mul_inv, div_eq_mul_inv] exact mul_le_mul_of_nonneg_right hnum (inv_nonneg.mpr (abs_nonneg _)) have hg_int : Integrable g P := by -- bounded by a constant (sup-norm ≤ sum of coordinate bounds) on a prob. measure refine (integrable_const (∑ j, (|τ j| + 1) / |f j|)).mono' (measurable_pi_lambda _ (fun j => measurable_quantileIF (τ j) (q j) (f j))).aestronglyMeasurable ?_ filter_upwards with x refine (pi_norm_le_iff_of_nonneg (Finset.sum_nonneg fun j _ => div_nonneg (by positivity) (abs_nonneg _))).2 (fun j => ?_) rw [Real.norm_eq_abs] exact (hcoordbound x j).trans (Finset.single_le_sum (f := fun j => (|τ j| + 1) / |f j|) (fun i _ => div_nonneg (by positivity) (abs_nonneg _)) (Finset.mem_univ j)) refine ⟨?_, ?_, ?_⟩ · -- mean_zero : ∫ quantileIFVec = 0 change ∫ x, eucl (g x) ∂P = 0 rw [ContinuousLinearEquiv.integral_comp_comm (EuclideanSpace.equiv (Fin k) ℝ).symm g] have hzero : (∫ x, g x ∂P) = 0 := by funext j have hproj := ContinuousLinearMap.integral_comp_comm (ContinuousLinearMap.proj (R := ℝ) (φ := fun _ : Fin k => ℝ) j) hg_int simp only [ContinuousLinearMap.proj_apply] at hproj rw [← hproj] exact (AL j).mean_zero rw [hzero, map_zero] · -- finite_var : ‖quantileIFVec‖² ∈ L¹(P) have hsum : (fun x => ‖quantileIFVec τ q f x‖ ^ 2) = fun x => ∑ j, (quantileIF (τ j) (q j) (f j) x) ^ 2 := by funext x exact norm_sq_eucl (g x) rw [hsum] exact integrable_finset_sum _ (fun j _ => quantileIF_sq_integrable) · -- remainder : the vector Bahadur remainder is o_p(1) -- The per-coordinate scalar remainder `Rₙⱼ`. set R : Fin k → ℕ → Ω → ℝ := fun j n ω => sqrt ((range n).card : ℝ) * (S.sampleQuantile (τ j) n ω - q j) - (sqrt ((range n).card : ℝ))⁻¹ * ∑ i ∈ range n, quantileIF (τ j) (q j) (f j) (S.Z i ω) with hR have hRlit : ∀ j, IsLittleOp (R j) (fun _ => (1 : ℝ)) μ := fun j => (AL j).remainder -- The vector bracket equals `eucl (fun j => R j n ω)`. have hbracket : ∀ n ω, sqrt (((range n).card : ℝ)) • (S.sampleQuantileVec τ n ω - eucl q) - (sqrt (((range n).card : ℝ)))⁻¹ • ∑ i ∈ range n, quantileIFVec τ q f (S.Z i ω) = eucl (fun j => R j n ω) := by intro n ω change sqrt _ • (eucl (fun j => S.sampleQuantile (τ j) n ω) - eucl q) - (sqrt _)⁻¹ • ∑ i ∈ range n, eucl (g (S.Z i ω)) = eucl (fun j => R j n ω) rw [← map_sub, ← map_smul, ← map_sum, ← map_smul, ← map_sub] congr 1 funext j simp only [Pi.sub_apply, Pi.smul_apply, Finset.sum_apply, smul_eq_mul, hR, hg] -- `∑ⱼ |Rₙⱼ|` is o_p(1), and the vector norm is bounded by it. have hsum_lit : IsLittleOp (fun n ω => ∑ j, |R j n ω|) (fun _ => (1 : ℝ)) μ := isLittleOp_finset_sum_one univ (fun j n ω => |R j n ω|) (fun j _ => isLittleOp_abs (hRlit j)) refine isLittleOp_of_abs_le_const_mul_one (C := 1) one_pos hsum_lit ?_ intro n ω rw [hbracket n ω] rw [abs_of_nonneg (norm_nonneg _), one_mul, abs_of_nonneg (Finset.sum_nonneg fun j _ => abs_nonneg _)] exact norm_eucl_le_sum_abs (fun j => R j n ω)
theorem sampleQuantileVec_tendsto_of_charFun reviewed
Causalean.Stat.IIDSample

Sample-quantile vector convergence from a target characteristic function. Given an i.i.d. real sample, a SampleQuantileReg bundle at every coordinate, a candidate target probability law, the identity equating its characteristic function to the quadratic exponential determined by the joint influence function, and almost-everywhere measurability of each rescaled estimator, the laws of the rescaled sample-quantile vectors converge weakly to that target.

Formal statement
Ω :
Type u_1
shared
P :
shared
k :
ℕ
shared
S :
IIDSample Ω ℝ μ P
τ q f :
Fin k → ℝ
hreg :
∀ j, SampleQuantileReg P (τ j) (q j) (f j)
hQ :
∀ t : EuclideanSpace ℝ (Fin k),
charFun Q t = exp (-(((∫ z, (⟪t, quantileIFVec τ q f z⟫) ^ 2 ∂P : ℝ)) : ℂ) / 2)
hθn_meas :
∀ n,
AEMeasurable (IsAsymLinearVec.rescaledEstimator (S.sampleQuantileVec τ) (eucl q) (fun m => range m) n) μ
Tendsto (β := ProbabilityMeasure (EuclideanSpace ℝ (Fin k))) (fun n => ⟨μ.map (IsAsymLinearVec.rescaledEstimator (S.sampleQuantileVec τ) (eucl q) (fun m => range m) n), Measure.isProbabilityMeasure_map (hθn_meas n)⟩) atTop (𝓝 ⟨Q, ‹IsProbabilityMeasure Q›⟩)
Proof (Lean source)
theorem IIDSample.sampleQuantileVec_tendsto_of_charFun (S : IIDSample Ω ℝ μ P) {τ q f : Fin k → ℝ} (hreg : ∀ j, SampleQuantileReg P (τ j) (q j) (f j)) (Q : Measure (EuclideanSpace ℝ (Fin k))) [IsProbabilityMeasure Q] (hQ : ∀ t : EuclideanSpace ℝ (Fin k), charFun Q t = exp (-(((∫ z, (⟪t, quantileIFVec τ q f z⟫) ^ 2 ∂P : ℝ)) : ℂ) / 2)) (hθn_meas : ∀ n, AEMeasurable (IsAsymLinearVec.rescaledEstimator (S.sampleQuantileVec τ) (eucl q) (fun m => range m) n) μ) : Tendsto (β := ProbabilityMeasure (EuclideanSpace ℝ (Fin k))) (fun n => ⟨μ.map (IsAsymLinearVec.rescaledEstimator (S.sampleQuantileVec τ) (eucl q) (fun m => range m) n), Measure.isProbabilityMeasure_map (hθn_meas n)⟩) atTop (𝓝 ⟨Q, ‹IsProbabilityMeasure Q›⟩) := by exact (S.sampleQuantileVec_isAsymLinearVec hreg).tendsto_normal_vec_clt (measurable_quantileIFVec τ q f) Q hQ hθn_meas
7 supporting declarations (lemmas, instances)
  • measurable_quantileIFVec lemma — The joint quantile influence function is measurable.
    k :
    ℕ
    shared
    τ q f :
    Fin k → ℝ
    Proof (Lean source)
    @[fun_prop] lemma measurable_quantileIFVec (τ q f : Fin k → ℝ) : Measurable (quantileIFVec τ q f) := by unfold quantileIFVec eucl refine ((EuclideanSpace.equiv (Fin k) ℝ).symm.continuous.measurable).comp ?_ exact measurable_pi_lambda _ (fun j => measurable_quantileIF (τ j) (q j) (f j))
    Causalean.Stat.measurable_quantileIFVec · Causalean/Stat/Quantile/SampleQuantileJoint.lean:80
  • eucl_apply lemma — Coordinate access for eucl: (eucl v) j = v j.
    k :
    ℕ
    shared
    v :
    Fin k → ℝ
    j :
    Fin k
    (eucl v) j = v j
    Proof (Lean source)
    @[simp] lemma eucl_apply (v : Fin k → ℝ) (j : Fin k) : (eucl v) j = v j := rfl
  • norm_sq_eucl lemma — Euclidean norm of a packed vector, squared, is the coordinatewise sum of squares.
    k :
    ℕ
    shared
    v :
    Fin k → ℝ
    ‖eucl v‖ ^ 2 = ∑ j, (v j) ^ 2
    Proof (Lean source)
    lemma norm_sq_eucl (v : Fin k → ℝ) : ‖eucl v‖ ^ 2 = ∑ j, (v j) ^ 2 := by rw [EuclideanSpace.norm_eq, Real.sq_sqrt (Finset.sum_nonneg fun j _ => sq_nonneg _)] refine Finset.sum_congr rfl fun j _ => ?_ rw [Real.norm_eq_abs, sq_abs] rfl
  • norm_eucl_le_sum_abs lemma — The Euclidean norm of a packed vector is bounded by the ℓ¹ norm of its coordinates: ‖eucl v‖ ≤ ∑ j, |v j|.
    k :
    ℕ
    shared
    v :
    Fin k → ℝ
    ‖eucl v‖ ≤ ∑ j, |v j|
    Proof (Lean source)
    lemma norm_eucl_le_sum_abs (v : Fin k → ℝ) : ‖eucl v‖ ≤ ∑ j, |v j| := by have hnonneg : 0 ≤ ∑ j, |v j| := Finset.sum_nonneg fun j _ => abs_nonneg _ have hsq : ‖eucl v‖ ^ 2 ≤ (∑ j, |v j|) ^ 2 := by rw [norm_sq_eucl] have hle : ∑ j, (v j) ^ 2 ≤ (∑ j, |v j|) ^ 2 := by rw [sq, Finset.sum_mul_sum] refine Finset.sum_le_sum fun j _ => ?_ calc (v j) ^ 2 = |v j| * |v j| := by rw [sq, ← abs_mul_abs_self] _ ≤ ∑ i, |v j| * |v i| := by refine Finset.single_le_sum (f := fun i => |v j| * |v i|) (fun i _ => mul_nonneg (abs_nonneg _) (abs_nonneg _)) (Finset.mem_univ j) exact hle exact le_of_pow_le_pow_left₀ (by norm_num) hnonneg hsq
    Causalean.Stat.norm_eucl_le_sum_abs · Causalean/Stat/Quantile/SampleQuantileJoint.lean:154
  • isLittleOp_finset_sum_one lemma — A finite sum of o_p(1) sequences is o_p(1).
    Ω :
    Type u_1
    shared
    ι :
    Type*
    s :
    g :
    ι → ℕ → Ω → ℝ
    h :
    ∀ i ∈ s, IsLittleOp (g i) (fun _ => (1 : ℝ)) μ
    IsLittleOp (fun n ω => ∑ i ∈ s, g i n ω) (fun _ => (1 : ℝ)) μ
    Proof (Lean source)
    lemma isLittleOp_finset_sum_one {ι : Type*} (s : Finset ι) (g : ι → ℕ → Ω → ℝ) (h : ∀ i ∈ s, IsLittleOp (g i) (fun _ => (1 : ℝ)) μ) : IsLittleOp (fun n ω => ∑ i ∈ s, g i n ω) (fun _ => (1 : ℝ)) μ := by classical induction s using Finset.induction_on with | empty => simpa using isLittleOp_zero (μ := μ) | insert a s has ih => have ha := h a (Finset.mem_insert_self a s) have hs := ih (fun i hi => h i (Finset.mem_insert_of_mem hi)) have hadd := IsLittleOp.add_one ha hs simpa [Finset.sum_insert has] using hadd
    Causalean.Stat.isLittleOp_finset_sum_one · Causalean/Stat/Quantile/SampleQuantileJoint.lean:171
  • isLittleOp_of_abs_le_const_mul_one lemma — Domination: if |Xn| ≤ C·|Yn| with Yn o_p(1) and C > 0, then Xn is o_p(1).
    Ω :
    Type u_1
    ℕ → Ω → ℝ
    shared
    C :
    ℝ
    hC :
    0 < C
    hY :
    IsLittleOp Y (fun _ => (1 : ℝ)) μ
    hbound :
    ∀ n ω, |X n ω| ≤ C * |Y n ω|
    IsLittleOp X (fun _ => (1 : ℝ)) μ
    Proof (Lean source)
    lemma isLittleOp_of_abs_le_const_mul_one {X Y : ℕ → Ω → ℝ} {C : ℝ} (hC : 0 < C) (hY : IsLittleOp Y (fun _ => (1 : ℝ)) μ) (hbound : ∀ n ω, |X n ω| ≤ C * |Y n ω|) : IsLittleOp X (fun _ => (1 : ℝ)) μ := IsLittleOp.of_abs_le_const_mul_one hC hY hbound
    Causalean.Stat.isLittleOp_of_abs_le_const_mul_one · Causalean/Stat/Quantile/SampleQuantileJoint.lean:185
  • isLittleOp_abs lemma — The absolute value of an o_p(1) sequence is o_p(1) (the threshold events coincide).
    Ω :
    Type u_1
    ℕ → Ω → ℝ
    shared
    hR :
    IsLittleOp R (fun _ => (1 : ℝ)) μ
    IsLittleOp (fun n ω => |R n ω|) (fun _ => (1 : ℝ)) μ
    Proof (Lean source)
    lemma isLittleOp_abs {R : ℕ → Ω → ℝ} (hR : IsLittleOp R (fun _ => (1 : ℝ)) μ) : IsLittleOp (fun n ω => |R n ω|) (fun _ => (1 : ℝ)) μ := by refine IsLittleOp.of_abs_le_const_mul_one (C := 1) one_pos hR ?_ intro n ω simp
Transport 1 core · 9 supporting This module proves the atom-valid one-dimensional identity between the absolute-distance cost of the shared-uniform quantile coupling and the integrated absolute difference of two CDFs on a common compact interval. ★ quantile_transport_eq_cdf_distance

One-dimensional quantile transport and CDF distance

This module proves the atom-valid one-dimensional identity between the absolute-distance cost of the shared-uniform quantile coupling and the integrated absolute difference of two CDFs on a common compact interval. It also exposes the support, integrability, threshold-kernel, and Tonelli facts used by that identity.

theorem quantile_transport_eq_cdf_distance reviewed
Causalean.Stat.Quantile.Transport

Two probability laws, an ordered common compact interval, and concentration of both laws on that interval give the identity between shared-uniform quantile transport cost and integrated CDF distance.

Formal statement
a b :
ℝ
hab :
a ≤ b
hμ :
μ (Icc a b)ᶜ = 0
hν :
ν (Icc a b)ᶜ = 0
(∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|) = ∫ t in a..b, |cdf μ t - cdf ν t|
Proof (Lean source)
theorem quantile_transport_eq_cdf_distance (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) : (∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|) = ∫ t in a..b, |cdf μ t - cdf ν t| := by exact (quantile_cost_eq_indicator_integral μ ν hμ hν).trans (indicator_integral_eq_cdf_distance μ ν hab)
Causalean.Stat.Quantile.Transport.quantile_transport_eq_cdf_distance · Causalean/Stat/Quantile/Transport.lean:337 · uses quantile
9 supporting declarations (lemmas, instances)
  • quantile_mem_Icc_ae lemma — A probability law concentrated on a closed interval has a quantile in that interval at almost every interior level.
    a b :
    ℝ
    hμ :
    μ (Icc a b)ᶜ = 0
    ∀ᵐ u ∂unifOI, quantile μ u ∈ Icc a b
    Proof (Lean source)
    lemma quantile_mem_Icc_ae (μ : Measure ℝ) [IsProbabilityMeasure μ] {a b : ℝ} (hμ : μ (Icc a b)ᶜ = 0) : ∀ᵐ u ∂unifOI, quantile μ u ∈ Icc a b := by /- Pull back the conull interval along `quantile_map_uniform μ`; use `aemeasurable_quantile_unifOI` to identify the preimage measure. -/ have h : ∀ᵐ x ∂μ, x ∈ Icc a b := by rw [ae_iff] exact hμ rw [← quantile_map_uniform μ] at h exact (ae_map_iff (aemeasurable_quantile_unifOI μ) measurableSet_Icc).mp h
    Causalean.Stat.Quantile.Transport.quantile_mem_Icc_ae · Causalean/Stat/Quantile/Transport.lean:23
  • intervalIntegrable_abs_cdf_sub lemma — Two probability laws have an absolute CDF difference integrable over the given finite interval.
    IntervalIntegrable (fun t : ℝ => |cdf μ t - cdf ν t|) volume a b
    Proof (Lean source)
    lemma intervalIntegrable_abs_cdf_sub (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (a b : ℝ) : IntervalIntegrable (fun t : ℝ => |cdf μ t - cdf ν t|) volume a b := by /- Monotonicity gives measurability of each CDF; `cdf_nonneg` and `cdf_le_one` bound the integrand by one on the finite interval. -/ apply (intervalIntegrable_iff).2 apply Measure.integrableOn_of_bounded (M := 1) (by simp only [uIoc]; exact measure_Ioc_lt_top.ne) · simpa only [Real.norm_eq_abs, Pi.sub_apply] using (((monotone_cdf μ).measurable.sub (monotone_cdf ν).measurable).norm).aestronglyMeasurable · filter_upwards with t rw [Real.norm_eq_abs, abs_abs] have hμ := cdf_nonneg μ t have hν := cdf_nonneg ν t have hμ' := cdf_le_one μ t have hν' := cdf_le_one ν t exact abs_le.mpr ⟨by linarith, by linarith⟩
    Causalean.Stat.Quantile.Transport.intervalIntegrable_abs_cdf_sub · Causalean/Stat/Quantile/Transport.lean:36
  • intervalIntegrable_abs_quantile_sub lemma — Two probability laws concentrated on one closed interval have an integrable absolute quantile difference over the unit interval.
    a b :
    ℝ
    hμ :
    μ (Icc a b)ᶜ = 0
    hν :
    ν (Icc a b)ᶜ = 0
    IntervalIntegrable (fun u : ℝ => |quantile μ u - quantile ν u|) volume 0 1
    Proof (Lean source)
    lemma intervalIntegrable_abs_quantile_sub (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) : IntervalIntegrable (fun u : ℝ => |quantile μ u - quantile ν u|) volume 0 1 := by /- Combine `aemeasurable_quantile_unifOI` with `quantile_mem_Icc_ae`; the distance is bounded by `b-a` almost everywhere. -/ have hmeas : AEStronglyMeasurable (fun u : ℝ => |quantile μ u - quantile ν u|) unifOI := by simpa only [Real.norm_eq_abs, Pi.sub_apply] using (((aemeasurable_quantile_unifOI μ).sub (aemeasurable_quantile_unifOI ν)).norm).aestronglyMeasurable have hbound : ∀ᵐ u ∂unifOI, ‖|quantile μ u - quantile ν u|‖ ≤ b - a := by filter_upwards [quantile_mem_Icc_ae μ hμ, quantile_mem_Icc_ae ν hν] with u hu hv rw [Real.norm_eq_abs, abs_abs] exact abs_le.mpr ⟨by linarith [hu.1, hv.2], by linarith [hu.2, hv.1]⟩ have hrest : volume.restrict (Ioc (0 : ℝ) 1) = unifOI := by rw [unifOI, restrict_Ioo_eq_restrict_Ioc] apply (intervalIntegrable_iff_integrableOn_Ioc_of_le (by norm_num : (0 : ℝ) ≤ 1)).2 change Integrable (fun u : ℝ => |quantile μ u - quantile ν u|) (volume.restrict (Ioc (0 : ℝ) 1)) rw [hrest] exact Integrable.of_bound hmeas (b - a) hbound
    Causalean.Stat.Quantile.Transport.intervalIntegrable_abs_quantile_sub · Causalean/Stat/Quantile/Transport.lean:56
  • threshold_indicator_integral_eq_cdf_distance lemma — Two probability laws and a threshold have a mean lower-ray indicator disagreement equal to the absolute difference of their CDFs there.
    (∫ u in (0 : ℝ)..1, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)|)
    = |cdf μ t - cdf ν t|
    Proof (Lean source)
    lemma threshold_indicator_integral_eq_cdf_distance (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (t : ℝ) : (∫ u in (0 : ℝ)..1, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)|) = |cdf μ t - cdf ν t| := by /- On (0,1), `quantile_le_iff` turns both predicates into `u ≤ cdf _ t`. Their symmetric difference is the interval between the two CDF values, including its right endpoint; that endpoint has zero Lebesgue measure. Use `cdf_nonneg` and `cdf_le_one`. -/ have hcongr : (∫ u in (0 : ℝ)..1, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)|) = ∫ u in (0 : ℝ)..1, |(if u ≤ cdf μ t then (1 : ℝ) else 0) - (if u ≤ cdf ν t then 1 else 0)| := by apply intervalIntegral.integral_congr_Ioo_of_le (by norm_num : (0 : ℝ) ≤ 1) intro u hu change |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)| = |(if u ≤ cdf μ t then (1 : ℝ) else 0) - (if u ≤ cdf ν t then 1 else 0)| simp only [quantile_le_iff hu.1 hu.2] rw [hcongr] exact integral_abs_cut_indicators (cdf μ t) (cdf ν t) (cdf_nonneg μ t) (cdf_le_one μ t) (cdf_nonneg ν t) (cdf_le_one ν t)
    Causalean.Stat.Quantile.Transport.threshold_indicator_integral_eq_cdf_distance · Causalean/Stat/Quantile/Transport.lean:129
  • indicator_kernel_integrable lemma — Two probability laws and a finite interval give an integrable lower-ray disagreement kernel under the product of the uniform-level law and restricted Lebesgue measure.
    Integrable (fun z : ℝ × ℝ => |(if quantile μ z.1 ≤ z.2 then (1 : ℝ) else 0) - (if quantile ν z.1 ≤ z.2 then 1 else 0)|) (unifOI.prod (volume.restrict (Ioc a b)))
    Proof (Lean source)
    lemma indicator_kernel_integrable (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} : Integrable (fun z : ℝ × ℝ => |(if quantile μ z.1 ≤ z.2 then (1 : ℝ) else 0) - (if quantile ν z.1 ≤ z.2 then 1 else 0)|) (unifOI.prod (volume.restrict (Ioc a b))) := by /- Pull a.e. measurability of each quantile on `unifOI` to the product; comparisons with the measurable second projection are a.e. measurable. The kernel is bounded by one, and the product measure is finite. -/ let ρ : Measure (ℝ × ℝ) := unifOI.prod (volume.restrict (Ioc a b)) haveI : IsFiniteMeasure (volume.restrict (Ioc a b)) := isFiniteMeasure_restrict.mpr measure_Ioc_lt_top.ne haveI : IsFiniteMeasure ρ := by dsimp [ρ]; infer_instance have hm : AEStronglyMeasurable (fun z : ℝ × ℝ => quantile μ z.1) ρ := (aemeasurable_quantile_unifOI μ).comp_fst |>.aestronglyMeasurable have hn : AEStronglyMeasurable (fun z : ℝ × ℝ => quantile ν z.1) ρ := (aemeasurable_quantile_unifOI ν).comp_fst |>.aestronglyMeasurable have ht : AEStronglyMeasurable (fun z : ℝ × ℝ => z.2) ρ := measurable_snd.aestronglyMeasurable have hc : AEStronglyMeasurable (fun _ : ℝ × ℝ => (1 : ℝ)) ρ := aestronglyMeasurable_const have hμ : AEStronglyMeasurable (fun z : ℝ × ℝ => if quantile μ z.1 ≤ z.2 then (1 : ℝ) else 0) ρ := by convert hc.indicator₀ (nullMeasurableSet_le hm.aemeasurable ht.aemeasurable) using 1 ext z simp [indicator] have hν : AEStronglyMeasurable (fun z : ℝ × ℝ => if quantile ν z.1 ≤ z.2 then (1 : ℝ) else 0) ρ := by convert hc.indicator₀ (nullMeasurableSet_le hn.aemeasurable ht.aemeasurable) using 1 ext z simp [indicator] have hk : AEStronglyMeasurable (fun z : ℝ × ℝ => |(if quantile μ z.1 ≤ z.2 then (1 : ℝ) else 0) - (if quantile ν z.1 ≤ z.2 then 1 else 0)|) ρ := by simpa only [Real.norm_eq_abs, Pi.sub_apply] using (hμ.sub hν).norm exact Integrable.of_bound hk 1 (by filter_upwards with z split_ifs <;> norm_num)
    Causalean.Stat.Quantile.Transport.indicator_kernel_integrable · Causalean/Stat/Quantile/Transport.lean:159
  • indicator_integral_swap lemma — Two probability laws and an ordered finite interval have equal iterated lower-ray disagreement integrals in either order.
    a b :
    ℝ
    hab :
    a ≤ b
    (∫ u in (0 : ℝ)..1, ∫ t in a..b, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)|)
    = ∫ t in a..b, ∫ u in (0 : ℝ)..1, |(if quantile μ u ≤ t then (1 : ℝ) else 0)
    - (if quantile ν u ≤ t then 1 else 0)|
    Proof (Lean source)
    lemma indicator_integral_swap (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hab : a ≤ b) : (∫ u in (0 : ℝ)..1, ∫ t in a..b, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)|) = ∫ t in a..b, ∫ u in (0 : ℝ)..1, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)| := by /- Write both interval integrals as set integrals on `Ioc`, identify the first factor with `unifOI`, then use `integral_integral_swap` with `indicator_kernel_integrable`. -/ have hrest : volume.restrict (Ioc (0 : ℝ) 1) = unifOI := by rw [unifOI, restrict_Ioo_eq_restrict_Ioc] simp_rw [intervalIntegral.integral_of_le hab, intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1)] rw [hrest] exact integral_integral_swap (indicator_kernel_integrable μ ν)
    Causalean.Stat.Quantile.Transport.indicator_integral_swap · Causalean/Stat/Quantile/Transport.lean:204
  • abs_sub_eq_integral_Icc_indicator lemma — Two points in a common closed interval have a distance equal to the integral of their lower-ray indicator disagreement.
    a b x y :
    ℝ
    hx :
    x ∈ Icc a b
    hy :
    y ∈ Icc a b
    |x - y| = ∫ t in a..b, |(if x ≤ t then (1 : ℝ) else 0) - (if y ≤ t then 1 else 0)|
    Proof (Lean source)
    lemma abs_sub_eq_integral_Icc_indicator {a b x y : ℝ} (hx : x ∈ Icc a b) (hy : y ∈ Icc a b) : |x - y| = ∫ t in a..b, |(if x ≤ t then (1 : ℝ) else 0) - (if y ≤ t then 1 else 0)| := by /- Split on `x ≤ y`. In the first branch the integrand is the indicator of `Ico x y`; in the second it is the indicator of `Ico y x`. Restrict to `Ioc a b`, then use `Real.volume_Ioc` (or the equal-volume half-open variant). Endpoint choices do not change the integral. -/ by_cases hxy : x ≤ y · have heq : ∀ᵐ t ∂volume, |(if x ≤ t then (1 : ℝ) else 0) - (if y ≤ t then 1 else 0)| = (Ioc x y).indicator (fun _ => (1 : ℝ)) t := by filter_upwards [volume.ae_ne x, volume.ae_ne y] with t htx hty have hxt' : x < t ↔ x ≤ t := by constructor · exact le_of_lt · intro h exact lt_of_le_of_ne h (Ne.symm htx) have hyt' : t ≤ y ↔ t < y := by constructor · intro h exact lt_of_le_of_ne h hty · exact le_of_lt by_cases hxt : x ≤ t <;> by_cases hyt : y ≤ t <;> simp_all [indicator, Set.mem_Ioc, not_le] <;> grind rw [intervalIntegral.integral_congr_ae (heq.mono fun t ht _ => ht)] rw [intervalIntegral.integral_of_le (le_trans hx.1 hx.2)] rw [setIntegral_indicator measurableSet_Ioc] have hs : Ioc a b ∩ Ioc x y = Ioc x y := by ext t simp only [Set.mem_inter_iff, Set.mem_Ioc] constructor · exact right · intro ht exact ⟨⟨lt_of_le_of_lt hx.1 ht.1, ht.2.trans hy.2⟩, ht⟩ rw [hs, setIntegral_const] simp [measureReal_def, Real.volume_Ioc, ENNReal.toReal_ofReal (sub_nonneg.mpr hxy), abs_of_nonpos (sub_nonpos.mpr hxy)] · have hyx : y ≤ x := le_of_not_ge hxy have heq : ∀ᵐ t ∂volume, |(if x ≤ t then (1 : ℝ) else 0) - (if y ≤ t then 1 else 0)| = (Ioc y x).indicator (fun _ => (1 : ℝ)) t := by filter_upwards [volume.ae_ne x, volume.ae_ne y] with t htx hty have hxt' : y < t ↔ y ≤ t := by constructor · exact le_of_lt · intro h exact lt_of_le_of_ne h (Ne.symm hty) have hyt' : t ≤ x ↔ t < x := by constructor · intro h exact lt_of_le_of_ne h htx · exact le_of_lt by_cases hxt : x ≤ t <;> by_cases hyt : y ≤ t <;> simp_all [indicator, Set.mem_Ioc, not_le] <;> grind rw [intervalIntegral.integral_congr_ae (heq.mono fun t ht _ => ht)] rw [intervalIntegral.integral_of_le (le_trans hx.1 hx.2)] rw [setIntegral_indicator measurableSet_Ioc] have hs : Ioc a b ∩ Ioc y x = Ioc y x := by ext t simp only [Set.mem_inter_iff, Set.mem_Ioc] constructor · exact right · intro ht exact ⟨⟨lt_of_le_of_lt hy.1 ht.1, ht.2.trans hx.2⟩, ht⟩ rw [hs, setIntegral_const] simp [measureReal_def, Real.volume_Ioc, ENNReal.toReal_ofReal (sub_nonneg.mpr hyx), abs_of_nonneg (sub_nonneg.mpr hyx)]
    Causalean.Stat.Quantile.Transport.abs_sub_eq_integral_Icc_indicator · Causalean/Stat/Quantile/Transport.lean:225
  • quantile_cost_eq_indicator_integral lemma — Two probability laws concentrated on one closed interval have a quantile cost equal to the iterated lower-ray indicator integral.
    a b :
    ℝ
    hμ :
    μ (Icc a b)ᶜ = 0
    hν :
    ν (Icc a b)ᶜ = 0
    (∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|)
    = ∫ u in (0 : ℝ)..1, ∫ t in a..b, |(if quantile μ u ≤ t then (1 : ℝ) else 0)
    - (if quantile ν u ≤ t then 1 else 0)|
    Proof (Lean source)
    lemma quantile_cost_eq_indicator_integral (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hμ : μ (Icc a b)ᶜ = 0) (hν : ν (Icc a b)ᶜ = 0) : (∫ u in (0 : ℝ)..1, |quantile μ u - quantile ν u|) = ∫ u in (0 : ℝ)..1, ∫ t in a..b, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)| := by /- Apply the preceding pointwise identity on the intersection of `quantile_mem_Icc_ae μ hμ` and `quantile_mem_Icc_ae ν hν`. Convert `unifOI` to the interval restriction on `Ioc 0 1` as in `intervalIntegrable_abs_quantile_sub`, then use `intervalIntegral.integral_congr_ae`. -/ have hrest : volume.restrict (Ioc (0 : ℝ) 1) = unifOI := by rw [unifOI, restrict_Ioo_eq_restrict_Ioc] apply intervalIntegral.integral_congr_ae_restrict simp only [uIoc_of_le (by norm_num : (0 : ℝ) ≤ 1)] rw [hrest] filter_upwards [quantile_mem_Icc_ae μ hμ, quantile_mem_Icc_ae ν hν] with u hu hv exact abs_sub_eq_integral_Icc_indicator hu hv
    Causalean.Stat.Quantile.Transport.quantile_cost_eq_indicator_integral · Causalean/Stat/Quantile/Transport.lean:296
  • indicator_integral_eq_cdf_distance lemma — Two probability laws and an ordered closed interval give an iterated quantile-indicator integral equal to their integrated CDF distance.
    a b :
    ℝ
    hab :
    a ≤ b
    (∫ u in (0 : ℝ)..1, ∫ t in a..b, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)|)
    = ∫ t in a..b, |cdf μ t - cdf ν t|
    Proof (Lean source)
    lemma indicator_integral_eq_cdf_distance (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {a b : ℝ} (hab : a ≤ b) : (∫ u in (0 : ℝ)..1, ∫ t in a..b, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)|) = ∫ t in a..b, |cdf μ t - cdf ν t| := by calc _ = ∫ t in a..b, ∫ u in (0 : ℝ)..1, |(if quantile μ u ≤ t then (1 : ℝ) else 0) - (if quantile ν u ≤ t then 1 else 0)| := indicator_integral_swap μ ν hab _ = ∫ t in a..b, |cdf μ t - cdf ν t| := by apply intervalIntegral.integral_congr intro t _ exact threshold_indicator_integral_eq_cdf_distance μ ν t
    Causalean.Stat.Quantile.Transport.indicator_integral_eq_cdf_distance · Causalean/Stat/Quantile/Transport.lean:318
VCMc­Diarmid­Radius 4 core · 1 supporting This module calibrates both proved branches of the VC--McDiarmid bound. ★ empiricalCDF_vc_mcdiarmid_radius

Confidence radii for the VC--McDiarmid empirical-CDF bound

This module calibrates both proved branches of the VC--McDiarmid bound. When its threshold condition holds, the large-deviation branch supplies the smaller square-root radius; otherwise the globally valid VC radius is used.

def vcMcDiarmidGlobalRadius reviewed
Causalean.Stat.Quantile.VCMcDiarmid

For a confidence level and a sample size, the globally valid VC--McDiarmid radius is sqrt (32 * log (8 * (m+1) / α) / m).

Definition (Lean source)
α :
ℝ
m :
ℕ
vcMcDiarmidGlobalRadius α m :
ℝ
sqrt (32 * log (8 * ((m : ℝ) + 1) / α) / (m : ℝ))
Causalean.Stat.Quantile.VCMcDiarmid.vcMcDiarmidGlobalRadius · Causalean/Stat/Quantile/VCMcDiarmidRadius.lean:21
def vcMcDiarmidLargeRadius reviewed
Causalean.Stat.Quantile.VCMcDiarmid

For a confidence level and a sample size, the radius calibrated from the large-threshold VC--McDiarmid branch is sqrt (8 * log (1 / α) / m).

Definition (Lean source)
α :
ℝ
m :
ℕ
vcMcDiarmidLargeRadius α m :
ℝ
sqrt (8 * log (1 / α) / (m : ℝ))
Causalean.Stat.Quantile.VCMcDiarmid.vcMcDiarmidLargeRadius · Causalean/Stat/Quantile/VCMcDiarmidRadius.lean:27
def vcMcDiarmidRadius reviewed
Causalean.Stat.Quantile.VCMcDiarmid

For a confidence level and a sample size, the VC--McDiarmid confidence radius is the minimum of the globally valid radius and the large-threshold radius when the latter satisfies its validity condition, and is the global radius otherwise.

Definition (Lean source)
α :
ℝ
m :
ℕ
vcMcDiarmidRadius α m :
ℝ
if α < 1 ∧
4 * sqrt (2 * log (2 * ((m : ℝ) + 1)) / (m : ℝ))
Causalean.Stat.Quantile.VCMcDiarmid.vcMcDiarmidRadius · Causalean/Stat/Quantile/VCMcDiarmidRadius.lean:33
theorem empiricalCDF_vc_mcdiarmid_radius reviewed
Causalean.Stat.Quantile.VCMcDiarmid

Given a population probability law, a positive sample size, and a confidence level between zero and one, the probability that the empirical CDF exceeds the automatically selected vcMcDiarmidRadius α m is at most α. This radius comes from the proved VC--McDiarmid bound, not the sharp DKW--Massart inequality.

Formal statement
m :
ℕ
hm :
0 < m
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
(Measure.pi (fun _ : Fin m => ρ)) (fixedCDFBadSet ρ (vcMcDiarmidRadius α m))
≤ ofReal α
Proof (Lean source)
theorem empiricalCDF_vc_mcdiarmid_radius (ρ : Measure ℝ) [IsProbabilityMeasure ρ] {m : ℕ} (hm : 0 < m) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : (Measure.pi (fun _ : Fin m => ρ)) (fixedCDFBadSet ρ (vcMcDiarmidRadius α m)) ≤ ofReal α := by by_cases hvalid : α < 1 ∧ 4 * sqrt (2 * log (2 * ((m : ℝ) + 1)) / (m : ℝ)) ≤ vcMcDiarmidLargeRadius α m · rw [vcMcDiarmidRadius, if_pos hvalid] by_cases hbetter : vcMcDiarmidLargeRadius α m ≤ vcMcDiarmidGlobalRadius α m · rw [min_eq_left hbetter] exact empiricalCDF_vc_mcdiarmid_large_radius ρ hm hα hvalid.1 hvalid.2 · rw [min_eq_right (le_of_not_ge hbetter)] exact empiricalCDF_vc_mcdiarmid_global_radius ρ hm hα hα_one · rw [vcMcDiarmidRadius, if_neg hvalid] exact empiricalCDF_vc_mcdiarmid_global_radius ρ hm hα hα_one
Causalean.Stat.Quantile.VCMcDiarmid.empiricalCDF_vc_mcdiarmid_radius · Causalean/Stat/Quantile/VCMcDiarmidRadius.lean:125 · uses fixedCDFBadSet , vcMcDiarmidRadius
1 supporting declaration (lemmas, instances)
CDFBand 3 core · 4 supporting This module turns the product-law VC--McDiarmid deviation inequality into a confidence band on the sample space of an arbitrary IIDSample. ★ cdfBand_coverage

Uniform empirical-CDF confidence bands

This module turns the product-law VC--McDiarmid deviation inequality into a confidence band on the sample space of an arbitrary IIDSample. The band is centered at the empirical CDF and covers the population CDF simultaneously at every real threshold. Its radius is more conservative than the sharp Dvoretzky--Kiefer--Wolfowitz--Massart radius.

def cdfBand reviewed
Causalean.Stat.IIDSample

Given an i.i.d. real sample, a confidence level, a sample size, an outcome, and a threshold, the empirical-CDF confidence band is the empirical-CDF interval of radius vcMcDiarmidRadius α n, clipped to the CDF range [0,1].

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
α :
ℝ
n :
ℕ
ω :
Ω
x :
ℝ
cdfBand S α n ω x :
Set ℝ
Icc (max 0 (S.empiricalCDF x n ω - vcMcDiarmidRadius α n)) (min 1 (S.empiricalCDF x n ω + vcMcDiarmidRadius α n))
Causalean.Stat.IIDSample.cdfBand · Causalean/Stat/Quantile/CDFBand.lean:27 · uses IIDSample
def cdfBandCoverageEvent reviewed
Causalean.Stat.IIDSample

Given an i.i.d. real sample, a confidence level, and a sample size, the simultaneous CDF-band coverage event consists of outcomes for which the population CDF belongs to the empirical band at every real threshold.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
α :
ℝ
n :
ℕ
cdfBandCoverageEvent S α n :
Set Ω
{ω | ∀ x : ℝ, cdf P x ∈ S.cdfBand α n ω x}
Causalean.Stat.IIDSample.cdfBandCoverageEvent · Causalean/Stat/Quantile/CDFBand.lean:36 · uses IIDSample
theorem cdfBand_coverage reviewed
Causalean.Stat.IIDSample

Uniform CDF confidence band from a VC--McDiarmid bound. Given an i.i.d. real sample, a positive sample size, and a confidence level between zero and one, the data-dependent VC--McDiarmid-radius band covers the population CDF simultaneously at every real threshold with probability at least 1 - α.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
hn :
0 < n
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
μ (S.cdfBandCoverageEvent α n) ≥ 1 - ofReal α
Proof (Lean source)
theorem IIDSample.cdfBand_coverage (S : IIDSample Ω ℝ μ P) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : μ (S.cdfBandCoverageEvent α n) ≥ 1 - ofReal α := by letI : IsProbabilityMeasure (Measure.pi (fun _ : Fin n => P)) := inferInstance let E : Set (Fin n → ℝ) := (fixedCDFBadSet P (vcMcDiarmidRadius α n))ᶜ have hbad := empiricalCDF_vc_mcdiarmid_radius P hn hα hα_one have hEprob : Measure.pi (fun _ : Fin n => P) E ≥ 1 - ofReal α := by rw [show E = (fixedCDFBadSet P (vcMcDiarmidRadius α n))ᶜ from rfl, measure_compl (measurableSet_fixedCDFBadSet P _) (MeasureTheory.measure_ne_top _ _), measure_univ] exact tsub_le_tsub_left hbad 1 have htransport := event_pullback_along_iidSample S n (measurableSet_fixedCDFBadSet P _).compl hEprob dsimp only at htransport exact htransport.2.trans (measure_mono fun ω hω => S.mem_cdfBand_of_prefix_not_bad hω)
Causalean.Stat.IIDSample.cdfBand_coverage · Causalean/Stat/Quantile/CDFBand.lean:109 · uses IIDSample , cdfBandCoverageEvent
4 supporting declarations (lemmas, instances)
Glivenko­Cantelli­Rate 3 core · 4 supporting This module derives expectation and convergence-in-probability consequences of the proved finite-sample VC--McDiarmid inequality. ★ integral_uniformCDFDeviation_le_radius_add★ integral_uniformCDFDeviation_le_radius_add★ cdfStat_glivenkoCantelli

Quantitative Glivenko--Cantelli bounds from VC--McDiarmid

This module derives expectation and convergence-in-probability consequences of the proved finite-sample VC--McDiarmid inequality. The expectation statement is written through vcMcDiarmidRadius, so changes to the upstream VC constant propagate without duplicating a numeric tail formula here.

theorem integral_uniformCDFDeviation_le_radius_add reviewed
Causalean.Stat

Integrated VC--McDiarmid expectation bound. Given a population probability law, a positive sample size, and a confidence level between zero and one, the expected uniform empirical-CDF deviation is at most the VC--McDiarmid radius plus α.

Formal statement
n :
ℕ
hn :
0 < n
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
∫ z, uniformCDFDeviation P z ∂(Measure.pi (fun _ : Fin n => P))
≤ vcMcDiarmidRadius α n + α
Proof (Lean source)
theorem integral_uniformCDFDeviation_le_radius_add (P : Measure ℝ) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : ∫ z, uniformCDFDeviation P z ∂(Measure.pi (fun _ : Fin n => P)) ≤ vcMcDiarmidRadius α n + α := by let ν : Measure (Fin n → ℝ) := Measure.pi (fun _ : Fin n => P) let r := vcMcDiarmidRadius α n let B : Set (Fin n → ℝ) := fixedCDFBadSet P r have hr : 0 ≤ r := vcMcDiarmidRadius_nonneg α n have hBmeas : MeasurableSet B := measurableSet_fixedCDFBadSet P r have hdevInt : Integrable (uniformCDFDeviation (m := n) P) ν := integrable_uniformCDFDeviation P have hindInt : Integrable (B.indicator fun _ => (1 : ℝ)) ν := (integrable_const (1 : ℝ)).indicator hBmeas have hdomInt : Integrable (fun z => r + B.indicator (fun _ => (1 : ℝ)) z) ν := (integrable_const r).add hindInt have hpoint (z : Fin n → ℝ) : uniformCDFDeviation P z ≤ r + B.indicator (fun _ => (1 : ℝ)) z := by by_cases hz : z ∈ B · rw [indicator_of_mem hz] exact (uniformCDFDeviation_le_one P z).trans (by linarith) · rw [indicator_of_notMem hz, add_zero] exact le_of_not_gt hz have hbad := empiricalCDF_vc_mcdiarmid_radius P hn hα hα_one have hbadReal : ν.real B ≤ α := by change (ν B).toReal ≤ α calc (ν B).toReal ≤ (ofReal α).toReal := ENNReal.toReal_mono ENNReal.ofReal_ne_top hbad _ = α := ENNReal.toReal_ofReal hα.le calc ∫ z, uniformCDFDeviation P z ∂ν ≤ ∫ z, (r + B.indicator (fun _ => (1 : ℝ)) z) ∂ν := integral_mono hdevInt hdomInt hpoint _ = r + ν.real B := by rw [integral_add (integrable_const r) hindInt, integral_const, integral_indicator hBmeas, setIntegral_const] simp [ν] _ ≤ r + α := by gcongr _ = vcMcDiarmidRadius α n + α := rfl
Causalean.Stat.integral_uniformCDFDeviation_le_radius_add · Causalean/Stat/Quantile/GlivenkoCantelliRate.lean:54 · uses uniformCDFDeviation , vcMcDiarmidRadius
theorem integral_uniformCDFDeviation_le_radius_add reviewed
Causalean.Stat.IIDSample

For an i.i.d. real sample, a positive sample size, and a confidence level between zero and one, the expected uniform empirical-CDF deviation of its first n observations is at most the VC--McDiarmid radius plus α.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
hn :
0 < n
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
∫ ω, uniformCDFDeviation P (fun i : Fin n => S.Z i ω) ∂μ ≤ vcMcDiarmidRadius α n + α
Proof (Lean source)
theorem IIDSample.integral_uniformCDFDeviation_le_radius_add (S : IIDSample Ω ℝ μ P) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : ∫ ω, uniformCDFDeviation P (fun i : Fin n => S.Z i ω) ∂μ ≤ vcMcDiarmidRadius α n + α := by let sampleVec : Ω → (Fin n → ℝ) := fun ω i => S.Z i ω have hsampleVec : Measurable sampleVec := iidSample_finN_measurable S n have hdevMeas : AEStronglyMeasurable (uniformCDFDeviation (m := n) P) (Measure.map sampleVec μ) := (measurable_uniformCDFDeviation P).aestronglyMeasurable rw [← integral_map hsampleVec.aemeasurable hdevMeas, iidSample_finN_pushforward S n] exact integral_uniformCDFDeviation_le_radius_add P hn hα hα_one
Causalean.Stat.IIDSample.integral_uniformCDFDeviation_le_radius_add · Causalean/Stat/Quantile/GlivenkoCantelliRate.lean:102 · uses IIDSample , uniformCDFDeviation , vcMcDiarmidRadius
theorem cdfStat_glivenkoCantelli reviewed
Causalean.Stat.IIDSample

Quantitative Glivenko--Cantelli for lower rays. Given an i.i.d. real sample, the lower-ray indicator class is Glivenko--Cantelli: for every positive tolerance, the probability that some empirical CDF value differs from its population value by at least that tolerance tends to zero.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
Proof (Lean source)
theorem IIDSample.cdfStat_glivenkoCantelli (S : IIDSample Ω ℝ μ P) [IsProbabilityMeasure P] : WeakGlivenkoCantelli S cdfStat := by letI : IsProbabilityMeasure μ := S.indep.isProbabilityMeasure intro ε hε have hle (n : ℕ) : μ {ω | ∃ x : ℝ, ε ≤ |S.sampleMean (cdfStat x) n ω - ∫ z, cdfStat x z ∂P|} ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * (ε / 2) ^ 2) / 32)) := by by_cases hn : n = 0 · subst n calc μ {ω | ∃ x : ℝ, ε ≤ |S.sampleMean (cdfStat x) 0 ω - ∫ z, cdfStat x z ∂P|} ≤ 1 := prob_le_one _ ≤ ofReal (8 * (((0 : ℕ) : ℝ) + 1) * exp (-(((0 : ℕ) : ℝ) * (ε / 2) ^ 2) / 32)) := by norm_num · have hnpos : 0 < n := Nat.pos_of_ne_zero hn calc μ {ω | ∃ x : ℝ, ε ≤ |S.sampleMean (cdfStat x) n ω - ∫ z, cdfStat x z ∂P|} ≤ μ ((fun ω : Ω => fun i : Fin n => S.Z i ω) ⁻¹' fixedCDFBadSet P (ε / 2)) := by apply measure_mono rintro ω ⟨x, hx⟩ change ε / 2 < uniformCDFDeviation P (fun i : Fin n => S.Z i ω) rw [integral_cdfStat] at hx have hpoint : |empiricalCDFVec (fun i : Fin n => S.Z i ω) x - cdf P x| ≤ uniformCDFDeviation P (fun i : Fin n => S.Z i ω) := abs_empiricalCDFVec_sub_cdf_le_uniformCDFDeviation P _ x rw [← S.empiricalCDF_eq_empiricalCDFVec n ω x] at hpoint change ε ≤ |S.empiricalCDF x n ω - cdf P x| at hx linarith _ = (Measure.pi (fun _ : Fin n => P)) (fixedCDFBadSet P (ε / 2)) := by rw [← iidSample_finN_pushforward S n, Measure.map_apply (iidSample_finN_measurable S n) (measurableSet_fixedCDFBadSet P _)] _ ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * (ε / 2) ^ 2) / 32)) := empiricalCDF_vc_mcdiarmid P hnpos (by linarith) exact tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (tendsto_vc_mcdiarmid_bound_zero hε) (Eventually.of_forall fun _ => zero_le) (Eventually.of_forall hle)
4 supporting declarations (lemmas, instances)
Kolmogorov­Smirnov 10 core · 4 supporting This module scales the uniform empirical-CDF deviation by the square root of the sample size to obtain the two-sided Kolmogorov--Smirnov statistic and its upper and lower one-sided variants. ★ ksStatistic_tail_at★ ksStatistic_tail★ ksUpperStatistic_tail★ ksStatistic_tail

Finite-sample Kolmogorov--Smirnov bounds

This module scales the uniform empirical-CDF deviation by the square root of the sample size to obtain the two-sided Kolmogorov--Smirnov statistic and its upper and lower one-sided variants. For finite sample vectors, all three have finite-sample tail bounds inherited from the proved VC--McDiarmid radius theorem. The two-sided and upper bounds are also transported to an arbitrary IIDSample sample space; this file does not provide the parallel transported lower bound.

def KSStatistic reviewed
Causalean.Stat

Given a population law and a finite sample vector, the two-sided Kolmogorov--Smirnov statistic is the square root of the sample size times the uniform absolute empirical-CDF deviation.

Definition (Lean source)
n :
ℕ
P :
z :
Fin n → ℝ
KSStatistic P z :
ℝ
def KSUpperStatistic reviewed
Causalean.Stat

Given a population law and a finite sample vector, the upper one-sided Kolmogorov--Smirnov statistic is the square root of the sample size times the supremum of empirical CDF minus population CDF.

Definition (Lean source)
n :
ℕ
P :
z :
Fin n → ℝ
KSUpperStatistic P z :
ℝ
Causalean.Stat.KSUpperStatistic · Causalean/Stat/Quantile/KolmogorovSmirnov.lean:33
def KSLowerStatistic reviewed
Causalean.Stat

Given a population law and a finite sample vector, the lower one-sided Kolmogorov--Smirnov statistic is the square root of the sample size times the supremum of population CDF minus empirical CDF.

Definition (Lean source)
n :
ℕ
P :
z :
Fin n → ℝ
KSLowerStatistic P z :
ℝ
Causalean.Stat.KSLowerStatistic · Causalean/Stat/Quantile/KolmogorovSmirnov.lean:39
def ksStatistic reviewed
Causalean.Stat.IIDSample

Given an i.i.d. real sample, a sample size, and an outcome, the sample's two-sided Kolmogorov--Smirnov statistic applies KSStatistic to the first n observations.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
ω :
Ω
ksStatistic S n ω :
ℝ
KSStatistic P (fun i : Fin n => S.Z i ω)
Causalean.Stat.IIDSample.ksStatistic · Causalean/Stat/Quantile/KolmogorovSmirnov.lean:45 · uses IIDSample
def ksUpperStatistic reviewed
Causalean.Stat.IIDSample

Given an i.i.d. real sample, a sample size, and an outcome, the sample's upper one-sided Kolmogorov--Smirnov statistic applies KSUpperStatistic to the first n observations.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
ω :
Ω
ksUpperStatistic S n ω :
ℝ
KSUpperStatistic P (fun i : Fin n => S.Z i ω)
Causalean.Stat.IIDSample.ksUpperStatistic · Causalean/Stat/Quantile/KolmogorovSmirnov.lean:51 · uses IIDSample
def ksLowerStatistic reviewed
Causalean.Stat.IIDSample

Given an i.i.d. real sample, a sample size, and an outcome, the sample's lower one-sided Kolmogorov--Smirnov statistic applies KSLowerStatistic to the first n observations.

Definition (Lean source)
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
ω :
Ω
ksLowerStatistic S n ω :
ℝ
KSLowerStatistic P (fun i : Fin n => S.Z i ω)
Causalean.Stat.IIDSample.ksLowerStatistic · Causalean/Stat/Quantile/KolmogorovSmirnov.lean:58 · uses IIDSample
theorem ksStatistic_tail_at reviewed
Causalean.Stat

KS tail at an arbitrary threshold. Given a population probability law, a positive sample size, and a positive threshold, the product-law probability that the two-sided KS statistic exceeds t is at most 8 * (n+1) * exp (-t² / 32).

Formal statement
n :
ℕ
hn :
0 < n
t :
ℝ
ht :
0 < t
(Measure.pi (fun _ : Fin n => P)) {z | t < KSStatistic P z}
≤ ofReal (8 * ((n : ℝ) + 1) * exp (-(t ^ 2) / 32))
Proof (Lean source)
theorem ksStatistic_tail_at (P : Measure ℝ) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {t : ℝ} (ht : 0 < t) : (Measure.pi (fun _ : Fin n => P)) {z | t < KSStatistic P z} ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-(t ^ 2) / 32)) := by have hnR : 0 < (n : ℝ) := Nat.cast_pos.mpr hn have hsqrt : 0 < sqrt (n : ℝ) := Real.sqrt_pos.2 hnR have hsqrt_sq : sqrt (n : ℝ) ^ 2 = n := Real.sq_sqrt hnR.le have hset : {z : Fin n → ℝ | t < KSStatistic P z} = fixedCDFBadSet P (t / sqrt n) := by ext z change t < sqrt (n : ℝ) * uniformCDFDeviation P z ↔ t / sqrt (n : ℝ) < uniformCDFDeviation P z constructor · intro h rw [div_lt_iff₀ hsqrt] simpa [mul_comm] using h · intro h rw [div_lt_iff₀ hsqrt] at h simpa [mul_comm] using h rw [hset] have hmain := empiricalCDF_vc_mcdiarmid P hn (div_pos ht hsqrt) convert hmain using 1 congr 3 field_simp [hsqrt.ne'] exact congrArg (fun x : ℝ => -x) hsqrt_sq
Causalean.Stat.ksStatistic_tail_at · Causalean/Stat/Quantile/KolmogorovSmirnov.lean:87 · uses KSStatistic
theorem ksStatistic_tail reviewed
Causalean.Stat

Finite-sample KS tail bound from VC--McDiarmid. Given a population probability law, a positive sample size, and a confidence level between zero and one, the product-law probability that the two-sided KS statistic exceeds the VC--McDiarmid critical value is at most α.

Formal statement
n :
ℕ
hn :
0 < n
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
(Measure.pi (fun _ : Fin n => P)) {z | sqrt n * vcMcDiarmidRadius α n < KSStatistic P z}
≤ ofReal α
Proof (Lean source)
theorem ksStatistic_tail (P : Measure ℝ) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : (Measure.pi (fun _ : Fin n => P)) {z | sqrt n * vcMcDiarmidRadius α n < KSStatistic P z} ≤ ofReal α := by have hsqrt : 0 < sqrt (n : ℝ) := Real.sqrt_pos.2 (Nat.cast_pos.mpr hn) have hset : {z : Fin n → ℝ | sqrt n * vcMcDiarmidRadius α n < KSStatistic P z} = fixedCDFBadSet P (vcMcDiarmidRadius α n) := by ext z change sqrt (n : ℝ) * vcMcDiarmidRadius α n < sqrt (n : ℝ) * uniformCDFDeviation P z ↔ vcMcDiarmidRadius α n < uniformCDFDeviation P z exact mul_lt_mul_iff_of_pos_left hsqrt rw [hset] exact empiricalCDF_vc_mcdiarmid_radius P hn hα hα_one
theorem ksUpperStatistic_tail reviewed
Causalean.Stat

One-sided finite-sample KS tail bound from VC--McDiarmid. Given a population probability law, a positive sample size, and a confidence level between zero and one, the product-law probability that the upper one-sided KS statistic exceeds the VC--McDiarmid critical value is at most α.

Formal statement
n :
ℕ
hn :
0 < n
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
(Measure.pi (fun _ : Fin n => P)) {z | sqrt n * vcMcDiarmidRadius α n < KSUpperStatistic P z}
≤ ofReal α
Proof (Lean source)
theorem ksUpperStatistic_tail (P : Measure ℝ) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : (Measure.pi (fun _ : Fin n => P)) {z | sqrt n * vcMcDiarmidRadius α n < KSUpperStatistic P z} ≤ ofReal α := by have hsqrt : 0 < sqrt (n : ℝ) := Real.sqrt_pos.2 (Nat.cast_pos.mpr hn) calc (Measure.pi (fun _ : Fin n => P)) {z | sqrt n * vcMcDiarmidRadius α n < KSUpperStatistic P z} ≤ (Measure.pi (fun _ : Fin n => P)) (fixedCDFBadSet P (vcMcDiarmidRadius α n)) := by apply measure_mono intro z hz change sqrt (n : ℝ) * vcMcDiarmidRadius α n < sqrt (n : ℝ) * upperCDFDeviation P z at hz change vcMcDiarmidRadius α n < uniformCDFDeviation P z exact ((mul_lt_mul_iff_of_pos_left hsqrt).mp hz).trans_le (upperCDFDeviation_le_uniformCDFDeviation P z) _ ≤ ofReal α := empiricalCDF_vc_mcdiarmid_radius P hn hα hα_one
theorem ksStatistic_tail reviewed
Causalean.Stat.IIDSample

For an i.i.d. real sample, a positive sample size, and a confidence level between zero and one, the probability that its KS statistic exceeds the VC--McDiarmid critical value is at most α.

Formal statement
Ω :
Type u_1
shared
P :
shared
S :
IIDSample Ω ℝ μ P
n :
ℕ
hn :
0 < n
α :
ℝ
hα :
0 < α
hα_one :
α ≤ 1
μ {ω | sqrt n * vcMcDiarmidRadius α n < S.ksStatistic n ω} ≤ ofReal α
Proof (Lean source)
theorem IIDSample.ksStatistic_tail (S : IIDSample Ω ℝ μ P) [IsProbabilityMeasure P] {n : ℕ} (hn : 0 < n) {α : ℝ} (hα : 0 < α) (hα_one : α ≤ 1) : μ {ω | sqrt n * vcMcDiarmidRadius α n < S.ksStatistic n ω} ≤ ofReal α := by let sampleVec : Ω → (Fin n → ℝ) := fun ω i => S.Z i ω have hsampleVec : Measurable sampleVec := iidSample_finN_measurable S n have hset : {ω | sqrt n * vcMcDiarmidRadius α n < S.ksStatistic n ω} = sampleVec ⁻¹' {z | sqrt n * vcMcDiarmidRadius α n < KSStatistic P z} := rfl have htailMeas : MeasurableSet {z : Fin n → ℝ | sqrt n * vcMcDiarmidRadius α n < KSStatistic P z} := by exact measurableSet_lt measurable_const ((measurable_uniformCDFDeviation P).const_mul _) rw [hset, ← Measure.map_apply hsampleVec htailMeas] rw [iidSample_finN_pushforward S n] exact ksStatistic_tail P hn hα hα_one
4 supporting declarations (lemmas, instances)
VCMc­Diarmid 5 core · 3 supporting This module proves a distribution-free finite-sample exponential bound for the uniform empirical-CDF deviation under a canonical iid product law. ★ empiricalCDF_vc_mcdiarmid_large

A VC--McDiarmid bound for uniform empirical-CDF deviation

This module proves a distribution-free finite-sample exponential bound for the uniform empirical-CDF deviation under a canonical iid product law. Real lower half-lines have at most n+1 traces on an n-point sample. Finite-pattern Rademacher control, symmetrization, and McDiarmid's inequality therefore give the following distribution-free VC bound

8 * (n+1) * exp (-n * ε^2 / 32).

The module also provides upper and lower one-sided forms. The sharp Dvoretzky--Kiefer--Wolfowitz--Massart bound 2 * exp (-2 * n * ε^2) remains outside its scope.

def upperCDFDeviation reviewed
Causalean.Stat.Quantile.VCMcDiarmid

For a population law on the real line and a finite sample vector, the upper one-sided empirical-CDF deviation is the supremum of the empirical CDF minus the population CDF over all real thresholds.

Definition (Lean source)
n :
ℕ
ρ :
x :
Fin n → ℝ
upperCDFDeviation ρ x :
ℝ
sSup (Set.range fun y : ℝ => empiricalCDFVec x y - cdf ρ y)
Causalean.Stat.Quantile.VCMcDiarmid.upperCDFDeviation · Causalean/Stat/Quantile/VCMcDiarmid.lean:318
def lowerCDFDeviation reviewed
Causalean.Stat.Quantile.VCMcDiarmid

For a population law on the real line and a finite sample vector, the lower one-sided empirical-CDF deviation is the supremum of the population CDF minus the empirical CDF over all real thresholds.

Definition (Lean source)
n :
ℕ
ρ :
x :
Fin n → ℝ
lowerCDFDeviation ρ x :
ℝ
sSup (Set.range fun y : ℝ => cdf ρ y - empiricalCDFVec x y)
Causalean.Stat.Quantile.VCMcDiarmid.lowerCDFDeviation · Causalean/Stat/Quantile/VCMcDiarmid.lean:324
def upperCDFBadSet reviewed
Causalean.Stat.Quantile.VCMcDiarmid

For a population law and a deviation threshold, the upper one-sided empirical-CDF bad set contains the sample vectors whose upper deviation is greater than that threshold.

Definition (Lean source)
n :
ℕ
ρ :
ε :
ℝ
upperCDFBadSet ρ ε :
Set (Fin n → ℝ)
{x | upperCDFDeviation ρ x > ε}
Causalean.Stat.Quantile.VCMcDiarmid.upperCDFBadSet · Causalean/Stat/Quantile/VCMcDiarmid.lean:330
def lowerCDFBadSet reviewed
Causalean.Stat.Quantile.VCMcDiarmid

For a population law and a deviation threshold, the lower one-sided empirical-CDF bad set contains the sample vectors whose lower deviation is greater than that threshold.

Definition (Lean source)
n :
ℕ
ρ :
ε :
ℝ
lowerCDFBadSet ρ ε :
Set (Fin n → ℝ)
{x | lowerCDFDeviation ρ x > ε}
Causalean.Stat.Quantile.VCMcDiarmid.lowerCDFBadSet · Causalean/Stat/Quantile/VCMcDiarmid.lean:336
theorem empiricalCDF_vc_mcdiarmid_large reviewed
Causalean.Stat.Quantile.VCMcDiarmid

Given a population probability law, a positive sample size, a positive threshold, and the large-threshold condition, the uniform empirical-CDF tail is at most exp (-n * ε² / 8).

Formal statement
n :
ℕ
hn :
0 < n
ε :
ℝ
hε :
0 < ε
hlarge :
4 * sqrt (2 * log (2 * ((n : ℝ) + 1)) / (n : ℝ)) ≤ ε
(Measure.pi (fun _ : Fin n => ρ)) (fixedCDFBadSet ρ ε)
≤ ofReal (exp (-((n : ℝ) * ε ^ 2) / 8))
Proof (Lean source)
theorem empiricalCDF_vc_mcdiarmid_large (ρ : Measure ℝ) [IsProbabilityMeasure ρ] {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) (hlarge : 4 * sqrt (2 * log (2 * ((n : ℝ) + 1)) / (n : ℝ)) ≤ ε) : (Measure.pi (fun _ : Fin n => ρ)) (fixedCDFBadSet ρ ε) ≤ ofReal (exp (-((n : ℝ) * ε ^ 2) / 8)) := by apply (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).1 rw [ENNReal.toReal_ofReal (Real.exp_pos _).le] exact empiricalCDF_vc_mcdiarmid_large_toReal ρ hn hε hlarge
Causalean.Stat.Quantile.VCMcDiarmid.empiricalCDF_vc_mcdiarmid_large · Causalean/Stat/Quantile/VCMcDiarmid.lean:413 · uses fixedCDFBadSet
3 supporting declarations (lemmas, instances)
  • empiricalCDF_vc_mcdiarmid theorem — Given an arbitrary population probability law on the real line, a positive sample size, and a positive deviation threshold, the product-law probability that the empirical CDF differs uniformly from the population CDF by more than that threshold is at most 8 * (n+1) * exp (-n * ε² / 32).
    n :
    ℕ
    hn :
    0 < n
    ε :
    ℝ
    hε :
    0 < ε
    (Measure.pi (fun _ : Fin n => ρ)) (fixedCDFBadSet ρ ε)
    ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * ε ^ 2) / 32))
    Proof (Lean source)
    theorem empiricalCDF_vc_mcdiarmid (ρ : Measure ℝ) [IsProbabilityMeasure ρ] {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) : (Measure.pi (fun _ : Fin n => ρ)) (fixedCDFBadSet ρ ε) ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * ε ^ 2) / 32)) := by apply (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).1 rw [ENNReal.toReal_ofReal] · exact empiricalCDF_vc_mcdiarmid_toReal ρ hn hε · positivity
    Causalean.Stat.Quantile.VCMcDiarmid.empiricalCDF_vc_mcdiarmid · Causalean/Stat/Quantile/VCMcDiarmid.lean:495
  • empiricalCDF_vc_mcdiarmid_upper theorem — Given an arbitrary population probability law on the real line, a positive sample size, and a positive deviation threshold, the product-law probability that the empirical CDF exceeds the population CDF somewhere by more than that threshold is at most 8 * (n+1) * exp (-n * ε² / 32).
    n :
    ℕ
    hn :
    0 < n
    ε :
    ℝ
    hε :
    0 < ε
    (Measure.pi (fun _ : Fin n => ρ)) (upperCDFBadSet ρ ε)
    ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * ε ^ 2) / 32))
    Proof (Lean source)
    theorem empiricalCDF_vc_mcdiarmid_upper (ρ : Measure ℝ) [IsProbabilityMeasure ρ] {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) : (Measure.pi (fun _ : Fin n => ρ)) (upperCDFBadSet ρ ε) ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * ε ^ 2) / 32)) := by have hmono : (Measure.pi (fun _ : Fin n => ρ)) (upperCDFBadSet ρ ε) ≤ (Measure.pi (fun _ : Fin n => ρ)) (fixedCDFBadSet ρ ε) := by apply measure_mono intro x hx change ε < upperCDFDeviation ρ x at hx change ε < uniformCDFDeviation ρ x exact hx.trans_le (upperCDFDeviation_le_uniformCDFDeviation ρ x) exact hmono.trans (empiricalCDF_vc_mcdiarmid ρ hn hε)
    Causalean.Stat.Quantile.VCMcDiarmid.empiricalCDF_vc_mcdiarmid_upper · Causalean/Stat/Quantile/VCMcDiarmid.lean:513
  • empiricalCDF_vc_mcdiarmid_lower theorem — Given an arbitrary population probability law on the real line, a positive sample size, and a positive deviation threshold, the product-law probability that the population CDF exceeds the empirical CDF somewhere by more than that threshold is at most 8 * (n+1) * exp (-n * ε² / 32).
    n :
    ℕ
    hn :
    0 < n
    ε :
    ℝ
    hε :
    0 < ε
    (Measure.pi (fun _ : Fin n => ρ)) (lowerCDFBadSet ρ ε)
    ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * ε ^ 2) / 32))
    Proof (Lean source)
    theorem empiricalCDF_vc_mcdiarmid_lower (ρ : Measure ℝ) [IsProbabilityMeasure ρ] {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) : (Measure.pi (fun _ : Fin n => ρ)) (lowerCDFBadSet ρ ε) ≤ ofReal (8 * ((n : ℝ) + 1) * exp (-((n : ℝ) * ε ^ 2) / 32)) := by have hmono : (Measure.pi (fun _ : Fin n => ρ)) (lowerCDFBadSet ρ ε) ≤ (Measure.pi (fun _ : Fin n => ρ)) (fixedCDFBadSet ρ ε) := by apply measure_mono intro x hx change ε < lowerCDFDeviation ρ x at hx change ε < uniformCDFDeviation ρ x exact hx.trans_le (lowerCDFDeviation_le_uniformCDFDeviation ρ x) exact hmono.trans (empiricalCDF_vc_mcdiarmid ρ hn hε)
    Causalean.Stat.Quantile.VCMcDiarmid.empiricalCDF_vc_mcdiarmid_lower · Causalean/Stat/Quantile/VCMcDiarmid.lean:531