What is the Chi-Square (χ²) Test?
The Chi-Square (χ²) test is one of the most foundational and widely applied non-parametric hypothesis tests in modern statistical analysis. Introduced in 1900 by British mathematician and polymath Karl Pearson, the test evaluates whether an observed frequency distribution of categorical events differs significantly from the distribution that would be expected under a theoretical null hypothesis (H₀).
Unlike parametric tests such as the Student's t-test or ANOVA (Analysis of Variance), which require continuous numerical measurements and assumptions of normal distribution and homoscedasticity, the Chi-Square test operates directly on mutually exclusive categorical frequency counts. It is robust, mathematically transparent, and universally applicable across medicine, biology, sociology, marketing, epidemiology, and quality control.
Two Primary Types of Chi-Square Tests
Depending on the experimental design and the structure of the categorical variables, researchers apply one of two standard Chi-Square test variants:
1. The Chi-Square Test of Independence (Contingency Table)
The Test of Independence determines whether a statistically significant relationship exists between two distinct categorical variables evaluated on a single sample population. The data are arranged in an r × c contingency matrix (cross-tabulation table), where r represents the number of levels in Variable A and c represents the number of levels in Variable B.
- Null Hypothesis (H₀): Variable A and Variable B are independent; knowledge of one provides no predictive value regarding the other.
- Alternative Hypothesis (H₁): Variable A and Variable B are dependent; there is a statistically significant association between the two factors.
2. The Chi-Square Goodness-of-Fit Test
The Goodness-of-Fit test assesses whether the observed frequency distribution of a single categorical variable across k categories conforms to a hypothesized theoretical or historical distribution (such as uniform equal proportions, known demographic quotas, or Mendelian genetic ratios).
- Null Hypothesis (H₀): The observed sample frequencies follow the specified theoretical distribution.
- Alternative Hypothesis (H₁): The observed sample frequencies diverge significantly from the theoretical distribution.
The Pearson Chi-Square Formula Breakdown
The general formula for Pearson's Chi-Square test statistic across all categories or contingency table cells is:
Where:
- Oᵢ (Observed Frequency): The actual count of items, patients, or responses observed in category or cell i.
- Eᵢ (Expected Frequency): The theoretical count predicted to occur under the null hypothesis (H₀).
- (Oᵢ − Eᵢ): The residual discrepancy or deviation between observation and expectation.
- (Oᵢ − Eᵢ)²: The squared deviation, ensuring all differences remain non-negative and penalizing larger discrepancies disproportionately.
- (Oᵢ − Eᵢ)² / Eᵢ: The standardized squared residual weighted relative to the expected scale of the cell.
Expected Frequency Formula for Contingency Tables
Under the null hypothesis of independence, the expected cell frequency is calculated by multiplying its row total by its column total and dividing by the grand sample total:
Degrees of Freedom (df)
- For Contingency Tables:
df = (r − 1) × (c − 1), reflecting the number of cell counts that are freely variable given fixed marginal row and column totals. - For Goodness-of-Fit Tests:
df = k − 1(ork − 1 − mif m parameters were estimated directly from sample data).
Yates' Continuity Correction for 2×2 Tables
Because the continuous Chi-Square distribution is used as a smooth approximation to discrete multinomial counts, British statistician Frank Yates (1934) proposed subtracting 0.5 from the absolute deviation in 2×2 tables:
Quantifying Effect Size: Cramér's V, Phi, and Odds Ratio
Because the Chi-Square test statistic scales proportionally with sample size N, an enormous sample size can yield a statistically significant p < 0.001 even when the underlying relationship is practically trivial. Researchers must always report standardized effect sizes:
-
Cramér's V: The universal metric for tables of any dimension:
Values range from 0 (complete independence) to 1 (perfect association). For df* = 1: 0.10 is small, 0.30 is medium, and 0.50 is large.V = √ [ χ² / (N × min(r − 1, c − 1)) ]
- Phi Coefficient (φ): Specifically for 2×2 tables, defined as
φ = √(χ² / N). - Odds Ratio (OR): In 2×2 epidemiological and medical studies with cell counts
[[a, b], [c, d]], the Odds Ratio isOR = (a × d) / (b × c).
Calculation Procedure: How to Perform a Chi-Square Test
- Step 1: Formulate the Hypotheses. State the null hypothesis (H₀: no association) and alternative hypothesis (H₁: variables are associated). Select your significance threshold α (most commonly 0.05).
- Step 2: Construct the Observed Frequency Table. Enter observed counts into the contingency matrix. Compute row sums (Rᵢ), column sums (Cⱼ), and grand total (N).
- Step 3: Calculate Expected Frequencies. For every cell, compute
Eᵢⱼ = (Rᵢ × Cⱼ) / N. Verify Cochran's rule (allEᵢⱼ ≥ 1and at least 80%Eᵢⱼ ≥ 5). - Step 4: Compute Cell Discrepancies and Components. For each cell, calculate the residual
(O − E), square it(O − E)², and divide byEto find cell contribution(O − E)² / E. - Step 5: Sum All Components to Obtain χ². Add the contributions across all cells:
χ² = Σ [ (O − E)² / E ]. - Step 6: Determine Critical Value and P-Value. Calculate degrees of freedom
df = (r − 1)(c − 1). Look up critical value χ²_crit for your chosen α. - Step 7: State the Conclusion and Report Effect Size. If
χ² ≥ χ²_crit(orp ≤ α), reject H₀. Report the test statistic, degrees of freedom, exact p-value, and Cramér's V.
Worked Chi-Square Examples with Complete Working
Example 1: Chi-Square Test of Independence (2×2 Clinical Drug Trial)
Problem: A clinical trial tests a new antiviral medication against a placebo on 200 patients suffering from seasonal influenza:
| Treatment Group | Substantially Improved | Not Improved | Row Total (Rᵢ) |
|---|---|---|---|
| New Medication | 68 | 32 | 100 |
| Placebo | 42 | 58 | 100 |
| Column Total (Cⱼ) | 110 | 90 | N = 200 |
Step 1: Expected Frequencies
Step 2: Chi-Square Cell Contributions
| Cell | Observed (O) | Expected (E) | (O - E) | (O - E)² | Component (O - E)² / E |
|---|---|---|---|---|---|
| Drug / Improved | 68 | 55.0 | +13.0 | 169.0 | 3.0727 |
| Drug / Not Improved | 32 | 45.0 | -13.0 | 169.0 | 3.7556 |
| Placebo / Improved | 42 | 55.0 | -13.0 | 169.0 | 3.0727 |
| Placebo / Not Improved | 58 | 45.0 | +13.0 | 169.0 | 3.7556 |
| Total Chi-Square (χ²): | 13.6566 | ||||
Step 3: Degrees of Freedom & Decision
Conclusion: Because χ² = 13.6566 > 3.841 and p = 0.00022 < 0.05, we reject the null hypothesis. The new medication produces a statistically significant improvement over placebo.
Example 2: Goodness-of-Fit Test (Mendelian Genetics 9:3:3:1)
Problem: Dihybrid pea plant crosses produce 1,600 offspring. Gregor Mendel's Law of Independent Assortment predicts a phenotype ratio of 9:3:3:1. Test whether observed counts match this ratio at α = 0.05.
| Phenotype | Observed (O) | Expected (E) | (O - E) | (O - E)² | Component (O - E)² / E |
|---|---|---|---|---|---|
| Round Yellow | 920 | 900 | +20 | 400 | 0.4444 |
| Round Green | 295 | 300 | -5 | 25 | 0.0833 |
| Wrinkled Yellow | 315 | 300 | +15 | 225 | 0.7500 |
| Wrinkled Green | 70 | 100 | -30 | 900 | 9.0000 |
| Total Chi-Square (χ²): | 10.2778 | ||||
Conclusion: Because χ² = 10.2778 > 7.815 and p = 0.0163 < 0.05, we reject the null hypothesis. The observed phenotype frequencies diverge significantly from the classical 9:3:3:1 ratio, primarily due to a deficit of wrinkled green offspring.
Critical Assumptions and Cochran's Rule of 5
- 1. Random Sampling and Mutually Exclusive Observations: Each participant, specimen, or event must be counted in exactly one cell. The test cannot be used for repeated measures or longitudinal paired data (use McNemar's test instead).
- 2. Raw Frequency Counts: Data must be expressed as raw integer counts, never percentages, proportions, rates, or normalized indices.
- 3. Cochran's Rule of 5 (1954): No expected cell count should be less than 1, and no more than 20% of all expected cell counts should be less than 5.
- 4. Remedy for Violated Assumptions: If Cochran's rule is violated, use Fisher's Exact Test for 2×2 tables or pool adjacent categories with sparse counts in larger tables.
Properties of the Chi-Square Distribution
- Mean and Variance: For degrees of freedom k, the mean is
μ = kand variance isσ² = 2k. - Asymmetry and Skewness: When degrees of freedom are small (df = 1 or 2), the distribution is right-skewed. As df increases beyond 30, it approximates a symmetric normal distribution.
- Additivity Property: If independent random variables
X₁ ~ χ²(k₁)andX₂ ~ χ²(k₂), thenX₁ + X₂ ~ χ²(k₁ + k₂).
Academic References & Authoritative Sources
- Pearson, K. (1900). "On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling." Philosophical Magazine Series 5, 50(302), 157–175.
- Cochran, W. G. (1954). "Some methods for strengthening the common χ² tests." Biometrics, 10(4), 417–451.
- Yates, F. (1934). "Contingency tables involving small numbers and the χ² test." Supplement to the Journal of the Royal Statistical Society, 1(2), 217–235.
- Agresti, A. (2013). Categorical Data Analysis (3rd ed.). John Wiley & Sons, Hoboken, NJ.
- National Institute of Standards and Technology (NIST). "Chi-Square Goodness-of-Fit Test." e-Handbook of Statistical Methods, Section 1.3.5.15.
Frequently Asked Questions (FAQ)
What is the Chi-Square (χ²) test and when should I use it?
The Chi-Square (χ²) test is an omnibus non-parametric statistical hypothesis test introduced by Karl Pearson in 1900. It is used to analyze categorical (nominal or ordinal) frequency data. There are two primary types: (1) The Chi-Square Test of Independence determines whether two categorical variables in a contingency table are significantly associated or independent. (2) The Chi-Square Goodness-of-Fit test determines whether an observed categorical frequency distribution differs significantly from a theoretical or hypothesized distribution.
What is the difference between a Test of Independence and a Goodness-of-Fit test?
The Chi-Square Test of Independence analyzes two categorical variables simultaneously arranged in an r × c contingency matrix to test whether knowledge of one variable provides predictive information about the other. In contrast, the Goodness-of-Fit test examines a single categorical variable across k categories to verify whether observed counts match expected proportions (such as equal probabilities, genetic Mendelian 9:3:3:1 ratios, or known demographic percentages).
How do you calculate expected frequencies (E) in a contingency table?
In a contingency table under the null hypothesis of independence, the expected frequency for cell (i, j) is calculated by multiplying its row total (Ri) by its column total (Cj) and dividing by the grand sample total (N): E_ij = (Row Total × Column Total) / Grand Total. This represents the frequency count you would expect to see purely by chance if no relationship existed between the variables.
How do you calculate degrees of freedom (df) for Chi-Square?
For a Chi-Square Test of Independence in an r × c contingency table, degrees of freedom are computed as df = (r - 1) × (c - 1), where r is the number of rows and c is the number of columns. For a Goodness-of-Fit test with k categories, degrees of freedom are calculated as df = k - 1 (or k - 1 - m if m parameters were estimated from sample data).
How do you interpret the Chi-Square test statistic and p-value?
The Chi-Square test statistic (χ²) measures the aggregate discrepancy between observed counts (O) and expected counts (E). A larger χ² value produces a smaller p-value. If the p-value is less than or equal to your predetermined significance level (commonly α = 0.05 or 0.01), you reject the null hypothesis (H₀) and conclude that there is a statistically significant association or difference. If p > α, you fail to reject H₀.
What is Cochran's Rule of 5 and why is it important?
Cochran's Rule (1954) specifies the minimum sample size assumption for a valid Chi-Square approximation: no expected cell frequency should be less than 1, and no more than 20% of expected cell frequencies should be less than 5. When expected counts are too small, the discrete multinomial distribution diverges from the continuous Chi-Square distribution, leading to inflated Type I error rates. For 2×2 tables violating this rule, Fisher's Exact Test is recommended.
What is Yates' Continuity Correction and when should it be used?
Yates' Continuity Correction (Frank Yates, 1934) subtracts 0.5 from the absolute difference between observed and expected frequencies (|O - E| - 0.5)² in 2×2 contingency tables. Because the continuous Chi-Square distribution is used to approximate discrete frequency counts, Yates' correction prevents overestimation of statistical significance in small to moderate 2×2 samples.
How do you measure effect size in a Chi-Square test?
Because Chi-Square test statistics depend on sample size N (larger samples always yield higher χ²), effect size metrics quantify the actual strength of the association. For 2×2 tables, the Phi coefficient (φ) or Odds Ratio (OR) is used. For tables larger than 2×2, Cramér's V (ranging from 0 for no association to 1 for complete association) is the standard metric, computed as V = √[χ² / (N × min(r - 1, c - 1))].