Documentation

TauCeti.Probability.Distributions.ChiSquared.Basic

The chi-squared distribution #

The chi-squared law with k degrees of freedom is the gamma law of shape k / 2 and rate 1 / 2. This file defines it for every real k, records its three parameter regimes, and transports the elementary theory of the gamma law across the bridge: the density, the cumulative distribution function, the mean k, the variance 2 * k, the exponential-moment domain Set.Iio (1 / 2), the moment- and cumulant-generating functions there, and the characteristic function. It also proves that the family is additive in its degrees of freedom.

The three regimes. Only 0 < k gives a gamma law. At k = 0 the shape would degenerate, and the law is defined to be Measure.dirac 0: that is the value forced by additivity, since a convolution unit must be a point mass at the origin, and it is the law of an empty sum of squared standard Gaussians. Below 0 there is no law at all, and the measure is 0. The boundary at k = 0 is singular with respect to Lebesgue measure, so it carries its own moment and transform formulas rather than a density.

Main definitions #

Main results #

Implementation #

Every positive-parameter statement is the gamma statement of shape k / 2 and rate 1 / 2, read through chiSquaredMeasure_eq_gammaMeasure; nothing is recomputed. The arithmetic that remains is the substitution r = 1 / 2 in the gamma formulas: it turns a / r into k, a / r ^ 2 into 2 * k, and (1 - t / r) ^ (-a) into (1 - 2 * t) ^ (-(k / 2)).

The density is stated in the textbook normalisation 2 ^ (k / 2) * Γ (k / 2) rather than as gammaPDFReal (k / 2) (1 / 2), and chiSquaredPDFReal_eq_gammaPDFReal identifies the two; the only content of that identification is (1 / 2) ^ (k / 2) = (2 ^ (k / 2))⁻¹.

The boundary k = 0 uses the Dirac formulas of TauCeti/Probability/Distributions/Dirac.lean together with Mathlib's ProbabilityTheory.mgf_dirac', ProbabilityTheory.variance_dirac and MeasureTheory.charFun_dirac. Its exponential-moment domain is all of ℝ, strictly larger than the positive-parameter domain Set.Iio (1 / 2), which is why the two regimes cannot share a statement.

References #

The density #

noncomputable def TauCeti.Probability.chiSquaredPDFReal (k x : ℝ) :

The candidate density formula for the chi-squared law with k degrees of freedom, in the textbook normalisation: x ^ (k / 2 - 1) * exp (-x / 2) / (2 ^ (k / 2) * Γ (k / 2)) on the nonnegative half-line, and 0 below it. It is a probability density when 0 < k.

Instances For
    noncomputable def TauCeti.Probability.chiSquaredPDF (k x : ℝ) :

    The ℝ≥0∞-valued companion to chiSquaredPDFReal. It is a probability density when 0 < k.

    Instances For

      The extended candidate density is obtained from its real companion.

      @[simp]
      theorem TauCeti.Probability.chiSquaredPDFReal_of_nonneg {k x : ℝ} (hx : 0 ≤ x) :
      chiSquaredPDFReal k x = x ^ (k / 2 - 1) * Real.exp (-x / 2) / (2 ^ (k / 2) * Real.Gamma (k / 2))

      On the nonnegative half-line, the candidate real-valued chi-squared density is given by its textbook formula.

      @[simp]

      Below zero, the candidate real-valued chi-squared density vanishes.

      @[simp]
      theorem TauCeti.Probability.chiSquaredPDF_of_nonneg {k x : ℝ} (hx : 0 ≤ x) :
      chiSquaredPDF k x = ENNReal.ofReal (x ^ (k / 2 - 1) * Real.exp (-x / 2) / (2 ^ (k / 2) * Real.Gamma (k / 2)))

      On the nonnegative half-line, the ℝ≥0∞-valued candidate chi-squared density is given by its textbook formula.

      @[simp]

      Below zero, the ℝ≥0∞-valued candidate chi-squared density vanishes.

      @[simp]

      At zero degrees of freedom the real candidate density vanishes identically.

      @[simp]

      At zero degrees of freedom the extended candidate density vanishes identically.

      The chi-squared density is the gamma density of shape k / 2 and rate 1 / 2.

      The ℝ≥0∞-valued chi-squared density is the gamma density of shape k / 2 and rate 1 / 2.

      The chi-squared density is nonnegative for nonnegative degrees of freedom.

      The real-valued chi-squared density is measurable.

      The chi-squared density is measurable.

      The measure and its three regimes #

      The chi-squared law with k degrees of freedom: the gamma law of shape k / 2 and rate 1 / 2 for 0 < k, the point mass at the origin for k = 0, and the zero measure for k < 0.

      Instances For

        For positive degrees of freedom the chi-squared law is a gamma law.

        @[simp]

        At zero degrees of freedom the chi-squared law is the point mass at the origin.

        @[simp]

        There is no chi-squared law with negative degrees of freedom: the measure is zero.

        The chi-squared law is a probability measure for every nonnegative number of degrees of freedom, the boundary k = 0 included.

        A chi-squared law of positive degree has no atoms.

        @[simp]

        A chi-squared law of positive degree gives zero mass to every singleton.

        A chi-squared variable of positive degree is positive almost surely.

        For a chi-squared variable V with k > 0 degrees of freedom, the normalized square root √(V / k), the denominator of Student-type ratios, is positive almost surely.

        Every chi-squared measure is carried by the nonnegative half-line, including its Dirac and invalid zero-measure cases.

        For positive degrees of freedom the chi-squared law has the chi-squared density with respect to Lebesgue measure.

        The chi-squared family is measurable in its degrees of freedom, so it can be used as a kernel.

        Densities of random variables #

        A variable with a chi-squared law of positive degrees of freedom has a density.

        The density of a chi-squared law of positive degrees of freedom is chiSquaredPDF.

        The Radon–Nikodym derivative of a chi-squared law of positive degrees of freedom is chiSquaredPDF.

        The cumulative distribution function #

        @[simp]

        The cumulative distribution function of a chi-squared law with positive degrees of freedom is the regularized lower incomplete gamma function P (k / 2, x / 2).

        At zero degrees of freedom the cumulative distribution function is the unit step at the origin.

        Moments #

        At zero degrees of freedom the mean is 0.

        @[simp]

        The mean of a chi-squared law with nonnegative degrees of freedom is its number of degrees of freedom.

        @[simp]

        The variance of a chi-squared law with nonnegative degrees of freedom is twice its number of degrees of freedom.

        @[simp]

        A real power is integrable under a positive-degree chi-squared law exactly when its exponent is greater than minus half the number of degrees of freedom.

        theorem TauCeti.Probability.integral_rpow_chiSquaredMeasure {k q : ℝ} (hk : 0 < k) (hq : -(k / 2) < q) :
        ∫ (x : ℝ), x ^ q ∂chiSquaredMeasure k = 2 ^ q * Real.Gamma (k / 2 + q) / Real.Gamma (k / 2)

        The real-power moment of a positive-degree chi-squared law, on its exact integrability domain.

        theorem TauCeti.Probability.integrable_prod_rpow_pi_chiSquaredMeasure_iff {ι : Type u_2} [Fintype ι] {k : ι → ℝ} (hk : ∀ (i : ι), 0 < k i) (q : ℝ) :
        MeasureTheory.Integrable (fun (x : ι → ℝ) => ∏ i : ι, x i ^ q) (MeasureTheory.Measure.pi fun (i : ι) => chiSquaredMeasure (k i)) ↔ ∀ (i : ι), -(k i / 2) < q

        A product of real powers of independent positive-degree chi-squared coordinates is integrable exactly when the exponent is greater than minus half of every coordinate's degrees of freedom.

        Exponential moments and transforms #

        @[simp]

        The exponential moments of a chi-squared law with positive degrees of freedom are exactly those of rate t < 1 / 2.

        @[simp]
        theorem TauCeti.Probability.mgf_id_chiSquaredMeasure {k : ℝ} (hk : 0 ≤ k) {t : ℝ} (ht : t < 2⁻¹) :

        The moment-generating function of a chi-squared law with nonnegative degrees of freedom on the half-line t < 2⁻¹.

        @[simp]
        theorem TauCeti.Probability.cgf_id_chiSquaredMeasure {k : ℝ} (hk : 0 ≤ k) {t : ℝ} (ht : t < 2⁻¹) :

        The cumulant-generating function of a chi-squared law with nonnegative degrees of freedom on the half-line t < 2⁻¹. It is the real logarithm of TauCeti.Probability.mgf_id_chiSquaredMeasure.

        At zero degrees of freedom the characteristic function is identically 1.

        @[simp]

        The characteristic function of a chi-squared law with nonnegative degrees of freedom, at every real t. The base has real part 1, so the principal power does not meet the branch cut.

        At zero degrees of freedom the moment-generating function is identically 1.

        At zero degrees of freedom the cumulant-generating function is identically 0.

        Additivity and the exponential law #

        Degrees of freedom add under convolution, including at the boundary k = 0, where the chi-squared law is the convolution unit.

        theorem TauCeti.Probability.iIndepFun.hasLaw_sum_chiSquared {Ω : Type u_1} [MeasurableSpace Ω] {P : MeasureTheory.Measure Ω} {ι : Type u_2} [Fintype ι] {Y : ι → Ω → ℝ} {k : ι → ℝ} (hindep : ProbabilityTheory.iIndepFun Y P) (hlaw : ∀ (i : ι), ProbabilityTheory.HasLaw (Y i) (chiSquaredMeasure (k i)) P) :
        ProbabilityTheory.HasLaw (fun (ω : Ω) => ∑ i : ι, Y i ω) (chiSquaredMeasure (∑ i : ι, k i)) P

        A finite sum of independent chi-squared variables has the chi-squared law whose degrees of freedom are the sum of the individual degrees of freedom.

        Two degrees of freedom give the exponential law of rate 1 / 2.