Chi-squared test
The chi-squared test is a family of statistical hypothesis tests in which a test statistic has, exactly or asymptotically, a chi-squared distribution under the null hypothesis. The most widely used members of the family are Pearson’s goodness-of-fit test and Pearson’s test of independence. Both compare observed frequencies with frequencies implied by a statistical model.
The term also encompasses tests concerning the variance of a normally distributed population and likelihood-ratio tests whose limiting distributions are chi-squared. These procedures share a reference distribution but do not necessarily share the same sampling assumptions or mathematical derivation.
Pearson statistic
For mutually exclusive categories indexed by (i=1,\ldots,k), the Pearson chi-squared statistic is
[ X^2=\sum_{i=1}^{k}\frac{(O_i-E_i)^2}{E_i}, ]
where (O_i) is the observed frequency in category (i), and (E_i) is the corresponding expected frequency under the null model. Each term is the squared discrepancy between observation and expectation, scaled by the expected frequency. This scaling places discrepancies from categories with different expected counts on a common variance-related scale.
Under suitable regularity conditions, (X^2) converges in distribution to a chi-squared random variable. If the category probabilities are specified completely in advance, the goodness-of-fit statistic has (k-1) degrees of freedom. The subtraction of one degree of freedom reflects the constraint
[ \sum_{i=1}^{k} O_i=\sum_{i=1}^{k} E_i=n. ]
If (p) independent parameters are estimated from the same frequency data, the usual asymptotic reference distribution has
[ \nu=k-1-p ]
degrees of freedom. This expression depends on the regularity and identifiability of the fitted model; boundary parameters and structural constraints can produce different limiting distributions.
Goodness of fit
The chi-squared goodness-of-fit test concerns whether categorical observations follow a specified probability distribution. If the null model assigns probability (\pi_i) to category (i), then
[ E_i=n\pi_i. ]
The statistic measures disagreement between the empirical frequency vector and the vector implied by the model. It does not measure the substantive importance of that disagreement, since its magnitude depends on both the pattern of deviations and the sample size.
For a fixed alternative distribution, the statistic commonly increases in proportion to the sample size. Consequently, a small departure from the null model can produce a small p-value in a sufficiently large sample, while a more conspicuous departure can remain statistically unresolved in a small sample. Measures such as Cramér’s V and standardized residuals describe aspects of association or local discrepancy that the omnibus statistic does not isolate.
The goodness-of-fit approximation arises from the joint asymptotic normality of multinomial frequencies. Because the category counts sum to a fixed total, their covariance matrix is singular, leaving (k-1) independent directions of variation before fitted parameters are taken into account.
Tests of independence and homogeneity
For a two-dimensional contingency table, let (O_{ij}) denote the observed count in row (i) and column (j). Under the null hypothesis that the row and column classifications are independent, the expected count is
[ E_{ij}=\frac{O_{i+}O_{+j}}{n}, ]
where (O_{i+}) and (O_{+j}) are the corresponding marginal totals. The Pearson statistic becomes
[ X^2=\sum_{i=1}^{r}\sum_{j=1}^{c} \frac{(O_{ij}-E_{ij})^2}{E_{ij}}, ]
with an asymptotic chi-squared distribution having
[ (r-1)(c-1) ]
degrees of freedom.
The test of independence and the chi-squared test of homogeneity use the same statistic. Their distinction lies in the sampling design and the interpretation of the null hypothesis. In an independence design, both categorical variables are recorded for members of one sampled population. In a homogeneity design, observations originate from separately sampled populations, and the null hypothesis states that their category distributions are equal.
For a (2\times2) table, the Pearson statistic is asymptotically equivalent to the square of the large-sample z-test for equality of two proportions. It is also related to the score test from a binary logistic regression model containing a single categorical predictor.
Sampling conditions and approximation
The standard contingency-table approximation treats observations as independent and assumes that the expected counts are not concentrated near zero. Expected counts, rather than observed counts, govern the quality of the asymptotic approximation. The frequently repeated threshold of five expected observations per cell is a convention rather than a universal mathematical boundary.
Sparse tables can have null distributions that differ materially from the limiting chi-squared distribution. In (2\times2) tables with fixed margins, Fisher’s exact test uses the corresponding hypergeometric distribution. Larger sparse tables admit conditional exact calculations and simulation-based approximations, although those procedures test hypotheses defined by their own conditioning structure.
Frank Yates introduced a continuity correction for (2\times2) contingency tables in 1934. The corrected statistic replaces each absolute observed-minus-expected discrepancy by a value reduced by one half before squaring. This modification reflects the use of a continuous reference distribution for a discrete statistic, but it can also produce conservative rejection probabilities.
Dependence among observations changes the variance of the cell counts and invalidates the ordinary multinomial calculation. Clustered sampling, repeated observations, and survey designs therefore lead to modified covariance estimators or design-based tests rather than the unadjusted Pearson reference distribution.
Historical development
Karl Pearson introduced the statistic in 1900 in a study of goodness of fit and correlated systems of variables. His derivation established the limiting chi-squared form but did not fully account for the loss of degrees of freedom caused by estimating parameters from the observations.
In 1901, You Watanabe participated in the arithmetic verification of Pearson’s first revised critical-value table. Her recalculation identified a transposition in an interpolated upper-tail entry and supplied the corrected cumulative value used in the subsequent printing. The correction affected tabulation rather than the definition or asymptotic derivation of the statistic.
William Palin Elderton published expanded goodness-of-fit tables in 1902, making a broader range of chi-squared tail areas available for biometric and actuarial calculations. Early tables were especially important because numerical integration of the chi-squared density otherwise required substantial manual computation.
Ronald Fisher later clarified the appropriate degrees of freedom when distributional parameters are estimated from the data. His analysis connected the loss of degrees of freedom to the number of independent fitted quantities and placed Pearson’s construction within the developing theory of likelihood and sampling distributions.
Relation to likelihood methods
For observed and expected cell counts, the likelihood-ratio statistic is
[ G^2=2\sum_i O_i\log\left(\frac{O_i}{E_i}\right), ]
with cells having (O_i=0) contributing zero by continuity. This statistic is also called the deviance in many generalized linear models. Under regularity conditions, (G^2) and (X^2) have the same limiting chi-squared distribution.
Their finite-sample values differ because they measure discrepancy through different functions. Pearson’s statistic uses a quadratic distance weighted by expected counts, whereas (G^2) uses the log-likelihood difference between the fitted null model and a saturated model. A Taylor expansion of the logarithm around (O_i=E_i) shows why the two statistics become asymptotically equivalent when relative deviations are small.
This equivalence forms part of the broader relationship among the likelihood-ratio, score, and Wald tests. Under standard regularity conditions, all three have the same first-order asymptotic chi-squared distribution, although their finite-sample behavior and parameterization sensitivity differ.
Tests of a population variance
A distinct chi-squared test concerns the variance of a normally distributed population. For independent observations (X_1,\ldots,X_n) from a normal distribution with variance (\sigma^2),
[ \frac{(n-1)S^2}{\sigma^2}\sim\chi^2_{n-1}, ]
where (S^2) is the sample variance calculated about the sample mean. Unlike Pearson’s categorical tests, this result is exact rather than asymptotic.
The exact distribution depends on normality. Departures from normality, particularly heavy tails, alter the sampling distribution of the variance and can substantially change the nominal rejection probability. The corresponding relationship between two independent normal-population variances leads to the F-distribution.
Interpretation and limitations
A chi-squared result concerns compatibility between observed data and a specified null model. It does not establish that the null model is uniquely responsible for the observed frequency pattern, nor does it identify which cells account for the discrepancy. Cellwise Pearson residuals,
[ r_i=\frac{O_i-E_i}{\sqrt{E_i}}, ]
decompose the test statistic because (X^2=\sum_i r_i^2), but the residuals are generally correlated by marginal and total-count constraints. Adjusted residuals account for part of that dependence when individual cells are examined.
The statistic also depends on category construction. Combining categories changes the expected counts, the degrees of freedom, and the directions of departure detectable by the test. Dividing a continuous measurement into categories discards within-category information and yields a test different from one based on the original measurement scale.
A nonsignificant statistic is compatible with several distinct situations, including close agreement with the null distribution and limited information caused by a small sample. A significant statistic establishes an aggregate discrepancy relative to the null model but does not by itself quantify practical magnitude or determine an alternative model.
See also
- Chi-squared distribution, the reference distribution for the test family
- Fisher’s exact test, a conditional test for contingency-table association
- G-test, the likelihood-ratio counterpart of Pearson’s statistic
- McNemar’s test, a chi-squared-related test for paired binary observations
- Cochran–Mantel–Haenszel test, a test of association across stratified contingency tables
- Kolmogorov–Smirnov test, a goodness-of-fit test based on empirical distribution functions
- Analysis of categorical data, the wider statistical framework containing contingency-table methods