Historical Context & Motivation
Statistical inference about categorical data presents a fundamentally different challenge than inference about continuous measurements. When a researcher records whether subjects fall into categories—political affiliation, blood type, customer preference—the resulting data are counts rather than means, and the familiar z- and t-procedures no longer apply. The need for a dedicated framework to compare observed categorical frequencies against theoretical or hypothesized frequencies motivated one of the most versatile tools in all of statistics: the chi-square test. At the heart of every chi-square test lies the concept of expected counts—the frequencies we would anticipate in each cell if the null hypothesis were true—and the validity of the entire procedure rests on a set of conditions that must be checked before any conclusion is drawn.
The central question this lesson addresses is twofold: how do we calculate the expected counts that serve as the benchmark in any chi-square test, and what conditions must be satisfied so that the chi-square distribution provides a reliable approximation to the true sampling distribution of the test statistic? Without a firm grasp of both, even a correctly computed test statistic may lead to erroneous conclusions.
Core Principles & Definitions
Before computing any chi-square statistic, you must understand the conceptual scaffolding on which the test rests. The chi-square family encompasses three common tests—goodness of fit, test of independence, and test of homogeneity—and all three rely on the same underlying logic: compare what you observe in the data to what you would expect under a specific null hypothesis. The magnitude of the discrepancy, measured in a standardized way, determines the test statistic. Below are the foundational ideas that underpin expected count calculations and the conditions for their use.
Expected Count
Observed Count
Chi-Square Statistic
Degrees of Freedom
Conditions for Inference
Visualizing Expected vs. Observed Counts
A powerful way to build intuition for expected counts is to visualize how they compare to observed counts across multiple categories. The diagram below presents a side-by-side bar chart for a hypothetical goodness-of-fit scenario: a die-rolling experiment with n = 120 rolls. Under the null hypothesis that the die is fair, each face has probability 1/6, yielding an expected count of 20 per face. The observed counts, drawn from actual data, deviate from this uniform expectation, and the chi-square statistic quantifies whether those deviations are larger than chance alone would produce.
Notice that the expected count line sits at 20 for every face—a direct consequence of the null hypothesis asserting equal probability across all six outcomes. The observed counts scatter above and below this reference. Each cell's contribution to the chi-square statistic is (O − E)² / E; cells with larger absolute deviations from the expected count, such as Face 3 (O = 27) and Face 6 (O = 14), dominate the sum. Visualizing the data this way reinforces a crucial insight: the chi-square statistic aggregates squared, standardized discrepancies across all categories, and it is the pattern of deviations—not any single category—that drives the result.
Mathematical Framework
The computation of expected counts differs depending on which chi-square test you are conducting. We present the formulas for the two most common settings: the goodness-of-fit test (one categorical variable) and the test of independence or homogeneity (two categorical variables in an r × c table). In both cases, the expected count for a cell represents the count that would be predicted if the null hypothesis held exactly, scaled by the sample size.
Goodness-of-Fit Expected Counts
Two-Way Table Expected Counts
The Chi-Square Test Statistic
Conditions for the Chi-Square Test
The chi-square test statistic only follows the χ² distribution approximately, and that approximation degrades when certain conditions are violated. Before reporting a p-value or making a reject/fail-to-reject decision, you must verify three categories of conditions. Failing to check these conditions is one of the most common errors in applied categorical analysis and can lead to inflated Type I error rates or diminished power.
Condition Details
The randomness condition requires that the data arise from a probability-based sampling mechanism or a randomized experiment. Without random selection, the sample may not represent the population, and without random assignment, confounding variables may explain observed differences between groups. In practice, you should state how the data were collected and confirm that randomization was employed.
The independence condition demands that each observation provides information independent of all other observations. When sampling without replacement from a finite population, this is approximately satisfied provided the sample is no more than 10% of the population (the 10% condition). Matched or repeated-measures designs violate independence and require alternative methods such as McNemar's test.
The large counts condition (also called the large-sample condition) stipulates that every expected count must be at least 5. This threshold, rooted in Cochran's 1954 guidelines, ensures that the continuous χ² distribution provides a close approximation to the discrete distribution of the test statistic. If any expected count falls below 5, remedies include combining sparse categories, collecting a larger sample, or switching to an exact test (e.g., Fisher's exact test for 2 × 2 tables). Note that this condition concerns expected counts, not observed counts—a frequent source of student confusion.
Worked Example — Two-Way Table
A university dining services office surveys a random sample of 400 students about their preferred meal plan (Unlimited, 14-Meal, or 8-Meal) and their year in school (Underclass: first-year or sophomore; Upperclass: junior or senior). The administrators want to know whether meal-plan preference is independent of class standing. Below is the observed two-way table.
| Unlimited | 14-Meal | 8-Meal | Row Total | |
|---|---|---|---|---|
| Underclass | 120 | 90 | 40 | 250 |
| Upperclass | 50 | 60 | 40 | 150 |
| Column Total | 170 | 150 | 80 | 400 |
Because all three conditions are met, we can trust the chi-square approximation. With χ² ≈ 10.48 on 2 degrees of freedom, the p-value is approximately 0.0053, providing strong evidence against the null hypothesis of independence. We conclude that there is a statistically significant association between class standing and meal-plan preference at any conventional significance level.
Strengths, Limitations & Remedies
The chi-square test is remarkably versatile, but like all statistical procedures it has both strengths and limitations. Understanding these trade-offs allows you to choose the right tool for a given dataset and to interpret results responsibly.
| Strengths | Limitations | Possible Remedies |
|---|---|---|
| Works with nominal (unordered) categorical data where parametric tests cannot be applied. | Does not measure the strength or direction of an association; only tests whether one exists. | Supplement with Cramér's V or phi coefficient to quantify effect size. |
| Generalizes easily to tables of any dimension (r × c) and to goodness-of-fit with many categories. | Requires all expected counts ≥ 5; sparse tables with low expected counts violate the large-counts condition. | Combine sparse categories, increase sample size, or use Fisher's exact test. |
| Simple to compute by hand and widely available in every statistical software package. | Sensitive to sample size: very large samples may yield statistical significance for trivially small deviations. | Report effect sizes alongside p-values to distinguish practical from statistical significance. |
| Assumptions are transparent and easy to check before conducting the test. | Cannot handle paired or matched data; observations must be independent. | Use McNemar's test for matched-pair categorical data. |
Connection to Advanced Theory
The expected-count machinery and conditions you have learned generalize naturally into more advanced frameworks. Understanding where the introductory chi-square test sits within the broader statistical landscape clarifies both its power and its boundaries, and prepares you for methods you may encounter in upper-division courses or graduate-level research.
| Introductory Chi-Square | Advanced Extension |
|---|---|
| Pearson χ² statistic: Σ (O − E)² / E | Likelihood-ratio G² statistic: 2 Σ O × ln(O / E). Asymptotically equivalent to χ² but preferred in log-linear modeling and when nested models are compared. |
| Expected counts computed from marginal totals assuming independence. | Log-linear models parameterize expected counts using main effects and interaction terms, accommodating multi-way tables with three or more categorical variables. |
| All expected counts ≥ 5 for valid approximation. | Exact tests (Fisher's, Freeman-Halton) and permutation tests are used when expected counts are too small, providing exact p-values without distributional assumptions. |
| Binary or polytomous outcome with no ordinal structure assumed. | Cochran-Armitage trend test and ordinal logistic regression exploit the ordering of categories, often yielding greater power when the response is ordinal. |
Mastering expected counts and conditions at the introductory level provides the conceptual foundation for these advanced methods. In particular, the logic of comparing observed to expected under a model carries directly into generalized linear models, where the expected cell counts are expressed as functions of model parameters and the deviance (based on G²) replaces the familiar χ² in model-selection contexts. Regardless of the complexity of the method, the fundamental question remains unchanged: are the observed data compatible with what the model predicts?
Practice Problems
Summary & Review
The expected count for a chi-square test represents the frequency you would anticipate in each cell if the null hypothesis were exactly true. For a goodness-of-fit test, compute E = n × p₀; for a test of independence or homogeneity, compute E = (row total × column total) / grand total. The chi-square statistic χ² = Σ (O − E)² / E aggregates the standardized squared deviations across all cells, and larger values provide stronger evidence against H₀.
Before interpreting any chi-square result, verify three conditions: randomness (data from a random sample or randomized experiment), independence (observations are independent; if sampling without replacement, n ≤ 10% of the population), and the large counts condition (every expected count is at least 5). When the large-counts condition fails, consider combining categories, increasing the sample size, or using an exact test. Remember: the condition applies to expected counts, not observed counts.