class

Chi2

extendsGamma
Chi2(df: Tensor | float, validate_args: bool | None = None)
source

Chi-squared distribution with kk degrees of freedom.

Distribution of the sum of squares of kk independent standard Normal random variables. Foundational in classical statistics: arises in the likelihood-ratio test (Wilks' theorem), Pearson's goodness-of-fit, confidence intervals for variance, and many F-test /t-test derivations.

Equivalent to a Gamma with shape k/2k/2 and rate 1/21/2: χ2(k)=Gamma(k/2,1/2)\chi^2(k) = \mathrm{Gamma}(k/2,\, 1/2).

Parameters

dfTensor or float
Degrees of freedom k>0k > 0. Need not be an integer.
validate_argsbool= None
If True, validate parameter constraints at construction time.

Notes

Probability density on x>0x > 0:

p(x;k)=12k/2Γ(k/2)xk/21ex/2p(x; k) = \frac{1}{2^{k/2} \Gamma(k/2)} x^{k/2 - 1} e^{-x/2}

Moments:

E[X]=k,Var[X]=2k,Mode=max(k2,0)\mathbb{E}[X] = k, \qquad \mathrm{Var}[X] = 2k, \qquad \mathrm{Mode} = \max(k - 2, 0)

Special cases:

  • k=1k = 1 → squared standard Normal.
  • k=2k = 2Exponential(1/2)\mathrm{Exponential}(1/2).
  • Sum: χ2(k1)+χ2(k2)χ2(k1+k2)\chi^2(k_1) + \chi^2(k_2) \sim \chi^2(k_1 + k_2).

By the central limit theorem, (χ2(k)k)/2kN(0,1)(\chi^2(k) - k)/\sqrt{2k} \to \mathcal{N}(0, 1) as kk \to \infty.

Examples

>>> import lucid
>>> from lucid.distributions import Chi2
>>> d = Chi2(df=4.0)
>>> d.mean
Tensor(4.0)
>>> d.sample((4,))
Tensor([...])

Methods (1)

dunder

__init__

None
__init__(df: Tensor | float, validate_args: bool | None = None)
source

Construct a Chi-squared distribution.

Parameters

dfTensor | float
Degrees of freedom k>0k > 0.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Notes

χ2(k)\chi^2(k) is a special case of the Gamma distribution:

χ2(k)=Gamma ⁣(k2,  12)\chi^2(k) = \text{Gamma}\!\left(\frac{k}{2},\; \frac{1}{2}\right)

It arises as the distribution of the sum of squares of kk independent standard Normal variables, and is fundamental in hypothesis testing (e.g., goodness-of-fit tests, likelihood-ratio tests).

Examples

>>> from lucid.distributions import Chi2
>>> d = Chi2(df=4.0)
>>> d.mean  # k = 4
Tensor(4.0)