Historical Context & Motivation
Long before the formal apparatus of hypothesis testing existed, researchers confronted a deceptively simple question: when observed counts in a table of categorical data deviate from what we would expect under some null model, how do we decide whether those deviations are large enough to matter? The answer required a test statistic whose sampling distribution was known, and the development of that statistic — the chi-square (χ²) statistic — reshaped how scientists analyze categorical data. Understanding the historical trajectory of this tool illuminates why the setup of a chi-square test matters just as much as the computation itself.
Despite the shared computation, the test for homogeneity and the test for independence begin with fundamentally different research designs and hypotheses. The AP Statistics exam rewards students who can clearly articulate which test applies to a given scenario, state the correct hypotheses, verify the conditions, and interpret results in context. This lesson addresses the critical question: how do you set up each test correctly before any arithmetic begins?
Core Principles & Definitions
Before you can set up a chi-square test correctly, you need a firm grasp of several interrelated concepts. Both the test for homogeneity and the test for independence analyze data organized in a two-way table (also called a contingency table), where one categorical variable defines the rows and another defines the columns. The cells contain observed counts — not percentages or proportions. The distinction between the two tests lies entirely in how the data were collected and what the null hypothesis claims.
Test for Homogeneity
Test for Independence
Expected Counts
Degrees of Freedom
Conditions for Inference
Visual Explanation: Study Design Decision Flowchart
One of the most common exam pitfalls is misidentifying which chi-square test to use. The following flowchart walks you through the decision process based entirely on how the data were collected. Start at the top and follow the arrows to determine the correct test setup.
Notice that the flowchart converges at the bottom: both tests use the same χ² formula and the same degrees of freedom. The only differences are (1) the research design, (2) the wording of the hypotheses, and (3) which totals in the two-way table are predetermined by the design. On the AP exam, identifying these distinctions in context is worth significant credit in free-response scoring.
Mathematical Framework
Setting up the chi-square test requires computing expected counts under the null hypothesis and then measuring how far the observed data depart from those expectations. The mathematical machinery is compact but conceptually powerful: every cell in the two-way table contributes a term to the test statistic, and the sum of those terms follows a known distribution (under certain conditions) that lets us compute a p-value.
Stating the Hypotheses
Although the computation is identical, the hypotheses must match the study design. For a test for homogeneity: H₀ states that the distribution of the categorical response variable is the same for all populations (or treatment groups); Hₐ states that at least one population's distribution differs. For a test for independence: H₀ states that the two categorical variables are independent in the population; Hₐ states that the two variables are not independent (i.e., they are associated). On the AP exam, you must state these hypotheses in the context of the given problem, not just symbolically.
Checking the Conditions for Inference
Before computing the χ² statistic, you must verify three conditions. On the AP exam, failing to check conditions — or checking them incorrectly — is a common source of lost points on free-response questions. The conditions are the same for both the homogeneity and independence tests, though the way you describe the randomness condition differs slightly based on the study design.
A critical detail that many students overlook: the Large Counts condition applies to expected counts, not observed counts. If even one expected count falls below 5, the χ² approximation to the true sampling distribution becomes unreliable, and the test should not be performed in its standard form. In practice, this means you must compute (or at least spot-check) expected counts before running the test — which is why setting up the test carefully is so important.
Worked Example: Setting Up a Chi-Square Test
A university's admissions office surveyed a random sample of 400 current students and recorded each student's class year (Freshman, Sophomore, Junior, Senior) and preferred study location (Library, Dorm Room, Coffee Shop). The admissions office wants to know whether preferred study location is associated with class year. Here is the observed data:
| Library | Dorm Room | Coffee Shop | Row Total | |
|---|---|---|---|---|
| Freshman | 40 | 45 | 15 | 100 |
| Sophomore | 38 | 42 | 20 | 100 |
| Junior | 35 | 30 | 35 | 100 |
| Senior | 27 | 23 | 50 | 100 |
| Col Total | 140 | 140 | 120 | 400 |
Comparing Homogeneity, Independence, and Goodness-of-Fit
Students often confuse the three chi-square tests because they all involve categorical data and similar-looking formulas. The table below organizes the key differences along the dimensions that matter most for setting up each test: the study design, the hypotheses, the type of table, and the degrees of freedom formula.
| Feature | Goodness-of-Fit | Homogeneity | Independence |
|---|---|---|---|
| # of variables | 1 categorical variable | 1 categorical variable across ≥ 2 populations | 2 categorical variables in 1 population |
| # of samples | 1 sample | ≥ 2 independent samples | 1 sample |
| Table type | One-way (1 × c) | Two-way (r × c) | Two-way (r × c) |
| H₀ | Distribution matches a specified model | Distribution is the same across all populations | The two variables are independent |
| Degrees of freedom | k − 1 (k = # categories) | (r − 1)(c − 1) | (r − 1)(c − 1) |
| Expected counts | np₀ for each category | (row total × col total) / n | (row total × col total) / n |
Connections to Advanced Theory
The chi-square tests you learn in AP Statistics are special cases of a broader inferential framework. Understanding where these tests sit in the larger landscape of statistics helps you appreciate both their power and their limitations, and it previews material you will encounter in college-level courses.
| AP Statistics Level | Advanced / College Level |
|---|---|
| χ² test statistic: Σ (O − E)² / E | Derived as −2 × log-likelihood ratio (G-test), which is asymptotically equivalent to Pearson's χ² |
| Large counts condition: all E ≥ 5 | When expected counts are small, Fisher's exact test or permutation-based methods provide exact p-values |
| Reject or fail to reject H₀ | Standardized residuals (O − E) / √E identify which cells contribute most to the χ² statistic — a form of post-hoc analysis |
| Two-way tables only | Log-linear models extend χ² analysis to multi-way contingency tables with three or more categorical variables |
| No effect-size measure required | Cramér's V and the contingency coefficient quantify the strength of association, supplementing the significance test |
For the AP exam, you do not need to know Fisher's exact test, log-linear models, or Cramér's V. However, understanding that the chi-square test is an approximation that improves with larger expected counts deepens your understanding of why the conditions matter. The requirement that all expected counts be at least 5 is a practical threshold below which the χ² distribution becomes a poor model for the true sampling distribution of the test statistic. In more advanced courses, you will learn exact and simulation-based alternatives that remove this restriction.
Practice Problems
Summary
Setting up a chi-square test correctly is the most conceptually demanding part of the procedure. The test for homogeneity applies when independent random samples are drawn from two or more populations (or subjects are randomly assigned to treatment groups), and the goal is to determine whether the distribution of a single categorical variable is the same across all populations. The test for independence applies when a single random sample is drawn from one population and each individual is classified on two categorical variables, with the goal of assessing whether those variables are associated.
Both tests use the same χ² = Σ (O − E)² / E test statistic, compute expected counts as (row total × column total) / grand total, and use df = (r − 1)(c − 1). Before computing, you must verify three conditions: the data were collected via random sampling or random assignment, the observations are independent (10% condition if sampling without replacement), and all expected counts are at least 5. On the AP exam, clearly identifying the test, stating hypotheses in context, and verifying conditions earn the majority of setup points.