TL;DR
Take independent standard Gaussians, square each one, and add the squares. The total follows a chi-squared distribution with degrees of freedom. It is never negative, its average is , and it has a long right tail.
It is the distribution behind many classic tests: whether a sample's spread matches a theory, and whether observed counts match expected counts.
Where you'll see it: in testing whether a sample variance is unusually large or small, in goodness-of-fit tests on survey or experiment counts, and in confidence intervals for a variance.
Intuition
Squares of noise
Each Gaussian error can be positive or negative. Squaring removes the sign, so what is left measures how far off you are, not which way. Add the squares of independent errors and you get the total squared distance from the target. That total is chi-squared with degrees of freedom. The name "degrees of freedom" counts the independent directions the randomness can move in.
Statistics estimates spread by summing squared deviations. Squared deviations of Gaussian noise add up to a known distribution, so we can say how large such a sum is normally and when it is suspicious. That is the problem this distribution solves.
- k = 2
- k = 4
- k = 8
For the density is largest at zero and falls away. For larger the bump moves right and the curve looks more like a bell, which is the central limit theorem at work: a sum of many independent pieces becomes Gaussian-shaped.
The math
Definition
Let be independent, each with distribution . The random variable
has a chi-squared distribution with degrees of freedom, written . For its density is
where is the gamma function, which extends factorials: for a positive whole number .
Here is the number of squared terms, is a possible value of , and is the exponential decay that controls the right tail. The denominator is the constant that makes the area under the curve equal 1. The density is the gamma distribution with shape and scale 2, which is why the two appear together in software.
Mean and variance
For one standard Gaussian , . The fourth moment of a standard Gaussian is , a standard fact you can check by integration by parts. So
Each squared term has mean 1 and variance 2. The terms are independent, and means and variances of independent terms add:
The mean grows with , and the spread grows with the square root of , so the relative wobble shrinks as grows.
Adding chi-squared variables
If and are independent, then . This follows directly from the definition: the sum is a total of squared standard Gaussians.
The sample variance
This is the result that makes the distribution useful in practice. Suppose are independent , with sample mean and sample variance
Then
One degree of freedom is lost because is estimated from the same data. The variance sum is a sum of squares of Gaussian pieces, so it is chi-squared. It cannot be Gaussian itself, because a Gaussian takes negative values and a sum of squares cannot.
Goodness of fit
For counts in categories, with expected counts under a model, Pearson's statistic is
When the expected counts are large, this statistic is approximately if the model is right. The degrees of freedom are because the total count is fixed, so one category is determined by the others.
Worked examples
Let . The density is for .
- We want .
- An antiderivative of is .
- Evaluate: .
- .
Interpretation: when is the sum of squares of two independent standard Gaussians, it exceeds 2 about 37% of the time. For the distribution is simply exponential, which makes it a good first case to compute by hand.
A lab assumes its sensor has noise standard deviation , so . It takes readings and finds a sample variance . Is that surprising?
- Compute the test statistic: .
- If the assumption is true, this statistic follows , which has mean 9.
- The 95th percentile of is about 16.92, and the 99th is about 21.67. The value 24 lies beyond both, so its tail probability is below 0.01.
- Interpretation: either the sensor is noisier than the lab assumed, or the Gaussian noise assumption is wrong. The test is only as good as that assumption.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Data have heavy tails or outliers | The squared-Gaussian premise fails, so the chi-squared quantiles are too optimistic | Robust estimators, or a bootstrap that makes no distributional claim |
| Expected counts are small (roughly below 5 in a cell) | The chi-squared approximation is poor | An exact test, or merge sparse categories |
| You estimated parameters from the same data | Degrees of freedom are overstated and the test is too lenient | Subtract the number of estimated parameters from the degrees of freedom |
| Comparing two variances | A single chi-squared value does not answer the question | A ratio of two scaled chi-squared variables (the F distribution) |
| Positive data that are not sums of squares | The chi-squared shape is too rigid | The gamma distribution, which has a free scale parameter |
Large samples make tiny differences significant. A goodness-of-fit test can reject a model that is useful but not perfect, so report the size of the deviation, not only the p-value.
History
Friedrich Robert Helmert, a German geodesist, worked out the distribution of a sum of squared Gaussian errors in the 1870s while analysing measurement errors. In 1900 Karl Pearson introduced the goodness-of-fit test that uses the statistic above, and he gave the distribution its name from the Greek letter chi. The test caught on because it turned "does this model fit these counts?" into one number with a known reference distribution. In the 1920s Ronald Fisher showed that the degrees of freedom must be reduced by the number of parameters estimated from the data, a correction that is still applied today.
Check yourself
QuestionRecall: What are the mean and variance of a chi-squared variable with k degrees of freedom?Show answer
The mean is and the variance is . Each squared standard Gaussian has mean 1 and variance 2, and the variances of independent terms add, so terms give variance . The means add too, giving .
QuestionComputation: If , what is ?Show answer
. Integrate from 4 to infinity. The antiderivative evaluated at the limits gives .
QuestionWhy: why is a sample variance chi-squared distributed rather than Gaussian?Show answer
The scaled sample variance is a sum of squared deviations, and each deviation is a Gaussian quantity. A sum of squares is never negative, while a Gaussian is symmetric and takes negative values as well as positive ones. The chi-squared distribution is the one built from squares of Gaussians, so it is the right shape. The lost degree of freedom comes from estimating the mean from the same data.
QuestionApplied: A survey of 100 people is split across 4 answers, with 25 expected in each. The observed counts are 30, 20, 28 and 22. Which chi-squared distribution applies, and is the fit suspicious at the 5% level?Show answer
The statistic is . The degrees of freedom are , because the total of 100 is fixed. The 95th percentile of is about 7.81. Since 2.72 is well below that, the observed counts are consistent with the expected split, and there is no evidence against the model at the 5% level.