Computing Library › Probability Statistics
Probability Statistics

Chi-Squared Distribution

The chi-squared distribution describes sums of squared standard normals and underpins variance and goodness-of-fit tests.

Definition

If Z1, …, Zk are independent standard normal variables, then X = Z1² + … + Zk² follows a chi-squared distribution with k degrees of freedom, written χ²(k). It is supported on the non-negative reals, is right-skewed, and its mean is k while its variance is 2k.

Why squared normals matter

Sums of squared deviations appear whenever you measure total spread. The sample variance, scaled appropriately, follows a chi-squared distribution, which is what lets you build confidence intervals for a variance and test whether a variance equals a target value.

Goodness-of-fit

The chi-squared statistic Σ (observed − expected)² / expected compares observed counts to those predicted by a model. Under the null hypothesis it is approximately χ² distributed, so a large value signals that the model fits the data poorly. The same statistic tests independence in contingency tables.

python
obs = [22, 18, 20, 40]
exp = [25, 25, 25, 25]
chi2 = sum((o-e)**2/e for o,e in zip(obs,exp))
print(round(chi2,3))  # 11.520

Degrees of freedom

The degrees of freedom count independent squared terms after subtracting constraints. In a goodness-of-fit test with c categories and p estimated parameters, df = c − 1 − p. Getting df right is essential, since it sets the reference distribution and the critical value.

Related distributions

The chi-squared is a special case of the gamma distribution, and ratios of chi-squared variables give the F distribution used in analysis of variance. It also appears in the denominator that defines the Student-t distribution.