Probability And Stochastic Processes Codexery

Chi-squared test

Statistical test for independence in contingency tables.

Chi-squared test

The chi-squared test is a statistical method for analyzing contingency tables, typically used when sample sizes are large. Its main purpose is to assess whether two categorical variables—represented by the table’s dimensions—are independent of each other. The test relies on the test statistic following a chi-squared distribution under the null hypothesis, with Pearson’s chi-squared test being the most common version. This specific test compares observed frequencies in the table’s categories to expected frequencies, checking for statistically significant differences. For smaller sample sizes, Fisher’s exact test is preferred.

In standard applications, observations are sorted into mutually exclusive categories. If the null hypothesis—that no differences exist between categories in the population—is true, the test statistic follows a chi-squared frequency distribution. The test evaluates how likely the observed frequencies are, assuming the null hypothesis holds. Test statistics that follow a chi-squared distribution require independent observations. There are also chi-squared tests for testing the independence of two random variables based on paired observations.

The term “chi-squared tests” often refers to tests where the test statistic’s distribution approaches a chi-squared distribution asymptotically. This means that as sample sizes increase, the sampling distribution (under the null hypothesis) gets closer to a chi-squared distribution.

Historically, in the 19th century, statistical methods were mainly applied to biological data, with researchers like Sir George Airy and Mansfield Merriman assuming observations followed a normal distribution. Karl Pearson criticized this in his 1900 paper. Earlier, at the end of the 19th century, Pearson noticed significant skewness in biological data. To model both normal and skewed observations, he developed the Pearson distribution—a family of continuous probability distributions that includes the normal distribution and many skewed ones—in a series of articles from 1893 to 1916. He proposed using this distribution to model observations and then performing a goodness-of-fit test to check how well the model fit the data.

Pearson’s chi-squared test was introduced in his 1900 paper, considered a foundation of modern statistics. In it, he examined a goodness-of-fit test. Suppose a random sample of \(n\) observations is classified into \(k\) mutually exclusive classes, with observed counts \(o_i\) (for \(i=1,\dots,k\)). The null hypothesis gives the probability \(p_i\) that an observation falls into the \(i\)th class, so expected counts are \(e_i = n p_i\). Pearson proposed that, under the null hypothesis, as \(n\) grows, the limiting distribution of a certain quantity is the chi-squared distribution. He first considered cases where expected counts were large and known, assuming each observation could be treated as normally distributed, and found that in the limit, the statistic follows a chi-squared distribution with \(k-1\) degrees of freedom.

Pearson then considered cases where expected counts depended on parameters estimated from the sample. He suggested that the difference between true expected counts (\(m_i\)) and estimated ones (\(m'_i\)) would usually be positive and small enough to ignore. He argued that treating the statistic as chi-squared distributed with \(k-1\) degrees of freedom would not affect practical decisions. This conclusion sparked controversy and was unresolved for 20 years, until Fisher’s papers in 1922 and 1924.

Other chi-squared tests exist. One exact test is for the variance of a normally distributed population, based on a sample variance, though it is rarely used because the true variance is usually unknown. Several tests approximate the chi-squared distribution: Fisher’s exact test (used for 2×2 tables when row and column totals are fixed by design, but it can be overly conservative when margins are random), the binomial test (for 2×1 goodness-of-fit), the Cochran–Mantel–Haenszel chi-squared test, McNemar’s test (for paired tables), Tukey’s test of additivity, the portmanteau test in time-series analysis (for autocorrelation), and likelihood-ratio tests in statistical modeling (for comparing nested models). Yates’s correction for continuity is also applied when using the chi-squared distribution to interpret Pearson’s chi-squared statistic, as it accounts for the discrete nature of observed binomial frequencies.

field
Statistics
known_for
Pearson's chi-squared test, goodness of fit test

Lore & Background

In the 19th century, statistical analytical methods were mainly applied in biological data analysis, and researchers customarily assumed observations followed a normal distribution. Karl Pearson investigated a test of goodness of fit, proposing that under the null hypothesis, as n → ∞, the limiting distribution of the quantity X² = Σ (x_i - m_i)² / m_i follows the χ2 distribution with k − 1 degrees of freedom, where x_i are observed frequencies and m_i are expected frequencies. However, Pearson's original view on degrees of freedom was flawed. It was Ronald Fisher who later identified the issue and provided the correct adjustment: when parameters are estimated from the sample, the degrees of freedom must be reduced by the number of estimated parameters. For example, if r parameters are estimated, the correct degrees of freedom become k − 1 − r, not simply k − 1. Pearson had considered cases where expected numbers depended on parameters estimated from the sample, suggesting that the difference between X² and X'² would usually be positive and small enough to omit, but this omission is now known to be incorrect.

Reader's Guide

The chi-squared test is a foundational tool in statistics, primarily used to determine whether there is a statistically significant difference between expected and observed frequencies in one or more categories of a contingency table. Pearson's work allowed researchers to model skewed distributions and test goodness of fit, providing a method that remains widely applied today. The test's validity relies on the test statistic being chi-squared distributed under the null hypothesis, with the approximation improving as sample sizes increase. For smaller sample sizes, Fisher's exact test is used instead. The chi-squared test is also applied to test the null hypothesis of independence of a pair of random variables based on observations of the pairs. Despite its utility, Pearson's handling of estimated parameters led to a controversy that took two decades to resolve, highlighting the importance of rigorous statistical theory. The test's legacy endures as a standard method for categorical data analysis across many fields.

Did You Know?

Purpose and Core Application

The chi-squared test stands as a cornerstone of categorical data analysis, designed to answer a deceptively simple question: do two variables truly influence each other, or is any apparent association merely a product of chance? At its heart, the test operates on contingency tables—structured grids where observations are sorted into mutually exclusive classes along two dimensions. The null hypothesis posits that no meaningful difference exists between the classes in the underlying population. The test statistic then quantifies how far the observed frequencies deviate from what would be expected if that null hypothesis held true. A statistically significant result signals that the pattern of counts across categories is unlikely to have arisen by random fluctuation alone, suggesting the two categorical dimensions are not independent. This framework makes the chi-squared test indispensable whenever researchers need to assess relationships between discrete, non-numeric variables without assuming any particular shape for the underlying distribution.

Historical Origins and Pearson's Contribution

Before the turn of the twentieth century, statistical practice in biology and related fields was dominated by a single assumption: that observations naturally followed a normal distribution. Pioneers like Sir George Airy and Mansfield Merriman built their analytical work on this premise, but Karl Pearson challenged it. His method paired this flexible modeling with a goodness-of-fit procedure to judge how well a chosen distribution matched the data. It is broadly recognized as a pillar upon which much of modern statistics was built, transforming how scientists evaluate whether a theoretical model genuinely describes observed reality.

Mathematical Architecture and Asymptotic Behavior

The elegance of the chi-squared test lies in its mathematical structure. When n observations are partitioned into k mutually exclusive classes, and a null hypothesis assigns a probability p_i to each class, the expected count for class i becomes m_i = n·p_i. Pearson demonstrated that the quantity summing (x_i − m_i)² / m_i across all classes converges to a chi-squared distribution as n grows without bound. This asymptotic property is the test's defining characteristic: the shape of the statistic's sampling distribution draws nearer to the chi-squared curve as the number of observations grows, which is precisely why the test is recommended for large samples. The validity of the chi-squared distribution for the test statistic further requires that observations be independent. Beyond the classic goodness-of-fit setting, the same distributional logic extends to testing whether a pair of random variables is independent, based on paired observations. In both scenarios, the chi-squared framework provides a unified route to hypothesis testing that does not require the data to be normally distributed.

Practical Boundaries and the Role of Alternatives

The chi-squared test, while powerful, operates within clearly defined constraints that practitioners must respect. Its primary requirement is a sufficiently large sample size; the asymptotic convergence to the chi-squared distribution simply does not hold for small datasets. In such cases, Fisher's exact test serves as the appropriate alternative, computing exact probabilities rather than relying on distributional approximation. Additionally, the observations must fall into mutually exclusive classes—each data point belongs to one and only one category—and the independence of observations is a non-negotiable assumption for the test statistic to follow the chi-squared distribution. The test is also fundamentally a tool for categorical, not continuous, data, making it unsuitable for scenarios where the variables of interest are measured on a numerical scale. These boundaries do not diminish the test's utility but rather clarify its domain: large-sample, categorical, independence-based inference remains the territory where the chi-squared approach delivers its most reliable and interpretable results.

More in Probability And Stochastic Processes 1-21

Spotted an error? Know more?

This is a living reference — every entry is fact-audited, and reader corrections feed straight into our audit queue. Suggest an edit · See this site's audit record

Comments

Loading…
Open in the interactive codex →