Chi-square distribution
Chi-square distribution: the distribution of a sum of squared standard normal values. With the default parameters (degrees of freedom k = 4) its mean is 4 and its standard deviation 2.8284. Use the simulator below to draw samples and see it take shape.
Simulate it
Change the parameters, then draw random samples. The bars are the samples; the line is the exact density. With more samples the bars settle onto it.
Samples to draw
What is the chi-square distribution?
If you take k independent standard normal variables, square them and add them up, you get a chi-square variable with k degrees of freedom. It is a positive, right-skewed distribution that sits at the heart of tests about variances and about counts in categories.
In practice you meet it as the reference distribution for the chi-square goodness-of-fit and independence tests, and for confidence intervals and tests for a variance.
Where it is used
- Chi-square test of independence for a contingency table.
- Goodness-of-fit test: do observed counts match expected counts?
- Confidence interval and test for a population variance or standard deviation.
- Likelihood-ratio tests and model comparison.
Shape and parameters
With few degrees of freedom it is strongly skewed, piled up near 0 (and infinite at 0 for k = 1 or 2 in the limit sense); as k grows it becomes more symmetric and looks like a normal curve with mean k and variance 2k.
What it assumes
- For tests on counts, expected counts that are not too small (a common rule is at least 5 per cell).
- For variance tests, data that are close to normal.
How it relates to other distributions
- Gamma distribution: Chi-square(k) is gamma with shape k/2 and scale 2.
- Normal distribution: A chi-square is a sum of squared standard normals.
- Student's t distribution: A t variable is a standard normal divided by the square root of a chi-square over its degrees of freedom.
- F distribution: A ratio of two chi-squares (each over its degrees of freedom) is an F.
Common mistakes
- Using a chi-square test with very small expected counts.
- Running the variance test on clearly non-normal data, where it is unreliable.
- Using the wrong degrees of freedom (for a table it is (rows − 1)(columns − 1)).
How to work it out
- 1
The probability density function (the formula that gives the shape):
- 2
Its mean (the long-run average) and variance (the spread):
- 3
Worked example with the default parameters (degrees of freedom k = 4): With 4 degrees of freedom, what is the probability of a value above 9.49?
LaTeX source of the formulas on this page
\[ f(x)=\frac{x^{k/2-1}e^{-x/2}}{2^{k/2}\Gamma(k/2)},\quad x>0 \]
\[ \mu = k,\qquad \sigma^2 = 2k \]
\[ \text{answer} = 0.0500 \]At a glance
| Property | Value |
|---|---|
| Type | Continuous (measurements) |
| Parameters | degrees of freedom k |
| Possible values | 0 to ∞ |
| Mean | 4 |
| Variance | 8 |
| Standard deviation | 2.8284 |
| Example (degrees of freedom k = 4) | With 4 degrees of freedom, what is the probability of a value above 9.49? Answer: 0.0500. |
How to compute it in Excel, Python and R
| Tool | Function |
|---|---|
| Excel / Google Sheets | =CHISQ.DIST(x, k, TRUE) (CHISQ.DIST.RT for the p-value) |
| Python (SciPy) | scipy.stats.chi2.cdf(x, k) (sf for the p-value) |
| R | pchisq(x, k) (lower.tail = FALSE for the p-value) |
Questions
What is the chi-square distribution used for?
The distribution of a sum of squared standard normal values. Typical uses: Chi-square test of independence for a contingency table. Goodness-of-fit test: do observed counts match expected counts? Confidence interval and test for a population variance or standard deviation.
What are the mean and variance of the chi-square distribution?
Mean: μ = k. Variance: σ² = 2k.
What does the chi-square distribution assume?
For tests on counts, expected counts that are not too small (a common rule is at least 5 per cell). For variance tests, data that are close to normal.
How do I calculate it in Excel?
=CHISQ.DIST(x, k, TRUE) (CHISQ.DIST.RT for the p-value)
How is the chi-square distribution related to other distributions?
Gamma distribution: Chi-square(k) is gamma with shape k/2 and scale 2. Normal distribution: A chi-square is a sum of squared standard normals. Student's t distribution: A t variable is a standard normal divided by the square root of a chi-square over its degrees of freedom. F distribution: A ratio of two chi-squares (each over its degrees of freedom) is an F.