Factsheet: Chi-squared distribution
Where to use: The \(\chi^2\) distribution is used for hypothesis testing, such as for goodness of fit tests and tests for independence. (See Guide: Introduction to hypothesis testing for more.) It is a special case of the gamma distribution, as \(\chi^2(k)=\textrm{Gam}(\frac{k}{2},2)\).
Notation: \(X \sim \chi^2(k)\)
Parameter: The integer \(k\) is the number of degrees of freedom in the sample.
| Quantity | Value | Notes |
|---|---|---|
| Mean | \(\mathbb{E}(X) = k\) | |
| Variance | \(\mathbb{V}(X) = 2k\) | |
| \(\mathbb{P}(X=x)=\dfrac{x^{\frac{k}{2}-1}\exp\left({-\frac{x}{2}}\right)}{2^\frac{k}{2}\Gamma\left(\frac{k}{2}\right)}\) | \(\Gamma(x)\) is the gamma function | |
| CDF | \(\mathbb{P}(X \leq x)=\dfrac{1}{\Gamma\left(\frac{k}{2}\right)}\textrm{Gam}\left(\frac{k}{2},\frac{x}{2}\right)\) | \(\Gamma(x)\) is the gamma function, \(\textrm{Gam}(\alpha,\theta)\) is the PDF of the gamma distribution |
Examples:
Goodness of fit example: You have a six-sided die with six possible outcomes: \(1, 2, 3, 4, 5,\) and \(6\). You calculate the expected frequencies of each outcome. Then you roll the die many times and record the observed frequencies of each outcome. Since there are 6 categories, \[\textsf{degrees of freedom = number of categories} - 1 = 6 - 1 = 5\] This can be expressed as \(X \sim \chi^2(5)\), meaning the degrees of freedom is \(5\).
Test for independence example: You are investigating whether there is a correlation between two variables: candy colour and flavour. You have \(5\) categories of colours and 3 categories of flavours. Calculating the degrees of freedom can be done with the formula: \[(\textsf{categories of colours} - 1)(\textsf{categories of flavours} - 1) = (5-1)(3-1)=(4)(2)=8.\] You can model \(X \sim \chi^2(8)\), meaning that there are \(8\) degrees of freedom.
Further reading
Version history
v1.0: initial version created 04/25 by tdhc and Michelle Arnetta as part of a University of St Andrews VIP project.
v1.1: moved to factsheet form and populated with material from Overview: Probability distributions by tdhc.
v1.2: deprecated shinylive apps replaced 09/26 by tdhc.