Chi-Squared Distribution and Goodness of Fit
The chi-squared distribution is where probability theory hands experimental physics its ruler. Mathematically it is the distribution of a sum of squares of independent standard Gaussians; physically it is the number that decides whether a model curve genuinely threads a cloud of noisy data or merely looks as if it does. The bridge is the central limit theorem: because measurement errors are so often approximately Gaussian, the squared, error-normalised residuals of a fit pile up into a chi-squared variable, and the tail of that distribution becomes the universal currency of goodness of fit — the -value quoted in every particle-physics discovery, every cosmological parameter contour, every calibration report. We build the object constructively. Start from one standard normal ; the change-of-variables formula gives the density of , which is , equivalently a Gamma with shape and scale . Independence then adds degrees of freedom, handled most cleanly through the moment-generating function , whose product structure makes the additivity fall out in one line. The same variable reappears from the multivariate Gaussian, where the squared Mahalanobis distance is exactly — which is why error ellipsoids are level sets of a chi-squared. In practice we estimate parameters rather than knowing the true mean, each estimate costs one degree of freedom, and the Pearson statistic is compared against with . Reduced chi-squared, -values, and confidence regions all follow from a single tail integral of one density.
- The chi-squared with degrees of freedom is the law of for independent standard Gaussians; its density is on .
- It is exactly a Gamma with shape and scale , so it has mean , variance , and mode .
- The same variable is the squared Mahalanobis distance of a -dimensional Gaussian, which is why constant-probability error ellipsoids are its level sets.
- In goodness-of-fit testing the Pearson statistic is asymptotically with , one degree of freedom lost per fitted constraint.
- A good fit has reduced chi-squared ; the -value is the upper tail , small meaning tension with the data.
- For large the distribution becomes Gaussian, .
- Key idea: A sum of independent squared standard Gaussians is ; normalised squared residuals of a Gaussian-error fit therefore follow , and the upper-tail probability quantifies model–data agreement.
Where this lives today
The chi-squared tail is the arbiter of modern quantitative science. When ATLAS and CMS announced the Higgs boson in 2012, the "" they quoted was a -value converted to sigmas — a statement that the background-only model fit the observed excess with probability below , computed (in its profile-likelihood generalisation) from precisely this tail machinery. Cosmologists fitting CDM to the Planck power spectrum report a global chi-squared against thousands of multipole bins, and draw the joint confidence ellipses in the plane using exactly the contours of Example 3. Every particle-physics fit quoting a "" applies equation (6), and the same distribution governs variance confidence intervals in metrology, nuclear-decay histograms, and gravitational-wave error ellipsoids. Wherever a physicist writes "the fit is good," a chi-squared tail integral is doing the certifying.
The physical picture
Picture a standard Gaussian dart-thrower aiming at the origin of a -dimensional space. Each coordinate of a throw is an independent , and the quantity we watch is the squared distance from the bullseye, . In one dimension the darts crowd near zero, so piles up at the origin and diverges there; add dimensions and the typical squared radius grows to about , since every axis contributes one unit of variance on average. That single fact — mean , variance — sets the whole shape: the peak drifts rightward to , the distribution broadens, and for large it rounds into a Gaussian. The first figure is that family of shapes.
Goodness of fit turns that geometry into a decision. If the model were correct and the error bars honest, each residual divided by its error is roughly a standard Gaussian, so squaring and summing converts "distance from the model" into a chi-squared whose expected value is the number of free residuals . A statistic near signals agreement; far above signals a model that misses the data or underestimated errors; far below hints at overestimated errors (or data too good to be true). The verdict is quantitative: shade the density beyond the observed value and that area is the -value. The second figure carries a real case — a fair-die test with , an observed statistic of , and the rejection region past the critical value .
The core equations
Everything begins with the density — the law of a sum of independent squared standard normals. Its ingredients, the power , the exponential , and the constant built from , are exactly those of a Gamma distribution with shape and scale .
where: — degrees of freedom (a positive integer in physics); — value of the chi-squared variable, ; — the gamma function, with for integer and . Reading it: the power sets the origin behaviour (diverging for , flat for , vanishing for ), while keeps every moment finite. The moment-generating function is the algebraic engine of the subject. Because independent variables multiply their MGFs, the single factor for one squared normal raised to the -th power gives the MGF of , whose product form makes degrees of freedom add.
where: — the MGF of ; — the transform argument, restricted to so the defining integral converges. Reading it: the exponent is additive in , so — additivity of degrees of freedom is visible by eye. Differentiating at the origin extracts the cumulants; the first two anchor every rule of thumb for reading a fit.
where: — the expected value, equal to the degrees of freedom; — the variance, twice that; the skewness decays to zero as . Reading it: a "typical" chi-squared value is , which is why a reduced chi-squared has spread about . The cumulative distribution function is a regularised incomplete gamma function — no elementary closed form for general , but every statistics library evaluates it, and the goodness-of-fit -value is simply its upper tail.
where: — the lower incomplete gamma function; — its regularised form; — the degrees of freedom after fitting parameters; — the probability, under the null, of a statistic at least as large as observed. Reading it: small means the model sits in the improbable tail and is disfavoured. The two working statistics — the Pearson form for binned counts and the weighted least-squares form for continuous measurements — are both sums of squared, error-normalised residuals that converge to under the null.
where: — observed and model-expected counts in bin ; — the measured value and its standard error at ; — the model prediction with parameters ; — the number of bins or data points. Reading it: the Pearson denominator is the Poisson variance of the bin, so each term is a standardised fluctuation squared. The reduced chi-squared collapses the test to one number, and the Mahalanobis identity ties the distribution back to the multivariate Gaussian, showing why confidence ellipsoids are chi-squared level sets.
where: — the reduced chi-squared (chi-squared per degree of freedom); — a -dimensional Gaussian with mean and covariance . Reading it: a reduced chi-squared far from diagnoses trouble, while the quadratic form is the squared distance a whitening transform turns into .
The goal is to compute the MGF of a single squared standard normal from a Gaussian integral, show that independence multiplies MGFs so of them give , and read off both the additivity rule and the mean and variance from the cumulant expansion. This one transform does the work of a dozen convolution integrals and is the reason the chi-squared family is closed under addition.
Step 1. Take and form . Combine the exponents into , a Gaussian in with variance . Why: the whole calculation reduces to a Gaussian integral, and the coefficient carries the entire distribution.
Step 2. Evaluate the Gaussian: , so , valid whenever , i.e. . Why: the condition is the boundary beyond which the tail can no longer beat the growth of .
Step 3. For with independent , the expectation of a product factorises, so . Two independent chi-squared variables then satisfy , the MGF of ; by uniqueness the sum is . Why: because the MGF determines the distribution uniquely, matching MGFs is a complete proof — no convolution integral is needed to add degrees of freedom.
Step 4. Expand ; its derivatives at give (mean), (variance), and the standardised third cumulant (skewness). Why: the vanishing skewness as is the fingerprint of the central-limit approach to a Gaussian.
Go deeper · Derivation B · 1 minThe density from a single squared Gaussian and the Gamma match
The goal is to derive the density explicitly by the change-of-variables formula for the non-injective map , then recognise the general MGF as that of a Gamma distribution and read the full density off the Gamma family. Together these give two independent confirmations of equation (1): a direct construction for and a transform-based one for all .
Step 1. For with , work through the CDF because the map is two-to-one: , using . Why: squaring folds the roots onto one value, so a one-branch Jacobian would miss a factor of two — the CDF handles the folding automatically.
Step 2. Differentiate with the chain rule: . This matches equation (1) at because . Why: the appearance of is exactly what turns the general normalising constant into the familiar , closing the loop with the standard normal.
Step 3. For general , compare with the Gamma MGF of shape and scale ; matching gives , , so is exactly Gamma. Why: the chi-squared is not a distinct species but a slice of the Gamma family, so its density, moments, and CDF are all Gamma results at half-integer shape and scale two.
Step 4. Insert , into the Gamma density to recover . Check : this is , an exponential of mean ; check : it reproduces Step 2. Why: the two cases the density must satisfy — exponential at , folded Gaussian at — both fall out, confirming the match for every .
Go deeper · Derivation C · 1 minMahalanobis distance and the whitening transform
The goal is to prove that the squared Mahalanobis distance of a -dimensional Gaussian is exactly , by constructing a linear "whitening" transform that turns a correlated Gaussian vector into independent standard normals and rewrites the quadratic form as a sum of squares. This underlies every error ellipse and joint confidence region in experimental physics — the geometry of correlated uncertainties is chi-squared geometry in disguise.
Step 1. Because is symmetric positive-definite, it has a symmetric positive-definite square root with , and hence an inverse . Why: the square root exists precisely when the covariance is non-degenerate, encoding the assumption that no linear combination of the data has zero variance.
Step 2. Define the whitened vector . A linear transform of a Gaussian is Gaussian, and its covariance is , so : independent standard normals. Why: whitening is the multivariate analogue of dividing a residual by its error bar — it strips out correlations, leaving unit-variance independent coordinates.
Step 3. Rewrite the quadratic form: , a sum of independent squared standard normals, which is . Why: this identifies the error ellipsoids (surfaces of constant ) as level sets of a chi-squared, so their enclosed probabilities come straight from the CDF.
Step 4. Check one dimension: gives , the squared standardised residual, distributed as . Why: the familiar "residual over sigma, squared" is just the Mahalanobis distance, connecting it to the weighted least-squares statistic of equation (5).
Limiting cases
The character of shifts qualitatively with the degrees of freedom, and each regime has a clean closed form worth memorising.
| Case | Result | Meaning |
|---|---|---|
| One degree of freedom | The density of for one standard normal; diverges as but remains integrable. | |
| Two degrees of freedom | Exactly an exponential of mean — the simplest closed form, finite at the origin and monotone decreasing. | |
| Mode location | For the peak sits at ; for the density is monotone with no interior maximum. | |
| Large (central limit) | The standardised chi-squared becomes standard normal; Fisher's converges even faster. | |
| Sample variance | For i.i.d. normal samples the scaled sample variance is chi-squared — the basis of variance intervals and Student's . |
Worked examples
1 · Testing a die for fairness (fully worked)
A six-sided die is rolled times with observed counts . Under the fair-die hypothesis each face is expected times. Is the die consistent with fair?
Step 1. Form with . The squared deviations are , summing to ; dividing by gives .
Step 2. Count degrees of freedom. There are bins, but one constraint is imposed because the counts must sum to the fixed total , so . No further parameters were fitted — the fair-die model has none to estimate.
Step 3. Compare with , whose mean is and standard deviation . The observed sits just below the mean, well inside the bulk (second figure). The upper-tail probability is .
Step 4. Interpret. A -value of means that if the die were fair, a discrepancy this large or larger would occur about of the time — unremarkable. There is no evidence against fairness; the reduced chi-squared says the same. Rejecting at the level would have needed , more than double what we saw.
2 · Reading a weighted straight-line fit (fully worked)
Five voltage measurements , each with error , are taken at currents . Fit Ohm's law (a line through the origin) and assess the fit.
Step 1. For a one-parameter model through the origin with equal errors, the weighted least-squares estimate is , with error .
Step 2. The residuals are volts; standardising by gives standard errors.
Step 3. Square and sum: . With points and fitted parameter, , so the reduced chi-squared is .
Step 4. Interpret carefully. Naively looks alarming, but the spread of reduced chi-squared at is , so lies only about high. The exact tail is — mildly high but not significant. The fit is acceptable; the residual at is the largest and the first to re-measure, but four degrees of freedom cannot distinguish a poor model from an unlucky draw.
3 · Two-parameter confidence ellipse (worked relation)
A least-squares fit returns a best pair of parameters with a covariance. What contour encloses the joint , , and confidence regions?
Step 1. The offset is the squared Mahalanobis distance of from the best fit, which is , so the enclosed probability is the closed-form CDF .
Step 2. Invert for each level, : the one-, two-, and three-sigma joint levels give , the standard contour heights for parameter ellipses in cosmology and accelerator physics. For a single parameter of interest the levels are instead (a projection) — confusing the two doubles the error bars.
Physics of the portrait
The chi-squared goodness-of-fit test is the invention that let physics say, quantitatively, whether a theory fits — and it belongs above all to Karl Pearson.
Origins · 1 minKarl Pearson and how this was discovered
Karl Pearson was the founder of mathematical statistics as a discipline, and the chi-squared test is his most enduring gift to the experimental sciences. Trained at Cambridge and steeped in German philosophy — he spent enough time in Germany to respell his given name "Carl" as "Karl" — he held the University College London chair in applied mathematics and, spurred by the biologist Walter Weldon and the polymath Francis Galton, turned to measuring whether data agree with a hypothesised law. In an 1900 paper he introduced and proved that, under the null, it follows the distribution Helmert and others had already met in the theory of Gaussian errors. This was the first general, distribution-free way to attach a probability to "the model fits the data," and it remains the workhorse of hypothesis testing a century later. Pearson also gave us the method of moments, the modern correlation coefficient, and the term "standard deviation." His one famous error concerned this very test: he used regardless of how many parameters were fitted, a mistake Fisher corrected in 1922 — the source of a long and bitter feud between the two men.
Going further
Texts. Stone & Goldbart, Mathematics for Physics, probability and statistics chapter · Arfken & Weber, Mathematical Methods for Physicists, probability chapter · Riley, Hobson & Bence, Mathematical Methods for Physics and Engineering, Ch. 30 · Cowan, Statistical Data Analysis (Oxford) · Press et al., Numerical Recipes, "Modeling of Data" chapter. The key checkpoints in this article are: the Gaussian integral yields the single-normal MGF ; the change of variables for uses ; the cumulants and follow from differentiating ; and the whitening identity gives . The worked numbers are: the die test gives , , ; the resistor fit gives , , , ; the contour levels for follow from .
Prerequisites. Gaussian (Normal) Distribution · Multivariate Gaussian Distribution · Cumulative Distribution Functions and Change of Variables · Moment-Generating and Characteristic Functions · Expectation, Variance and Moments. Leads to. Central Limit Theorem · Conditional Probability and Bayes' Theorem · Poisson Distribution
Ask the tutor: Want to walk through your own dataset — its chi-squared, degrees of freedom, and p-value — or see why the Mahalanobis distance turns error ellipses into chi-squared contours?
Why exactly does each fitted parameter remove one degree of freedom?
Because each parameter estimated from the data forces a linear constraint on the residuals. A least-squares straight line is defined by setting the derivatives of with respect to slope and intercept to zero, which makes the weighted sum of residuals and their -moment vanish. Those two equations leave only residuals free to fluctuate, so the chi-squared's effective dimension drops to for fitted parameters. Using overstates the expected chi-squared and wrongly penalises good fits — the mistake Fisher corrected in 1922.
What counts as a good value of reduced chi-squared?
As a rule of thumb signals a healthy fit, since the mean of is . But "close to 1" must be judged against its spread : with a value outside roughly is notable, whereas with even is unremarkable. Values well above point to a model that misses the data or to underestimated errors; values well below suggest overestimated errors, over-fitting, or correlated data treated as independent. It is a first diagnostic, not a verdict — always convert to a -value before rejecting a model.
How is the p-value actually computed if the CDF has no closed form?
The chi-squared CDF is the regularised lower incomplete gamma function , so the -value is its complement . For general there is no elementary formula, but the incomplete gamma function is computed to machine precision by a continued fraction or series, and every library — `scipy.stats.chi2.sf`, ROOT's `TMath::Prob`, a spreadsheet's `CHISQ.DIST.RT` — returns it instantly. Closed forms exist for special cases: gives . For large the Gaussian approximation , or the sharper Wilson-Hilferty formula, suffices.
When does the Pearson statistic fail, and what replaces it?
The Pearson statistic relies on each Poisson bin being approximately Gaussian, which holds only when the expected count is not too small — the usual guideline is . With sparse bins the discreteness matters, the chi-squared approximation breaks down, and the -value can be badly misstated. The standard fixes are to merge adjacent sparse bins until each expected count clears the threshold, or to switch to an exact multinomial test, a likelihood-ratio (-test) statistic , or a Monte-Carlo null distribution. In particle physics with very low counts, unbinned likelihood methods are preferred outright.
Why is the squared Mahalanobis distance chi-squared, and why does it matter?
If is Gaussian with mean and covariance , the quadratic form is exactly . The proof is a change of variables: whitening, , produces independent standard normals, so the form becomes . This matters because the constant-probability surfaces of a multivariate Gaussian — the error ellipsoids around a best fit — are then level sets of a chi-squared, so the probability enclosed by an ellipse of "radius" is read directly from the chi-squared CDF. That is how joint confidence regions are built.
Is the chi-squared distribution related to the Gaussian, and how do they blur together?
Intimately. The chi-squared is built from Gaussians by squaring and summing, so for one degree of freedom it is literally the law of . For large the central limit theorem takes over: is a sum of i.i.d. squared normals, so tends to a standard Gaussian and the once-skewed density rounds into a symmetric bell (Fisher's converges faster still). A chi-squared with a few degrees of freedom is markedly skewed, but with a hundred it is nearly Gaussian — which is why for large you assess a fit by counting how many the statistic sits from .