Learn R Programming

distributional (version 0.6.0)

dist_chisq: The (non-central) Chi-Squared Distribution

Description

[Stable]

Chi-square distributions show up often in frequentist settings as the sampling distribution of test statistics, especially in maximum likelihood estimation settings.

Usage

dist_chisq(df, ncp = 0)

Arguments

df

Degrees of freedom (non-centrality parameter). Can be any positive real number.

ncp

Non-centrality parameter. Can be any non-negative real number. Defaults to 0 (central chi-squared distribution).

Details

We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_chisq.html

In the following, let \(X\) be a \(\chi^2\) random variable with df = \(k\) and ncp = \(\lambda\).

Support: \(R^+\), the set of positive real numbers

Mean: \(k + \lambda\)

Variance: \(2(k + 2\lambda)\)

Probability density function (p.d.f):

For the central chi-squared distribution (\(\lambda = 0\)):

$$ f(x) = \frac{1}{2^{k/2} \Gamma(k/2)} x^{k/2 - 1} e^{-x/2} $$

For the non-central chi-squared distribution (\(\lambda > 0\)):

$$ f(x) = \frac{1}{2} e^{-(x+\lambda)/2} \left(\frac{x}{\lambda}\right)^{k/4-1/2} I_{k/2-1}\left(\sqrt{\lambda x}\right) $$

where \(I_\nu(z)\) is the modified Bessel function of the first kind.

Cumulative distribution function (c.d.f):

For the central chi-squared distribution (\(\lambda = 0\)):

$$ F(x) = \frac{\gamma(k/2, x/2)}{\Gamma(k/2)} = P(k/2, x/2) $$

where \(\gamma(s, x)\) is the lower incomplete gamma function and \(P(s, x)\) is the regularized gamma function.

For the non-central chi-squared distribution (\(\lambda > 0\)):

$$ F(x) = \sum_{j=0}^{\infty} \frac{e^{-\lambda/2} (\lambda/2)^j}{j!} P(k/2 + j, x/2) $$

This is approximated numerically.

Moment generating function (m.g.f):

For the central chi-squared distribution (\(\lambda = 0\)):

$$ E(e^{tX}) = (1 - 2t)^{-k/2}, \quad t < 1/2 $$

For the non-central chi-squared distribution (\(\lambda > 0\)):

$$ E(e^{tX}) = \frac{e^{\lambda t / (1 - 2t)}}{(1 - 2t)^{k/2}}, \quad t < 1/2 $$

Skewness:

$$ \gamma_1 = \frac{2^{3/2}(k + 3\lambda)}{(k + 2\lambda)^{3/2}} $$

For the central case (\(\lambda = 0\)), this simplifies to \(\sqrt{8/k}\).

Excess Kurtosis:

$$ \gamma_2 = \frac{12(k + 4\lambda)}{(k + 2\lambda)^2} $$

For the central case (\(\lambda = 0\)), this simplifies to \(12/k\).

See Also

Examples

Run this code
dist <- dist_chisq(df = c(1,2,3,4,6,9))

dist
mean(dist)
variance(dist)
skewness(dist)
kurtosis(dist)

generate(dist, 10)

density(dist, 2)
density(dist, 2, log = TRUE)

cdf(dist, 4)

quantile(dist, 0.7)

Run the code above in your browser using DataLab