
carry out chi-square tests of independence and homogeneity on two-way tables, compute expected counts, and connect the 2 × 2 case to the two-proportion z-test.
Instruction
In RLP Statistics A (G.CP.A.4) you judged independence in a two-way table by comparing conditional proportions. The chi-square test turns that judgment into a test.
Two versions, one computation. A test of independence takes one sample and classifies each case by two categorical variables: are the variables associated? A test of homogeneity takes separate samples from several groups: is the distribution of one categorical variable the same in every group? The arithmetic is identical. The design, and so the wording of the hypotheses, differs.
Expected counts. If the variables are independent, each cell’s expected count is
E = (row total × column total) / grand total
and df = (rows − 1)(columns − 1).
Example 1: the 2 × 2 persistence table. St. Louis winters (December-February) 2000-2024, NOAA daily data, with each day paired with the day before (2,256 pairs):
| Rain today | Dry today | Total | |
|---|---|---|---|
| Rain yesterday | 294 (E 210.4) | 394 (E 477.6) | 688 |
| Dry yesterday | 396 (E 479.6) | 1,172 (E 1,088.4) | 1,568 |
| Total | 690 | 1,566 | 2,256 |
For example, E for the first cell is 688 × 690/2,256 ≈ 210.4. Every cell is off by about 84 from its expectation, and χ2 = Σ(O − E)2/E ≈ 68.8 with df = 1. P is effectively zero. Rain today is strongly associated with rain yesterday.
The link to z. The two-proportion z-test in Lesson 3.4 gave z ≈ 8.29 for the same data, and 8.292 ≈ 68.8. For a 2 × 2 table, the chi-square test and the two-sided two-proportion z-test are the same test. The z-test can also be one-sided and gives a confidence interval for the difference, so it is usually more informative.
Example 2: a 3 × 2 table with a dose-response pattern. Split “rain yesterday” by amount:
| Yesterday | Rain today | Dry today | P(rain today) |
|---|---|---|---|
| Dry | 396 | 1,172 | 0.253 |
| Light (0.01-0.24 in) | 174 | 284 | 0.380 |
| Heavy (0.25 in or more) | 120 | 110 | 0.522 |
χ2 ≈ 83.3, df = (3 − 1)(2 − 1) = 2, P far below 0.001. The conditional proportions tell the story the P-value cannot: the more it rained yesterday, the more likely rain is today. A dose-response pattern like this is one of the signs, discussed in RLP Statistics A, that an association may reflect a real mechanism. Here the mechanism is storm systems that last for days.
Conditions. Random sampling or independent observations, and all expected counts at least 5 (all are here: the smallest is 70.3). As before, consecutive days are not independent draws, which makes the P-value too small. With effects this large, the conclusion stands, but a report should say so.
After a significant result, report the conditional proportions (A1.DS.A.4 / A1.DS.A.4a / A1.DS.A.4b) and the largest contributions to χ2. “Associated” is the conclusion. The proportions show the direction and size.
Tools. Spreadsheet: build the expected table with formulas, then =CHISQ.TEST(observed, expected) for the P-value. CODAP: put one variable on each axis of a graph to see the two-way table. Python (optional): scipy.stats.chi2_contingency in JupyterLite.
📖 Read for this lesson
The reading opens over the lesson; close it to come back to exactly where you were. The checks below draw on it.
Formative check
Work through these before moving on. They are not graded — they tell you whether the standard below has landed yet.
The expected count for ‘rain yesterday, rain today’ is 688 × 690 / 2,256 ≈ ; the 3 × 2 table has df = .
For the 2 × 2 persistence table, χ² ≈ 68.8 and the two-proportion z ≈ 8.29. How are they related?
Simulation & tools
Build the persistence table from raw daily data
Data: NOAA NCEI GHCN-Daily, St. Louis Lambert International Airport (USW00013994), 2000-2024 (import URL from Unit 1). In CODAP or a spreadsheet:
- Add rain = PRCP ≥ 0.01 and rain_yesterday (in a spreadsheet, the previous row’s rain; in CODAP,
prev(rain)). Add month and keep December-February. - Make a graph with rain_yesterday on one axis and rain on the other to get the two-way counts. Check them against 294, 394, 396 and 1,172.
- Compute expected counts and χ2 in a spreadsheet, and the P-value with CHISQ.TEST.
- Repeat with heavy = PRCP ≥ 1.5 for all months. Is heavy rain also persistent? Check the expected counts condition first. Heavy rain is rare, even in St. Louis.
Choose one route. All three earn full credit and all three end in the same two chi-square tests.
- Route 1 — build the tables from the raw data, as steps 1-4 describe.
- Route 2 — work from the tables printed in this lesson. No internet needed. Compute all four expected counts, the four contributions, χ2 and df by hand for the 2 × 2 winter table, then all six for the 3 × 2 table. You should recover χ2 ≈ 68.8 on 1 df and χ2 ≈ 83.3 on 2 df.
- Route 3 — work from the printed heavy-rain table below, a real table built from the same NOAA file (each day from January 2, 2000 to December 31, 2024 paired with the day before, a “heavy” day being 1.5 inches or more of rain). It is here so that step 4’s question can be answered without a download, and so that you meet a table where the conditions fail.
Check your work: the expected count in the top-left cell is 125 × 125/9,131 ≈ 1.71, far below 5, so the expected-counts condition fails and no P-value from this table can be trusted. Report that as your answer. If you compute the statistic anyway you will get χ2 ≈ 76.6 on 1 df, almost all of it (74.5) from that one tiny-expectation cell, which is exactly the way the test misbehaves when a cell is nearly empty. The conditional proportions are still worth reporting: 13/125 ≈ 0.104 after a heavy day against 112/9,006 ≈ 0.0124 after any other day.All-year pairs Heavy today Not heavy today Total Heavy yesterday 13 112 125 Not heavy yesterday 112 8,894 9,006 Total 125 9,006 9,131
Open in a new tab ↗ · CODAP, Concord Consortium · MIT open source
For the 3 × 2 table, compute all six expected counts and contributions, confirm χ² ≈ 83.3, and identify the two largest contributions. Then write a four-sentence conclusion that reports the conditional proportions, names the dose-response pattern, and states one reason the P-value is too small to take literally.
How confident are you that you can carry out and interpret chi-square tests on two-way tables and connect them to two-proportion tests?
Practice
Work these on paper or in your notebook, then open Check your answer. Aim for all of Fluency and Application; try at least one Challenge.
Printable version: this unit’s practice workbook (PDF)
Fluency
Build speed and accuracy with the core skill.
- A table has 3 rows and 4 columns. What are the df for a chi-square test of independence?
Check your answer
Answer: 6.(3 − 1)(4 − 1). - Row total 688, column total 690, grand total 2,256. Find the expected count.
Check your answer
Answer: ≈ 210.4. - Independence or homogeneity? One random sample of students is classified by grade and by preferred study time.
Check your answer
Answer: Independence. - Independence or homogeneity? Separate random samples from three high schools are asked the same yes/no question.
Check your answer
Answer: Homogeneity. - For a 2 × 2 table, how is χ² related to the two-proportion z statistic?
Check your answer
Answer: χ² = z².
Application
Use the skill in context. Show your reasoning.
- Springfield winter persistence table (2000-2024): rain-rain 234, rain-dry 350, dry-rain 353, dry-dry 1,319. Carry out the chi-square test of independence, with the expected counts.
Check your answer
Answer: Expected: 152.0, 432.0, 435.0, 1,237.0; χ² ≈ 80.8, df = 1, P far below 0.001. Rain today is strongly associated with rain yesterday at Springfield, as at St. Louis. - Springfield winter days by yesterday’s rain (dry / light 0.01-0.24 in / heavy ≥ 0.25 in) and today’s (rain / dry): dry 353, 1,319; light 126, 241; heavy 108, 109. Test for association and describe the pattern with conditional proportions.
Check your answer
Answer: χ² ≈ 97.7, df = 2, P far below 0.001. P(rain today) ≈ 0.211 after a dry day, 0.343 after a light-rain day and 0.498 after a heavy-rain day: a dose-response pattern. - Kansas City, July-August 2000-2024: 90°F or above yesterday & today 466; yesterday, not today 182; not yesterday, 90°F or above today 179; neither 723. Test whether hot days are independent of the previous day, and explain what this means for any binomial model of hot days.
Check your answer
Answer: χ² ≈ 420.8, df = 1, P far below 0.001. P(90°F or above | 90°F or above yesterday) ≈ 0.719 against 0.198 after a cooler day. Hot days are strongly dependent, so a binomial model that assumes independent days will understate how often hot spells and cool spells occur. - Rainy days by season, 2000-2024 (Dec-Feb, Mar-May, Jun-Aug, Sep-Nov): St. Louis 690, 866, 691, 599; Springfield 587, 838, 674, 590. Test whether the two stations have the same seasonal distribution of rainy days.
Check your answer
Answer: χ² ≈ 4.60, df = 3, P ≈ 0.204. Proportions in each season: St. Louis 0.242, 0.304, 0.243, 0.210; Springfield 0.218, 0.312, 0.251, 0.219. No convincing difference in the seasonal pattern.Test of homogeneity on counts of rainy days (the days are not independent, so treat the P-value as approximate).
Challenge
Stretch problems. Expect to think before you write.
- A student converts a two-way table of counts to percentages before computing χ². What goes wrong, and why?
Check your answer
Answer: χ² depends on the sample size: (O − E)²/E scales with the counts. Using percentages (as if n were 100) gives the wrong statistic, usually far too small for large samples or too large for small ones.
Review
Keep earlier skills sharp.
- (Unit 3) Two-proportion z-test: 294/688 against 396/1,568. Find the pooled proportion.
Check your answer
Answer: 0.3059. - (RLP Statistics A) From a two-way table, how do you check independence?
Check your answer
Answer: Compare a conditional proportion with the overall proportion (or P(A and B) with P(A)P(B)).
A Two-by-Two from a Randomized Trial, and a Two-by-Two That Fails Its Conditions
1954 poliomyelitis vaccine field trial, paralytic-case counts as reported by Francis et al., American Journal of Public Health 45 (1955), supplement; NOAA NCEI GHCN-Daily, station USW00013994 (St. Louis Lambert International Airport), PRCP, 2000-2024; retrieved 2026-11-10 · SLS original, with published trial figures and public domain NOAA data
Why this reading. The lesson’s two tables are printed and its open question can be answered from them. What the lesson lacks is a two-way table from a designed study, so that the difference between a test of independence and a test of homogeneity is a difference you have met in data rather than in a definition. The 1954 polio vaccine trial is that table, and it is the same 2 × 2 the two-proportion z-test handles, so the χ2 = z2 identity can be checked on it. Then the real St. Louis table of heavy-rain days that the lesson’s Route 3 works from, with its failing expected count worked in full.
Table 1. The 1954 poliomyelitis vaccine field trial, randomized arm
In 1954, in parts of the United States where health authorities agreed to it, children in grades 1 to 3 whose parents consented were assigned at random to receive Salk vaccine or a saline placebo, with neither families nor diagnosing physicians told which. Cases were counted through the polio season. The figures below are the paralytic-polio counts as reported by Thomas Francis Jr. and colleagues in their 1955 evaluation; they are the figures reproduced in this course’s Algebra 2B reading on study design.
| Randomized, placebo-controlled arm | Paralytic polio | No paralytic polio | Total | Rate per 100,000 |
|---|---|---|---|---|
| Vaccinated | 33 | 200,712 | 200,745 | 16.4 |
| Placebo | 115 | 201,114 | 201,229 | 57.1 |
| Total | 148 | 401,826 | 401,974 | 36.8 |
This is a test of homogeneity: two groups formed by the design, one categorical response, and the question is whether the distribution of that response is the same in both. H0: the proportion developing paralytic polio is the same for vaccinated and placebo children. Expected counts, E = row total × column total / grand total:
| Expected under H0 | Paralytic polio | No paralytic polio |
|---|---|---|
| Vaccinated | 73.91 | 200,671.09 |
| Placebo | 74.09 | 201,154.91 |
Every expected count is above 5, and random assignment gives independence within the design. Contributions:
| Contribution (O − E)2/E | Paralytic polio | No paralytic polio |
|---|---|---|
| Vaccinated | 22.64 | 0.0083 |
| Placebo | 22.59 | 0.0083 |
χ2 = 45.25, df = 1. Table 3 of the critical-values reading gives 10.83 at the 0.001 tail; P is about 2e-11. Notice where the statistic lives: almost all of it in the two small cells. The two huge “no polio” cells contribute 0.0167 between them, because a discrepancy of 41 against an expectation of 200,000 is nothing. The two-proportion z: pooled p̂ = 148/401,974 = 0.000368; z = (0.000164 − 0.000571)/√(0.000368(1 − 0.000368)(1/200,745 + 1/201,229)) = -6.73, and -6.732 = 45.25. Same test.
The conclusion and its scope. Because assignment was random, the association is causal: the vaccine reduced paralytic polio in these children, by 1 − 16.4/57.1 = 71%, with the effect size stated as the rate ratio or as the difference of 40.7 cases per 100,000. The trial did not randomly select children from the country, so generalizing to all children was an argument about similarity, and it was made: the vaccine was licensed the day the results were announced. Compare the observed-control arm of the same trial (vaccinated second-graders against unvaccinated first- and third-graders, 38 of 221,998 against 330 of 725,173, χ2 = 35.3), where the same arithmetic runs on groups nobody assigned, and the conclusion has to stop at “associated”.
Table 2. The real St. Louis heavy-rain persistence table
The lesson’s Route 3 prints this table. It is a real one, built from the same NOAA file as the winter table (St. Louis Lambert International Airport, GHCN-Daily PRCP): each day from January 2, 2000 to December 31, 2024 paired with the day before it, with a “heavy” day defined as 1.5 inches or more of rain. Heavy days are rare (125 of 9,131), which is what breaks the conditions. Retrieved 2026-11-10.
| All-year pairs, 2000–2024 | Heavy rain today | Not heavy today | Total | P(heavy today) |
|---|---|---|---|---|
| Heavy rain yesterday | 13 | 112 | 125 | 0.104 |
| Not heavy yesterday | 112 | 8894 | 9006 | 0.0124 |
| Total | 125 | 9006 | 9131 | 0.0137 |
Expected count for the heavy–heavy cell: 125 × 125/9,131 = 1.71. The condition fails: an expected count of 1.71 is below 5, and no P-value from this table is trustworthy. Computed anyway, χ2 = 76.6 on 1 df, 74.5 of it from that one cell. The conditional proportions remain worth reporting and are the honest result: heavy rain followed heavy rain on 13 of 125 occasions (0.104) and followed a day that was not heavy on 112 of 9,006 (0.0124), about 8 times as often. A 2 × 2 table with a rare event needs either more data or a different procedure (an exact test), and the right report says so.
Independence or homogeneity?
| Table | How the data arose | Which test | H0 in words |
|---|---|---|---|
| Winter persistence (lesson) | One record; every day classified by yesterday’s rain and today’s | Independence | Today’s rain is independent of yesterday’s |
| Polio trial | Two groups created by random assignment; response recorded in each | Homogeneity | The polio rate is the same in both treatment groups |
| Heavy-rain persistence | One record, two classifications | Independence (conditions fail) | Today’s rain is independent of yesterday’s |
The arithmetic is identical; the wording of the hypotheses and, above all, the scope of the conclusion are not. Random assignment is what turns “associated” into “caused”, and no chi-square statistic, however large, does that on its own.
Sources: NOAA NCEI, Daily Summaries (GHCN-Daily) data search (ncei.noaa.gov); NOAA NCEI Access Data Service (the query used here) (ncei.noaa.gov); University of Michigan School of Public Health, the 1955 polio vaccine trial announcement (sph.umich.edu)