AP STATISTICS • INFERENCE FOR CATEGORICAL DATA: CHI-SQUARE

Carrying Out a Chi-Square Test for Homogeneity or Independence

Determine whether categorical variables are related by comparing observed and expected counts in two-way tables.

Historical Context & Motivation

Long before modern software made hypothesis testing routine, researchers faced a fundamental question: when you observe different proportions across groups, how do you know the difference is real rather than the product of random sampling variability? In the late nineteenth century, Karl Pearson developed a single statistic—what we now call the chi-square statistic—that elegantly measures the total discrepancy between what we observe in categorical data and what we would expect if there were no association. This idea became the backbone of two closely related tests: the chi-square test for independence and the chi-square test for homogeneity.

1900
Pearson's Chi-Square
Karl Pearson publishes 'On the Criterion that a Given System of Deviations…,' introducing the χ² goodness-of-fit statistic and the family of chi-square distributions.
1922
Fisher's Correction
R. A. Fisher clarifies the correct degrees of freedom for contingency tables, establishing (r − 1)(c − 1) as the standard and resolving Pearson's earlier miscalculation.
1954
Cochran's Guidelines
W. G. Cochran formalizes the expected-count condition: the chi-square approximation is reliable when all expected counts are at least 5, a rule still cited on the AP exam today.
2000s
Modern AP Curriculum
The College Board integrates chi-square tests for goodness-of-fit, homogeneity, and independence as core inference procedures, emphasizing a unified four-step framework: State, Plan, Do, Conclude.

The central question these tests address is deceptively simple: Is there convincing evidence that two categorical variables are associated, or that the distribution of a categorical variable differs across populations? Answering this requires a structured hypothesis-testing procedure that converts a two-way table of counts into a single test statistic, then assesses how unusual that statistic would be if the null hypothesis were true.

Core Principles & Definitions

Before executing the mechanics of a chi-square test, it is essential to distinguish the two test types and understand the logic that unites them. Both tests use the same formula and the same chi-square distribution, but they arise from different sampling designs and answer subtly different questions.

1

Test for Independence

A single sample is drawn from one population and each individual is classified on two categorical variables. H₀: the two variables are independent.
2

Test for Homogeneity

Independent samples are drawn from two or more populations (or treatment groups), and each individual is classified on one categorical variable. H₀: the distribution of that variable is the same across all populations.
3

Expected Counts

Under H₀, the expected count for any cell equals (row total × column total) / grand total. These represent counts we'd anticipate if no association exists.
4

Chi-Square Statistic

χ² = Σ (O − E)² / E sums squared deviations of observed from expected, scaled by expected count, across every cell. Larger values signal greater departure from H₀.
5

Degrees of Freedom

df = (r − 1)(c − 1), where r is the number of rows and c is the number of columns. This determines which chi-square distribution is used to find the P-value.
KEY TAKEAWAY
KEY TAKEAWAY

Visual Explanation

Flowchart: Carrying Out a Chi-Square Test

This flowchart traces the four-step procedure (State → Plan → Do → Conclude) used for both the chi-square test for homogeneity and the chi-square test for independence. The 'Plan' step branches into two conditions that must be verified before proceeding.

The flowchart above captures the backbone of every chi-square test on the AP exam. Notice that the Plan stage requires you to check two conditions: the data must come from a random process (either an SRS from a population or a randomized experiment), and all expected counts must be at least 5. If either condition fails, the chi-square approximation may be unreliable and the conclusion invalid. In the 'Do' step, you compute expected counts using the formula E = (row total × column total) / n, then plug every cell's observed and expected counts into the chi-square formula before looking up the P-value using the χ² distribution with (r − 1)(c − 1) degrees of freedom.

Mathematical Framework

The mathematical machinery behind the chi-square test is elegant in its simplicity. Three formulas do all the heavy lifting: one computes expected counts, one computes the test statistic, and one determines degrees of freedom. Together they convert a table of raw counts into a single number that can be compared against a known probability distribution.

EXPECTED COUNT
E = (row total × column total) / n
For each cell in the two-way table, E is the count expected under H₀. The row total is the sum of observed counts in that cell's row, the column total is the sum in that cell's column, and n is the grand total of all observations.
CHI-SQUARE TEST STATISTIC
χ² = Σ (O − E)² / E
Sum over all cells in the table. O is the observed count and E is the expected count for each cell. Squaring ensures positive and negative deviations contribute equally; dividing by E standardizes the contribution so that cells with larger expected counts do not dominate by default.
DEGREES OF FREEDOM
df = (r − 1)(c − 1)
Here r is the number of rows and c is the number of columns in the two-way table. The degrees of freedom determine which member of the chi-square family of distributions is used to compute the P-value.
P-VALUE
P-value = P(χ² ≥ χ²observed | df)
The P-value is always a right-tail probability because larger χ² values correspond to greater departure from H₀. Use a χ² distribution table or your calculator's χ²cdf function.
Calculator Tip

Anatomy of Chi-Square Components

Each cell in the two-way table contributes one component to the overall chi-square statistic. Examining these individual components tells you which cells deviate most from what independence or homogeneity would predict. After rejecting H₀, it is good practice (and often requested on the AP exam) to identify the largest components and explain their direction—whether the observed count is above or below the expected count—because this provides context for the nature of the association.

Each bar represents one cell's contribution (O − E)² / E to the overall χ² statistic. Cell (1,1) contributes the most at 5.52—this cell drives the bulk of the evidence against H₀. Summing all bars gives the total χ² value of 10.63.

The bar chart above illustrates how unevenly components can contribute. In this hypothetical 3 × 2 table, Cell (1,1) alone accounts for over half of the total χ² = 10.63. On a free-response question, identifying this cell and stating whether O exceeded or fell short of E demonstrates a deeper understanding than simply reporting χ² and the P-value. Remember: the chi-square statistic is a sum, and understanding the parts of that sum tells you where the association is strongest.

AP Exam Tip

Worked Example

A researcher surveys 400 randomly selected adults from three regions (North, Central, South) and records whether each person supports or opposes a proposed policy. The data are summarized below.

Observed counts for policy opinion by region
SupportOpposeRow Total
North7050120
Central10555160
South7545120
Col Total250150400
1
Step 1 — State HypothesesH₀: The distribution of opinion (Support vs. Oppose) is the same for all three regions. Hₐ: The distribution of opinion is not the same for all three regions. We use α = 0.05.
2
Step 2 — Plan: Name Test & Check ConditionsWe will perform a chi-square test for homogeneity. Random: The problem states adults were randomly selected. Large Counts: We compute expected counts: E(North, Support) = 120 × 250 / 400 = 75; E(North, Oppose) = 120 × 150 / 400 = 45; E(Central, Support) = 160 × 250 / 400 = 100; E(Central, Oppose) = 160 × 150 / 400 = 60; E(South, Support) = 120 × 250 / 400 = 75; E(South, Oppose) = 120 × 150 / 400 = 45. All expected counts are ≥ 5. ✓
3
Step 3 — Do: Compute χ² and P-valueCompute each component (O − E)² / E: (70 − 75)²/75 = 0.333; (50 − 45)²/45 = 0.556; (105 − 100)²/100 = 0.250; (55 − 60)²/60 = 0.417; (75 − 75)²/75 = 0.000; (45 − 45)²/45 = 0.000.
χ² = 0.333 + 0.556 + 0.250 + 0.417 + 0.000 + 0.000 = 1.556. df = (3 − 1)(2 − 1) = 2. Using χ²cdf(1.556, 10⁹, 2), the P-value ≈ 0.459.
4
Step 4 — ConcludeBecause the P-value (0.459) is greater than α = 0.05, we fail to reject H₀. There is not convincing evidence that the distribution of opinion on the proposed policy differs across the three regions.
Scoring Note

Homogeneity vs. Independence: Strengths & Limitations

Side-by-side comparison of the two chi-square tests
FeatureTest for HomogeneityTest for Independence
Sampling DesignIndependent random samples from 2+ populations (or groups in an experiment)Single random sample from one population; each individual classified on two variables
Null HypothesisThe distribution of the response variable is the same across all populationsThe two categorical variables are independent in the population
Formulaχ² = Σ (O − E)² / E — identicalχ² = Σ (O − E)² / E — identical
Degrees of Freedom(r − 1)(c − 1) — identical(r − 1)(c − 1) — identical
Key LimitationCannot establish causation unless data come from a randomized experimentCannot establish causation; association ≠ causation for observational data
ConditionsRandom samples/assignment; all expected counts ≥ 5Random sample; all expected counts ≥ 5
KEY TAKEAWAY
KEY TAKEAWAY

Connection to Advanced Methods

The chi-square test for homogeneity and independence is your first encounter with a broader family of categorical-data methods. In a college statistics course or graduate research, you will meet extensions that handle situations the basic chi-square test cannot.

AP-Level ConceptAdvanced Extension
χ² test with all expected counts ≥ 5Fisher's Exact Test: used when expected counts are small and the chi-square approximation is unreliable
Two-way table with r × c cellsLog-linear models: model complex multi-way contingency tables with three or more categorical variables simultaneously
χ² tests association (yes/no)Cramér's V and odds ratios: measure the strength and direction of association, not just its existence
Independent observationsMcNemar's test: handles paired or matched categorical data (e.g., before/after studies)

For the AP exam, you will not be asked to perform these advanced methods, but understanding that the chi-square test has limitations—it cannot measure strength of association, it requires sufficiently large expected counts, and it assumes independent observations—prepares you to appreciate why statisticians developed these refinements. A strong conceptual grasp of the basic chi-square procedure also provides the foundation for logistic regression, which models the relationship between a categorical response and one or more explanatory variables.

Practice Problems

1
A researcher collects a single random sample of 500 high-school students and records each student's grade level (9, 10, 11, 12) and preferred lunch option (hot meal, packed lunch, skip lunch). Which chi-square test is appropriate? (A) Goodness-of-fit test (B) Test for homogeneity (C) Test for independence (D) Two-sample z-test for proportions (E) Paired t-test
2
In a 3 × 4 two-way table with a grand total of 600, one cell has a row total of 200 and a column total of 150. The observed count for that cell is 60. What is that cell's contribution to the chi-square statistic? (A) 1.00 (B) 2.00 (C) 2.40 (D) 3.00 (E) 10.00
3
A chi-square test for homogeneity is performed on a 2 × 3 contingency table. The test statistic is χ² = 9.73 and α = 0.05. What conclusion should be drawn? (A) Fail to reject H₀ because 9.73 < 9.488 (B) Reject H₀ because 9.73 > 5.991 (C) Fail to reject H₀ because 9.73 < 12.592 (D) Reject H₀ because 9.73 > 7.815 (E) Reject H₀ because 9.73 > 3.841
PROBLEM 4APPLIED
A hospital randomly selects 300 patient records and classifies each by treatment group (Drug A, Drug B, Placebo) and outcome (Improved, No Change, Worsened). The observed and expected counts are shown below. | | Improved | No Change | Worsened | Row Total | |---|---|---|---|---| | Drug A | 55 | 30 | 15 | 100 | | Drug B | 48 | 35 | 17 | 100 | | Placebo | 27 | 45 | 28 | 100 | | Col Total | 130 | 110 | 60 | 300 | Carry out the full four-step chi-square test at α = 0.05. State hypotheses, verify conditions, calculate χ² and the P-value, and state a conclusion in context. Identify which cell contributes most to χ² and interpret its direction.
PROBLEM 5CRITICAL THINKING
A student performs a chi-square test for independence on a 2 × 2 table with n = 40 and obtains χ² = 4.82 with a P-value of 0.028. A classmate notes that a two-proportion z-test on the same data yields z = 2.196 and a two-sided P-value of 0.028. (a) Verify algebraically that z² = χ² in this setting. (b) Explain why the P-values are identical despite the tests using different reference distributions. (c) Discuss a scenario in which the chi-square test can address a question that the two-proportion z-test cannot, and explain why. (d) If the expected count in one cell were 3.5, explain which condition is violated and what alternative procedure you would recommend.
Varsity Tutors • AP Statistics • Carrying Out a Chi-Square Test for Homogeneity or Independence