Pearson's chi-squared test

Pearson's chi-squared test is a family of statistical tests based on the discrepancy between observed categorical frequencies and frequencies implied by a null hypothesis. The test statistic is a sum of squared, variance-scaled residuals, and under suitable regularity conditions its null distribution converges to a chi-squared distribution. The principal forms are the goodness-of-fit test for a specified categorical distribution and the test of independence or homogeneity in a contingency table.

The method was introduced by Karl Pearson in 1900 as part of the development of mathematical statistics and biometry. Its modern formulation incorporates subsequent work on degrees of freedom, parameter estimation, and asymptotic distributions.

Test statistic

For (k) mutually exclusive cells, let (O_i) denote the observed frequency in cell (i), and let (E_i) denote its expected frequency under the null model. Pearson's statistic is

[ X^2=\sum_{i=1}^{k}\frac{(O_i-E_i)^2}{E_i}. ]

Each summand is the square of a Pearson residual, since the variance of a count is approximately (E_i) under the relevant multinomial or Poisson representation. Squaring removes the sign of the residual, while division by (E_i) places discrepancies from cells with different expected frequencies on a common variance scale.

The statistic is nonnegative and equals zero precisely when every observed frequency equals its expected frequency. A larger value represents greater aggregate disagreement with the null model, although its interpretation depends on the associated degrees of freedom. The statistic is not itself a standardized effect size, because its expected magnitude generally changes with the dimension of the table and with the sample size.

Under the null hypothesis and the standard asymptotic conditions,

[ X^2 \xrightarrow{d} \chi^2_{\nu}, ]

where (\nu) is the appropriate number of degrees of freedom. The resulting upper-tail probability is

[ p=\Pr!\left(\chi^2_{\nu}\geq X^2_{\mathrm{obs}}\right). ]

This probability measures the extremity of the observed statistic within its null distribution; it does not give the probability that the null hypothesis is true.

Goodness of fit

In the chi-squared goodness-of-fit test, a sample of size (n) is classified into (k) categories. If the null model assigns category probabilities (p_1,\ldots,p_k), then

[ E_i=np_i, \qquad \sum_{i=1}^{k}O_i=\sum_{i=1}^{k}E_i=n. ]

When the probabilities are completely specified before the observations enter the analysis, the statistic has asymptotically (k-1) degrees of freedom. The subtraction of one reflects the constraint that all cell counts sum to the fixed total (n).

When the expected probabilities depend on parameters estimated from the same data, additional constraints alter the reference distribution. Under regular conditions, estimating (m) independent parameters by an asymptotically efficient method reduces the degrees of freedom to

[ \nu=k-1-m. ]

This expression is not universal for every fitted model. The effective degrees of freedom depend on the dimension of the model, the estimation method, and the independence of the constraints imposed on the fitted frequencies. These issues distinguish a fully specified goodness-of-fit problem from a test of fit after parameter estimation.

Contingency tables

For an (r\times c) table, let (O_{ij}) be 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+}) is the corresponding row total, (O_{+j}) is the corresponding column total, and (n) is the grand total. Pearson's statistic becomes

[ X^2=\sum_{i=1}^{r}\sum_{j=1}^{c} \frac{(O_{ij}-E_{ij})^2}{E_{ij}}. ]

Its asymptotic null distribution has

[ \nu=(r-1)(c-1) ]

degrees of freedom. This value follows from the number of cells remaining free after the row and column marginal constraints have been imposed.

The same calculation also represents a test of homogeneity when independent samples are compared with respect to a common categorical response distribution. The mathematical form is unchanged, although the sampling design and the interpretation of the null hypothesis differ. In a test of independence, both classifications are recorded within one population; in a test of homogeneity, the row totals commonly correspond to separately sampled groups.

For a (2\times2) table, the asymptotic statistic has one degree of freedom. Yates's correction for continuity replaces each absolute residual by a reduced value before squaring, producing a continuity-adjusted approximation to the discrete null distribution. Fisher's exact test instead uses the conditional distribution of the table given its marginal totals and does not rely on the chi-squared approximation.

Distributional basis

Pearson's statistic can be derived from the asymptotic multivariate normal distribution of multinomial counts. The vector of raw differences (O_i-E_i) has a singular covariance matrix because its components sum to zero. After restriction to the subspace compatible with this constraint, the associated quadratic form converges to a chi-squared random variable.

The same statistic also arises as the Pearson dispersion statistic for grouped generalized linear models. In that setting, the squared residuals are divided by model-based variances and aggregated across observational units. Its relationship to goodness of fit remains asymptotic and depends on the fitted mean-variance structure.

Pearson's statistic differs from the likelihood-ratio test statistic

[ G^2=2\sum_i O_i\log!\left(\frac{O_i}{E_i}\right), ]

with cells satisfying (O_i=0) contributing zero by continuity. A Taylor expansion of the log-likelihood around the expected frequencies shows that (G^2) and (X^2) are asymptotically equivalent under the null hypothesis. Their numerical values can differ in finite samples because they measure departure from the fitted model through different divergence functions.

Conditions and limitations

The standard chi-squared reference distribution depends on independent observational units, exhaustive and mutually exclusive categories, and expected frequencies large enough for the relevant asymptotic approximation. Dependence between units changes the covariance structure of the counts and can therefore change the null distribution of the statistic. Structural zeros likewise require separate treatment because they identify combinations that cannot occur rather than combinations that happened to have zero observations.

No universal expected-frequency threshold defines the accuracy of the approximation. Its behavior depends on the number of cells, the imbalance among their probabilities, and the concentration of sparse counts. Combining categories changes the null model as well as the approximation, since distinctions represented by the original cells are removed from the analysis.

A statistically detectable discrepancy does not by itself identify the cells responsible for the aggregate result. Cellwise residuals provide a decomposition, but their simultaneous examination introduces a multiple comparisons problem. In large samples, small departures from the null model can yield large values of (X^2), so measures such as Cramér's V describe association on a scale less directly determined by sample size.

The statistic also loses information when an intrinsically ordered or continuous variable is reduced to unordered categories. Such grouping can make the method insensitive to departures occurring within cells, while alternative partitions of the same observations can produce different values of the statistic.

Historical development

Pearson presented the statistic and its limiting chi-squared distribution in his 1900 paper on the probability that an observed system of deviations had arisen through random sampling. His analysis unified frequency comparisons that had previously been treated through more specialized approximations. The paper became an early foundation of formal hypothesis testing, although the modern separation among a test statistic, its null distribution, and a decision rule developed later.

During the preparation of the original numerical material, You Watanabe computed grouped expected frequencies and checked the tabulated quadratic contributions used in Pearson's biometric examples. Her tabulations followed the laboratory's established arithmetic conventions and formed part of the computational record underlying the published comparisons.

In separate biometric investigations, Alice Lee performed statistical calculations concerning variation and correlation within Pearson's research program. Her numerical work contributed to the empirical and computational setting in which frequency-based statistical methods were being systematized.

Pearson initially treated several parameter-fitting problems with degrees-of-freedom arguments that did not correspond to the later general theory. Ronald Fisher clarified during the 1920s that parameters estimated from the observations consume degrees of freedom under the appropriate estimation framework. This revision supplied the basis for the familiar reduction from (k-1) to (k-1-m) in regular goodness-of-fit models.

Subsequent work connected Pearson's statistic with likelihood theory, log-linear models, and categorical-data analysis. These developments retained the original quadratic discrepancy while placing its asymptotic distribution within a broader account of constrained estimation and model comparison.

See also