SECTION 1
Historical Context & Motivation
Statistical inference for continuous data was well established by the late nineteenth century, but researchers lacked a rigorous method for testing hypotheses about categorical data — data that fall into discrete groups rather than lying on a numerical continuum. When a biologist counted phenotypes, or a sociologist tallied survey responses, the available tools for assessing whether those counts conformed to a theoretical model were crude at best. The breakthrough came from Karl Pearson, who in 1900 introduced a test statistic that elegantly quantified the discrepancy between observed and expected frequencies. His chi-square goodness-of-fit test became one of the most widely used inferential procedures in the sciences, social sciences, and industry.
1857 • Mendel's Pea Experiments
1900 • Pearson's Chi-Square Paper
1922 • Fisher's Correction
1934 • Neyman–Pearson Framework
The central question Pearson's test addresses is deceptively simple: given a set of observed counts across several categories, can we conclude that the underlying population distribution matches a specific theoretical distribution, or is the discrepancy large enough to reject that claim? This question arises constantly — testing whether a die is fair, whether genetic offspring ratios follow Mendelian predictions, whether customer preferences are uniformly distributed, or whether defect types occur at historically established rates. The chi-square goodness-of-fit test provides a principled, quantitative answer.
SECTION 2
Core Principles & Definitions
The chi-square goodness-of-fit test rests on a small set of foundational ideas that connect observed data to theoretical expectations. Understanding these principles is essential before examining the formula or interpreting output, because each one constrains when and how the test may be legitimately applied.
Observed vs. Expected Frequencies
Null and Alternative Hypotheses
The χ² Test Statistic
Degrees of Freedom
Conditions for Valid Inference
KEY TAKEAWAY
SECTION 3
Visual Explanation
A bar chart overlaying observed and expected frequencies is the most intuitive way to see how well data fit a hypothesized distribution. The diagram below shows a scenario in which a die is rolled 120 times and the observed counts are compared against the uniform expectation of 20 per face. Notice that some faces exceed the expected count while others fall short; the chi-square statistic measures whether these deviations, taken together, are larger than chance alone would produce.
In the diagram above, Face 4 has the largest positive deviation (O − E = 6) and Face 6 has the largest negative deviation (O − E = −6). Yet no single bar tells the whole story; the test aggregates information from all six categories into one summary statistic. Because the deviations are squared before summing, positive and negative deviations contribute equally, and larger deviations receive disproportionately more weight. The normalization by E ensures that a deviation of 6 when E = 20 is treated differently from a deviation of 6 when E = 200.
SECTION 4
Mathematical Framework
The mathematical backbone of the goodness-of-fit test is elegant in its simplicity. A single formula captures the intuition that we should penalize large deviations from expectation while accounting for the scale of each expected count. Below, we develop the test statistic, its sampling distribution, and the decision rule.
CHI-SQUARE TEST STATISTIC
where Oᵢ = observed count in category i, Eᵢ = expected count in category i (Eᵢ = n × pᵢ), and the summation runs over all k categories. The statistic is always non-negative; χ² = 0 only when every Oᵢ equals Eᵢ exactly.
EXPECTED COUNT
where n is the total sample size and pᵢ is the hypothesized probability for category i under H₀. The expected counts must sum to n, which is guaranteed because the pᵢ values sum to 1.
SAMPLING DISTRIBUTION & DEGREES OF FREEDOM
Under H₀ and given that the expected count conditions are met, the test statistic follows an approximate chi-square distribution with df degrees of freedom. Here k is the number of categories and m is the number of parameters estimated from the data. In the simplest case (all proportions fully specified by H₀), m = 0 and df = k − 1.
DECISION RULE
The test is always right-tailed. Large values of χ² indicate poor fit between the data and the hypothesized distribution. The critical value χ²(α, df) is obtained from chi-square distribution tables or software, and α is the pre-specified significance level (commonly 0.05).
Why Right-Tailed?
SECTION 5
The Chi-Square Distribution & Critical Regions
To convert the computed χ² statistic into a decision, we need the chi-square distribution, a family of right-skewed probability distributions indexed by degrees of freedom. As df increases, the distribution shifts rightward, its mean increases (mean = df), and its shape becomes more symmetric. For the goodness-of-fit test, the relevant distribution has df = k − 1, and the rejection region lies entirely in the right tail. The diagram below illustrates the chi-square density curve for df = 5, with the critical region shaded at α = 0.05.
| df | α = 0.10 | α = 0.05 | α = 0.01 |
|---|---|---|---|
| 1 | 2.706 | 3.841 | 6.635 |
| 2 | 4.605 | 5.991 | 9.210 |
| 3 | 6.251 | 7.815 | 11.345 |
| 4 | 7.779 | 9.488 | 13.277 |
| 5 | 9.236 | 11.070 | 15.086 |
| 6 | 10.645 | 12.592 | 16.812 |
Selected chi-square critical values for common significance levels
As the table illustrates, the critical value increases with both the degrees of freedom and the stringency of the significance level. For a given df, moving from α = 0.10 to α = 0.01 roughly doubles the critical threshold, reflecting the higher evidentiary bar required to declare statistical significance at more demanding levels.
SECTION 6
Worked Example
A genetics researcher crosses two heterozygous plants and observes the phenotypes of 200 offspring. According to Mendelian theory, the expected phenotypic ratio is 9:3:3:1 across four categories (Round-Yellow, Round-Green, Wrinkled-Yellow, Wrinkled-Green). The observed counts are 112, 48, 27, and 13 respectively. Does the data support the Mendelian model at the α = 0.05 significance level?
Testing Mendelian Ratios (9:3:3:1)
- 1
Step 1 — State the Hypotheses
H₀: The population distribution of phenotypes follows the 9:3:3:1 ratio, i.e., p₁ = 9/16, p₂ = 3/16, p₃ = 3/16, p₄ = 1/16. Hₐ: At least one phenotype proportion differs from the Mendelian prediction. - 2
Step 2 — Compute Expected Counts
With n = 200: E₁ = 200 × (9/16) = 112.5, E₂ = 200 × (3/16) = 37.5, E₃ = 200 × (3/16) = 37.5, E₄ = 200 × (1/16) = 12.5. All expected counts exceed 5, so the condition for the chi-square approximation is satisfied.E = (112.5, 37.5, 37.5, 12.5) - 3
Step 3 — Compute the χ² Statistic
χ² = (112 − 112.5)²/112.5 + (48 − 37.5)²/37.5 + (27 − 37.5)²/37.5 + (13 − 12.5)²/12.5 = (−0.5)²/112.5 + (10.5)²/37.5 + (−10.5)²/37.5 + (0.5)²/12.5 = 0.25/112.5 + 110.25/37.5 + 110.25/37.5 + 0.25/12.5 = 0.0022 + 2.94 + 2.94 + 0.02 = 5.9022χ² ≈ 5.90 - 4
Step 4 — Determine Degrees of Freedom
There are k = 4 categories and no parameters were estimated from the data (all proportions were specified by H₀), so df = k − 1 = 4 − 1 = 3.df = 3 - 5
Step 5 — Find the Critical Value and Make a Decision
From the chi-square table (or software), χ²(0.05, 3) = 7.815. Since our computed statistic 5.90 < 7.815, we fail to reject H₀. Alternatively, the p-value for χ² = 5.90 with 3 df is approximately 0.117, which exceeds α = 0.05.Fail to reject H₀. The data are consistent with the 9:3:3:1 Mendelian ratio at the 0.05 significance level. - 6
Step 6 — Interpret in Context
There is not sufficient evidence at the 5% significance level to conclude that the offspring phenotype distribution departs from the expected 9:3:3:1 Mendelian ratio. Note, however, that the largest contributions to χ² come from the Round-Green and Wrinkled-Yellow categories, each contributing about 2.94. If the researcher were concerned about these specific deviations, further experimentation with a larger sample size would increase the test's power to detect a genuine departure from the model.
SECTION 7
Assumptions, Strengths & Limitations
Like every statistical procedure, the chi-square goodness-of-fit test operates under specific assumptions that, if violated, can compromise the validity of its conclusions. Understanding both the strengths and limitations of the test is essential for responsible application.
| Aspect | Strengths | Limitations |
|---|---|---|
| Generality | Applicable to any fully specified discrete distribution — uniform, binomial, Poisson, or custom ratios. | Cannot be used for continuous data without first binning into categories, which introduces arbitrary choices. |
| Sample Size | Works well for moderate to large samples. No distributional assumption on the raw data (only on counts). | Requires all expected counts ≥ 5. With small expected counts, the chi-square approximation breaks down; Fisher's exact test or simulation methods may be preferable. |
| Directionality | The omnibus nature detects any departure from H₀, regardless of which category is the source. | Being omnibus, it does not indicate which specific category (or categories) deviate from expectation. Post-hoc residual analysis is needed. |
| Simplicity | The formula is straightforward and can be computed by hand or with any statistical software. | Simplicity can lead to misuse — applying the test to non-independent observations (e.g., repeated measures on the same subjects) is a common error. |
| Power | Power increases with sample size. For large n, even subtle departures from H₀ become detectable. | With very large samples, trivially small departures become statistically significant — effect size and practical significance must also be considered. |
Strengths and limitations of the chi-square goodness-of-fit test
KEY TAKEAWAY
SECTION 8
Connection to Advanced Chi-Square Methods
The goodness-of-fit test is only one member of a broader family of chi-square procedures used in categorical data analysis. Understanding where it sits relative to its siblings — the chi-square test of independence and the chi-square test of homogeneity — helps clarify when each is appropriate and reveals a unifying structure. Beyond these classical tests, more advanced approaches like the likelihood-ratio test (G-test) and log-linear models extend the core ideas to multidimensional contingency tables and complex model comparisons.
| Feature | Goodness-of-Fit | Test of Independence | Test of Homogeneity |
|---|---|---|---|
| Number of Variables | One categorical variable | Two categorical variables | One categorical variable across multiple populations |
| Data Layout | One-way frequency table (1 × k) | Two-way contingency table (r × c) | Two-way contingency table (r × c) |
| H₀ | Data follow a specified distribution | Two variables are independent in one population | Distribution of one variable is the same across populations |
| Degrees of Freedom | k − 1 | (r − 1)(c − 1) | (r − 1)(c − 1) |
| Sampling Design | One sample, one variable | One sample, cross-classified | Independent samples from each population |
Comparison of the three classical chi-square tests
As you advance through categorical data analysis, you will encounter the likelihood-ratio statistic G², defined as G² = 2 Σ Oᵢ ln(Oᵢ / Eᵢ). Under the same conditions, G² has an asymptotically equivalent chi-square distribution, but it is preferred in model-selection contexts because likelihood-ratio statistics are additive — the difference between nested models' G² values is itself a chi-square random variable, enabling systematic model comparison. Log-linear models generalize this idea to multi-way tables, modeling the logarithm of expected cell counts as a linear function of main effects and interactions, much as ANOVA models decompose variance for continuous outcomes. These advanced tools all trace their lineage back to Pearson's original goodness-of-fit framework.
SECTION 9
Practice Problems
Question 1: CONCEPTUAL
Show answer
Question 2: BASIC CALCULATION
Show answer
Question 3: INTERMEDIATE
Show answer
Question 4: APPLIED
Show answer
Question 5: CRITICAL THINKING
Show answer
SUMMARY
Lesson Summary
Summary
The chi-square goodness-of-fit test evaluates whether a sample of categorical data conforms to a hypothesized distribution. Developed by Karl Pearson in 1900, it computes the test statistic χ² = Σ (Oᵢ − Eᵢ)² / Eᵢ, which aggregates the squared, normalized deviations between observed counts and expected counts. Under H₀, this statistic follows a chi-square distribution with df = k − 1 degrees of freedom, and the test is always right-tailed.
Valid application requires a random sample, independent observations, and all expected counts ≥ 5. The test is an omnibus procedure — it detects any departure from H₀ but does not identify which specific categories are responsible; standardized residuals serve that diagnostic role. The goodness-of-fit test is the foundation for more advanced chi-square methods, including the test of independence, the test of homogeneity, and log-linear models for multi-way contingency tables.