[Stable]

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

dist_chisq(df, ncp = 0)

Arguments

df

degrees of freedom (non-negative, but can be non-integer).

ncp

non-centrality parameter (non-negative).

Details

We recommend reading this documentation on https://pkg.mitchelloharawild.com/distributional/, where the math will render nicely.

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

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

Mean: \(k\)

Variance: \(2k\)

Probability density function (p.d.f):

$$ f(x) = \frac{1}{\sqrt{2 \pi \sigma^2}} e^{-(x - \mu)^2 / 2 \sigma^2} $$

Cumulative distribution function (c.d.f):

The cumulative distribution function has the form

$$ F(t) = \int_{-\infty}^t \frac{1}{\sqrt{2 \pi \sigma^2}} e^{-(x - \mu)^2 / 2 \sigma^2} dx $$

but this integral does not have a closed form solution and must be approximated numerically. The c.d.f. of a standard normal is sometimes called the "error function". The notation \(\Phi(t)\) also stands for the c.d.f. of a standard normal evaluated at \(t\). Z-tables list the value of \(\Phi(t)\) for various \(t\).

Moment generating function (m.g.f):

$$ E(e^{tX}) = e^{\mu t + \sigma^2 t^2 / 2} $$

See also

Examples

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

dist
#> <distribution[6]>
#> [1] ᵪ²(1) ᵪ²(2) ᵪ²(3) ᵪ²(4) ᵪ²(6) ᵪ²(9)
mean(dist)
#> [1] 1 2 3 4 6 9
variance(dist)
#> [1]  2  4  6  8 12 18
skewness(dist)
#> [1] 2.828427 2.000000 1.632993 1.414214 1.154701 0.942809
kurtosis(dist)
#> [1] 12.000000  6.000000  4.000000  3.000000  2.000000  1.333333

generate(dist, 10)
#> [[1]]
#>  [1] 4.047013e-01 6.205749e-02 4.435842e-02 3.789045e+00 3.414532e-03
#>  [6] 2.775745e-01 3.014216e-08 4.084889e+00 1.347450e-01 4.137046e-03
#> 
#> [[2]]
#>  [1] 2.1765663 0.1728463 0.6521504 0.5678153 6.5400095 1.1090362 1.9458278
#>  [8] 1.6737546 2.2380580 1.0848257
#> 
#> [[3]]
#>  [1] 0.2522179 2.2563275 0.5015687 2.4699871 0.9182044 3.6686716 0.1109399
#>  [8] 1.0783473 3.7730830 9.9781000
#> 
#> [[4]]
#>  [1]  3.6676943  6.6866742  2.3762074  1.3110265 12.0680911  4.5565400
#>  [7]  0.8961778  1.3136361  2.6503396  1.7013860
#> 
#> [[5]]
#>  [1]  0.7556929  1.4946454  3.1869203 19.5416985  4.9748662  4.6342390
#>  [7]  3.9310179 12.7009085 14.1567026  7.4961617
#> 
#> [[6]]
#>  [1] 11.362065  6.814651  7.571392 10.412219  9.341929  9.533922 13.157604
#>  [8]  4.677217 12.698442  9.926195
#> 

density(dist, 2)
#> [1] 0.10377687 0.18393972 0.20755375 0.18393972 0.09196986 0.01581362
density(dist, 2, log = TRUE)
#> [1] -2.265512 -1.693147 -1.572365 -1.693147 -2.386294 -4.146884

cdf(dist, 4)
#> [1] 0.95449974 0.86466472 0.73853587 0.59399415 0.32332358 0.08858747

quantile(dist, 0.7)
#> [1]  1.074194  2.407946  3.664871  4.878433  7.231135 10.656372