The same chi-square statistic as a goodness-of-fit test, with the expected counts built from the data's own margins rather than supplied by an outside claim. A test of independence uses a contingency table and asks whether two factors are related. The expected count in each cell is its row total times its column total divided by the grand total — a formula the book derives directly from chapter 3's definition of independence, since assuming the two factors are unrelated means each cell's probability is the product of its marginal probabilities. The degrees of freedom are rows minus one times columns minus one, which counts the cells still free once every margin is fixed, and the test is always right-tailed. Worked through the book's cell-phone and volunteer examples.
Subject: Statistics · 65 slides · symbolic lesson
Open the interactive version of this deck
Title
Statistics · Chapter 11 — The Chi-Square Distribution
Test of Independence
Objectives
Six outcomes, and the first one explains all the others.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-577 — the section these objectives are drawn from
Warm-up
Section 3.2 defined independent events; section 11.2 gave a statistic for comparing counts against expectations.
Discussion prompt
Of 755 drivers surveyed, 70 received a speeding violation and 305 used a cell phone while driving. If those two things were independent, how many drivers would you expect to have done both?
Hint: Independence means the probability of both is the product of the two probabilities.
Answer:
The probability of a violation is 70 out of 755 and the probability of cell phone use is 305 out of 755. If the events are independent, the probability of both is the product of those, and the expected COUNT is that probability times 755.
\[ E = 755 \cdot \frac{70}{755} \cdot \frac{305}{755} = \frac{70 \cdot 305}{755} = 28.28 \]
About 28 drivers. One of the 755 factors cancels, leaving a row total times a column total over the grand total — which is exactly the formula this section is about to state. The whole of the new machinery is chapter 3's definition of independence with the arithmetic tidied up.
Concept
A test of independence determines whether two factors are independent or not, using a contingency table of observed values. The expected count in each cell is its row total times its column total divided by the total number surveyed, and the degrees of freedom are the number of columns minus one times the number of rows minus one.
a test of independence — A chi-square test on a contingency table, asking whether two factors are related. The null is that they are independent; the alternative is that they are dependent.
\[ E = \frac{(\text{row total})(\text{column total})}{\text{total surveyed}}, \qquad \text{df} = (r-1)(c-1) \]
The book notes that the test statistic is similar to that of a goodness-of-fit test — in fact it is identical, summing squared differences over expected counts across every cell. What changed is only where the expected values come from. In section 11.2 an outside claim supplied them; here they are computed from the table's own margins under the assumption of independence.
Figure (svg): A card deriving the expected-count formula from the definition of independence
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-575
Section
Section 1
Concept
Suppose A is a speeding violation in the last year and B is cell phone use while driving. If A and B are independent then the probability of both is the product of the two probabilities. Writing each as a proportion of those surveyed and solving gives the expected count.
the expected table — What the same data would look like if the two factors were unrelated. It has the same row totals, the same column totals and the same grand total as the observed table — only the interior is redistributed.
\[ \frac{y}{755} = \frac{70}{755} \cdot \frac{305}{755} \;\Longrightarrow\; y = \frac{(70)(305)}{755} \approx 28.28 \]
The cancellation is worth watching. Both sides are divided by 755, and the right side has two factors of 755 in its denominator, so one survives — which is why the formula divides a product of two totals by the grand total exactly once rather than twice. Getting that wrong is the most common error in building an expected table, and it shows up immediately because the expected counts then fail to sum to n.
Figure (svg): A card deriving the expected-count formula from the definition of independence
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Example 11.5, and the formula for E
Picture it
From chapter 3's definition to the formula the section uses.
Figure (svg): A card deriving the expected-count formula from the definition of independence
Nothing here is new machinery. The formula is a restatement of what independence means, applied to a table, which is why the expected counts are exactly the right thing to compare the data against — they are the null hypothesis made numerical.
Worked example
Of 755 drivers, 70 had a speeding violation and 305 used a cell phone while driving.
\[ n = 755, \; 70 \text{ violations}, \; 305 \text{ cell users} \]
Write independence
Why: Probability of both.
Substitute proportions
Why: Out of 755 each.
\[ \frac{y}{755} = (\frac{70}{755}) (\frac{305}{755}) \]
Multiply through by 755
Why: One factor cancels.
\[ y = (70) (305) / 755 \]
Evaluate
Why: 21,350 over 755.
\[ 28.28 \]
Figure (svg): The solution to Worked example Example 11.5, cell phones and violations shown as a ladder of expressions, one row per legal move
\[ y = \frac{(70)(305)}{755} \approx 28 \]
Verify: confirm the answer is plausible against the margins
Why: Cell phone users are 305 of 755, about 40 percent of the sample, so if violations were spread without regard to phone use, about 40 percent of the 70 violations — around 28 — should fall among them. That reasoning gives the same answer by a different route and is a fast check on any expected count: it should be the row total's share of the column total, or equivalently the column's share of the row.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575
Faded example
Four-year college students volunteering 1 to 3 hours: row 290, column 298, total 839.
Fill in the blanks
E = \frac298})}103 = ___
Why: That is the book's own 103.00. Expected counts are usually not whole numbers; this one is very nearly exact by coincidence.
Worked example
The top-left cell of the volunteer table: community college students volunteering 1 to 3 hours.
\[ \text{row } 255, \; \text{column } 298, \; n = 839 \]
Identify the margins
Why: That cell's row and column.
\[ 255\text{ and } 298 \]
Multiply them
Why: The product.
\[ 75, 990 \]
Divide by the total
Why: Over 839.
\[ 90.57 \]
Compare with observed
Why: 111 were seen.
\[ 20\text{ above expectation} \]
Figure (svg): The solution to Worked example one cell of Example 11.6 shown as a ladder of expressions, one row per legal move
\[ E = \frac{(255)(298)}{839} = 90.57 \]
Verify: confirm the expected table reproduces the observed margins
Why: The first row of the expected table is 90.57, 115.19 and 49.24, which total 255 — exactly the observed row total. That must happen for every row and column, since each expected count is its row total times the column's share of the grand total, and the column shares sum to one. If a row of the expected table misses its observed total, the arithmetic went wrong.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576
Trap
\[ E = \frac{255}{839} \cdot \frac{298}{839} = 0.108 \]
Multiply the two marginal proportions
Why: That is the probability of the cell, not its count.
\[ 0.108 \text{ is a probability, not a number of volunteers} \]
A count is wanted, so the probability still has to be multiplied by the 839 people.
\[ E = 839 \cdot \frac{255}{839} \cdot \frac{298}{839} = \frac{(255)(298)}{839} = 90.57 \]
Multiply the probability by n, which cancels one denominator
Why: That is why the formula divides by the total only once.
The error is easy to spot because the numbers come out absurd: expected counts around 0.1 when hundreds of people were surveyed. Summing the expected table and checking it reaches n catches it immediately, which is why that check is worth doing every time.
Two truths and a lie
All three concern expected counts.
Eliminate the wrong options
Two are true. Knock those out and keep the false one.
Survives elimination: B
Why: The survivor is false and is the difference from section 11.2. Nothing outside the data supplies the expectations here — they are built entirely from the table's own row and column totals under the assumption of independence.
Prediction
Commit before reasoning.
Predict first
What does an expected contingency table describe?
Correct: The same people, redistributed under independence.
Why: The grand total and both sets of margins are unchanged; only the interior moves. That is what makes the comparison fair — the two tables describe identical marginal facts and differ only in whether the factors are related, which is exactly the question being asked.
Estimation
In a table of 400 people, a row totals 100 and a column totals 80.
Predict first
What is that cell's expected count?
Correct: 20.
Why: One hundred times eighty over four hundred is 20. The shortcut reading is that the row holds a quarter of everyone, so under independence it should hold a quarter of the column's 80 — which is 20 again, and is worth using as a mental check.
Section
Section 2
Concept
The number of degrees of freedom for a test of independence is the number of columns minus one times the number of rows minus one. It counts the cells that remain free once every row and column total is fixed.
free cells — In a table with fixed margins, choosing values for a block of rows minus one by columns minus one determines every remaining entry by subtraction.
\[ \text{df} = (r-1)(c-1) \]
The book poses its own version of the question: if the volunteer example had included a fourth type of volunteer, teenagers, what would the degrees of freedom be? Four rows and three columns give three times two, which is six. Adding a row adds two degrees of freedom rather than one, because each new row contributes as many free cells as there are columns minus one.
Figure (svg): A three-by-three grid with a two-by-two block shaded to show which cells are free once the margins are fixed
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 575-577 — the df formula, and the teenagers question
Picture it
A three-by-three table with its margins fixed.
Figure (svg): A three-by-three grid with a two-by-two block shaded to show which cells are free once the margins are fixed
Fill the shaded two-by-two block with any values at all and the remaining five cells follow by subtraction from the margins. Four numbers are genuinely free, which is what four degrees of freedom means — and it is a product because the freedom is two-dimensional.
Worked example
Three volunteer types by three hour bands.
\[ 3 \times 3 \]
Rows minus one
Why: Three types.
\[ 2 \]
Columns minus one
Why: Three bands.
\[ 2 \]
Multiply
Why: Two by two.
\[ 4 \]
Sanity check
Why: Nine cells, five determined.
\[ 4\text{ free} \]
Figure (svg): The solution to Worked example Example 11.6's degrees of freedom shown as a ladder of expressions, one row per legal move
\[ \text{df} = (3-1)(3-1) = 4 \]
Verify: confirm by counting the constraints rather than the free cells
Why: Nine cells, minus three row totals and three column totals, would suggest three — but the six margins are not independent constraints, since both sets sum to the same grand total. That double-count means only five constraints bind, leaving nine minus five, which is four. Both routes agree, and the product formula is simply the tidier one.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576
Faded example
Five rows by four columns.
Fill in the blanks
\text4 = (3)(___) = 12
Why: Four times three is twelve. Twenty cells, with eight determined by the margins once the other twelve are chosen.
Worked example
If a fourth type of volunteer were added to the same three hour bands.
\[ 4 \times 3 \]
Rows minus one
Why: Four types now.
\[ 3 \]
Columns minus one
Why: Still three bands.
\[ 2 \]
Multiply
Why: Three by two.
\[ 6 \]
Note the change
Why: Up from four.
Figure (svg): The solution to Worked example the book's teenagers question shown as a ladder of expressions, one row per legal move
\[ \text{df} = (4-1)(3-1) = 6 \]
Verify: confirm why a single new row adds two
Why: Each new row has three cells, and two of them are free once the third is forced by that row's own total. So every additional row contributes columns minus one new degrees of freedom. The same holds in the other direction: a fourth hour band would add three, one for each row beyond the last. This is what makes the count a product rather than a sum.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 577
Error analysis
The table holds 500 observations. Which count is right?
Annotate
On: \( \begin{aligned} &(1)\; (3-1)(4-1) = 6 \\ &(2)\; 12 - 1 = 11 \\ &(3)\; 500 - 1 = 499 \\ &(4)\; (3-1) + (4-1) = 5 \end{aligned} \)
Error (2) is the most tempting, since section 11.2 has just spent a whole lesson on cells minus one. The difference is that a goodness-of-fit table has one constraint — the total — while a contingency table has a whole set of row and column constraints.
Sorting
Each describes a chi-square test met so far.
Sort into buckets
Sort by which degrees-of-freedom rule is used.
The signal is whether the expected counts come from outside the data or from the table's own margins. If a distribution is quoted, it is goodness of fit; if a two-way table is given, it is a contingency test.
Two truths and a lie
All three concern the count.
Eliminate the wrong options
Two are true. Knock those out and keep the false one.
Survives elimination: B
Why: The survivor is false. A goodness-of-fit table has one constraint, so cells minus one is right there. A contingency table has a whole set of row and column constraints, and the count that survives them is a product.
Prediction
Commit before reasoning.
Predict first
Why do the degrees of freedom multiply rather than add?
Correct: The freedom is two-dimensional.
Why: Once the margins are fixed, the block of cells that can still vary is itself a rectangle — rows minus one tall and columns minus one wide. Counting its cells means multiplying its two dimensions, which is why the formula is a product and why adding a row adds several degrees of freedom rather than one.
Section
Section 3
Concept
The test of independence is always right-tailed because of the calculation of the test statistic. If the expected and observed values are not close together, the statistic is very large and way out in the right tail of the chi-square curve, as in a goodness-of-fit test. Every expected value must be at least five.
the hypotheses in words — The null states the two factors are independent; the alternative states they are dependent. As in section 11.2 there is no parameter, so the book states them in sentences.
\[ H_0: \text{independent} \quad\text{against}\quad H_a: \text{dependent} \]
The alternative is worth reading carefully: dependent, not dependent in some particular direction. A contingency test detects any departure from independence — one cell running high, another low, or a pattern spread across the table — and reports none of those specifics. Identifying which cells drive a rejection is a separate descriptive step.
Figure (svg): A chi-square curve on four degrees of freedom with a thin right tail beyond 12.99 shaded
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-577 — the hypotheses, the right tail, and the condition
Picture it
The book's Figure 11.7.
Figure (svg): A chi-square curve on four degrees of freedom with a thin right tail beyond 12.99 shaded
The statistic of 12.99 sits more than three times its mean of 4, so the shaded tail is thin at 0.0113. With no alpha given the book assumes 5 percent, and the test rejects.
Worked example
Volunteer hours by volunteer type, 839 adults.
\[ \alpha = 0.05 \]
Hypotheses
Why: In words.
Expected table
Why: Margins over 839.
\[ 90.57\text{ to } 56.77 \]
Check the condition
Why: Smallest expected.
\[ 49.24,\text{ well above } 5 \]
Statistic
Why: Summed over nine cells.
\[ 12.99 \]
Degrees of freedom, then the tail
Why: Two by two.
\[ d f 4, p = 0.0113 \]
Figure (svg): The solution to Worked example Example 11.6 in full shown as a ladder of expressions, one row per legal move
\[ \chi^2 = 12.99, \quad \text{df} = 4, \quad p = 0.0113 < 0.05 \]
Verify: confirm the direction of the largest departures
Why: Community college students volunteered 1 to 3 hours far more than expected — 111 against 90.57 — while nonstudents did so far less, at 91 against 104.42, and put more time into the 4-to-6 band. So the dependence is a real pattern rather than noise in a single cell, and describing it that way is what makes the rejection useful. The test itself says only that the factors are related.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 576-577
Matching
Match each stage of Example 11.6 to what it holds.
Match the pairs
Why: The sequence matches section 11.2's exactly. Only the second row differs in kind — expected counts from the margins rather than from a quoted distribution.
Worked example
The smallest expected count in Example 11.6.
\[ \text{min } E \]
Scan the expected table
Why: Nine values.
\[ 49.24\text{ is smallest} \]
Compare with five
Why: Far above.
Note where small cells arise
Why: Small margins.
Conclude
Why: Proceed.
Figure (svg): The solution to Worked example checking the condition shown as a ladder of expressions, one row per legal move
\[ \min E = 49.24 \ge 5 \]
Verify: confirm which cell would be at risk in a general table
Why: The smallest expected count always sits where the smallest row total meets the smallest column total, since each expected value is proportional to both margins. Checking that one cell is enough to check the whole table — here 255 times 162 over 839, which is 49.24 — and it makes the condition a single calculation rather than nine.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-576
Trap
\[ p = 0.0113 \;\Rightarrow\; \text{being a community college student CAUSES fewer volunteer hours} \]
Turn a dependence into a cause
Why: The two factors are clearly related.
\[ \text{but the alternative says only 'dependent'} \]
Dependence is a statement about the joint distribution, not about what produces what.
\[ \text{hours volunteered and volunteer type are dependent} \]
Report the association, and describe the pattern separately
Why: Causal direction is not something this test addresses.
Section 1.2's distinction between observational studies and experiments applies directly. These volunteers were observed, not assigned, so any number of other factors — course loads, work schedules, age — could produce the association. The test establishes that the two vary together, and nothing more.
Faded example
Example 11.6, with no alpha given.
Fill in the blanks
p = 0.0113, \quad \alpha = 0.05: \quad reject H_0
Why: The book says that since no alpha is given, assume 0.05 — and 0.0113 is below it, so reject. At 1 percent the same data would not reject, which is why stating alpha in advance matters.
Two truths and a lie
All three concern running the test.
Eliminate the wrong options
Two are true. Knock those out and keep the false one.
Survives elimination: B
Why: The survivor is false. The alternative hypothesis says the factors are dependent, which is a statement about how they vary together. With observational data, association never establishes direction or cause.
Prediction
Commit before reasoning.
Predict first
In any contingency table, which cell has the smallest expected count?
Correct: Where the smallest row meets the smallest column.
Why: Each expected count is proportional to both its margins, so the product is smallest where both are. That makes the condition a one-cell check rather than a scan of the whole table, and it identifies in advance which category might need merging if the sample is thin.
Section
Section 4
Concept
The test delivers one verdict on the whole table. Comparing observed against expected cell by cell shows where the dependence lies, and each cell's contribution to the statistic measures how much it mattered.
a cell's contribution — Its own term, observed minus expected squared over expected. Contributions sum to the statistic, so the largest ones identify where the table departs most from independence.
\[ \frac{(O-E)^2}{E} \quad \text{per cell, summing to } \chi^2 \]
This is description rather than inference. No p-value attaches to a single cell, and examining nine cells after the fact raises exactly the multiple-comparison concern that motivated a single omnibus test in the first place. The honest report gives the test's verdict, then describes the pattern as a description of these data.
Figure (svg): The expected contingency table computed from the row and column totals
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 576-577 — the observed and expected tables
Picture it
What 839 volunteers would look like if hours and type were unrelated.
Figure (svg): The expected contingency table computed from the row and column totals
Comparing against the observed table shows community college students over-represented in the shortest band and nonstudents in the middle one. Both departures are around 20 people, which on expectations near 100 is enough to reject.
Worked example
Comparing Example 11.6's observed and expected tables.
\[ O \text{ against } E \]
Community college, 1-3 hours
Why: 111 against 90.57.
\[ 20.4\text{ above} \]
Its contribution
Why: Squared, over 90.57.
\[ 4.61 \]
Nonstudents, 1-3 hours
Why: 91 against 104.42.
\[ 13.4\text{ below} \]
Its contribution
Why: Squared, over 104.42.
\[ 1.73 \]
Figure (svg): The solution to Worked example the two largest departures shown as a ladder of expressions, one row per legal move
\[ \frac{(111-90.57)^2}{90.57} = 4.61 \quad\text{and}\quad \frac{(91-104.42)^2}{104.42} = 1.73 \]
Verify: confirm these are a substantial share of the total
Why: Together they contribute 6.34 of the statistic's 12.99, so nearly half the evidence comes from the 1-to-3-hour column alone. That is a meaningful description of the pattern — the groups differ most in whether they volunteer only briefly — but it is a description of these 839 people rather than a separately tested claim.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576
Faded example
Four-year college students, 4 to 6 hours: 133 observed against 131.00 expected.
Fill in the blanks
\frac40.031 = \frac___}___ = ___
Why: A negligible contribution: this cell sits almost exactly where independence predicts. Scanning contributions separates the cells carrying the evidence from those that are simply along for the ride.
Worked example
Summing a row of the expected table.
\[ 90.57 + 115.19 + 49.24 \]
Add the three
Why: The first row.
\[ 255.00 \]
Compare with observed
Why: The same row.
\[ 255 \]
Say why
Why: Each is 255 times a column share.
Note the use
Why: A check.
Figure (svg): The solution to Worked example why the margins must match shown as a ladder of expressions, one row per legal move
\[ 255\left(\frac{298 + 379 + 162}{839}\right) = 255 \]
Verify: confirm the check works in the other direction too
Why: The first column of the expected table is 90.57, 103.00 and 104.42, totalling 297.99 — the observed 298 up to rounding. Every row and every column must reproduce its observed margin, which gives six independent checks on a three-by-three table. Any single arithmetic slip breaks at least two of them.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576
Error analysis
The p-value was 0.0113. Which statements are defensible?
Annotate
On: \( \begin{aligned} &(1)\; \text{hours volunteered and volunteer type are dependent} \\ &(2)\; \text{community college students volunteer fewer hours} \\ &(3)\; \text{being a student causes shorter volunteering} \\ &(4)\; \text{the largest departure was in the 1-to-3-hour column} \end{aligned} \)
The line to hold is between (1), which the test establishes, and (2) and (4), which describe the data that produced it. Both belong in a report, clearly labelled as different kinds of statement.
Two truths and a lie
All three concern reading the table.
Eliminate the wrong options
Two are true. Knock those out and keep the false one.
Survives elimination: B
Why: The survivor is false. One test gives one p-value for the whole table. Attaching p-values to individual cells after seeing which look extreme is the multiple-comparison problem that an omnibus test was chosen to avoid.
Prediction
Commit before reasoning.
Predict first
A cell contributes 0.03 to a statistic of 12.99. What does that say?
Correct: It sits almost exactly where independence predicts.
Why: A tiny contribution means observed and expected nearly coincide there. It says nothing about the cell's size — this one holds 133 people, the second largest count in the table — only that its count is what the margins alone would predict.
Explain it
A classmate concludes from Example 11.6 that going to community college makes people volunteer for shorter periods.
Discussion prompt
In two sentences or fewer, explain what the test does and does not show.
Hint: Ask how the volunteers ended up in their groups.
Answer:
The test shows that hours volunteered and volunteer type are dependent — the two vary together in this sample — but nobody was assigned to a volunteer type, so the association could come from course loads, work schedules, age, or anything else that differs between the groups.
An observational study can establish that two factors are related; only an experiment with assignment can establish that one produces the other.
Section
Section 5
Concept
The two tests share a statistic and a right tail. They differ in where the expected counts come from and in how the degrees of freedom are counted — an outside claim and cells minus one for goodness of fit, the table's own margins and a product for independence.
telling them apart — Look at what is given. A quoted distribution or set of percentages means goodness of fit; a two-way table of counts means a contingency test.
\[ \text{gof}: E = np_i, \; \text{df} = k-1 \qquad \text{ind}: E = \tfrac{RC}{n}, \; \text{df} = (r-1)(c-1) \]
There is one more difference worth naming. A goodness-of-fit test can be wrong about the claimed distribution because the claim itself came from outside; a test of independence cannot, because its null is built from the data's own margins. That is why the expected table always reproduces the observed margins exactly, and why the only thing being tested is the interior pattern.
Figure (svg): The observed contingency table of volunteer hours by volunteer type, with row and column totals
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 574 — the statistic is similar to that of a goodness-of-fit test
Picture it
Example 11.6's data, with margins.
Figure (svg): The observed contingency table of volunteer hours by volunteer type, with row and column totals
The margins along the edge are the only quantities the expected table borrows. Everything inside is what the test examines, which is why a contingency test asks about the relationship between two factors rather than about either one on its own.
Worked example
Two problems, side by side.
\[ \text{which test applies?} \]
Streaming services
Why: A national distribution is quoted.
Its degrees of freedom
Why: Five cells minus one.
\[ 4 \]
Volunteer hours
Why: A two-way table of counts.
Its degrees of freedom
Why: Two by two.
\[ 4 \]
Figure (svg): The solution to Worked example identifying the test shown as a ladder of expressions, one row per legal move
\[ k - 1 = 4 \qquad\text{against}\qquad (r-1)(c-1) = 4 \]
Verify: confirm the coincidence is not a pattern
Why: Both happen to give 4 here, which makes the pair a useful reminder that agreeing answers do not mean the rules are interchangeable. A five-by-four contingency table gives twelve degrees of freedom while twenty categories in a goodness-of-fit test give nineteen — the rules diverge sharply as tables grow.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-576
Sorting
Each describes a situation.
Sort into buckets
Sort by which chi-square test applies.
The tell is whether a distribution is quoted. If percentages or proportions come from outside the data, it is goodness of fit; if only a two-way table is given, the expected counts must come from its margins.
Worked example
Listing the differences precisely.
\[ \text{gof against independence} \]
The statistic
Why: Same formula.
The tail
Why: Both right.
The condition
Why: Both at least five expected.
Expected counts and df
Why: Claim against margins.
Figure (svg): The solution to Worked example what changes and what does not shown as a ladder of expressions, one row per legal move
\[ E \text{ and df change}; \; \chi^2, \text{ tail, condition do not} \]
Verify: confirm this is why section 11.5 exists
Why: Because so little differs between the chapter's tests, telling them apart is a matter of reading the setup rather than the arithmetic. Section 11.5 is the book's own comparison of the three, and its distinguishing feature is the wording of the hypotheses rather than anything computational — which is exactly what this comparison predicts.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 574
Trap
\[ 9 \text{ cells} \;\Rightarrow\; \text{df} = 8 \]
Carry section 11.2's rule across
Why: Both tests sum over cells.
\[ \text{but six margins constrain the table, not one total} \]
A goodness-of-fit table is constrained only by its total; a contingency table is constrained by every row and column sum.
\[ \text{df} = (3-1)(3-1) = 4 \]
Count what the margins leave free
Why: A two-by-two block of cells.
With Example 11.6's statistic the error would give a p-value of 0.1124 rather than 0.0113 — a tenfold difference that reverses the decision at 5 percent. Degrees of freedom are not a formality here; they change the verdict.
Two truths and a lie
All three compare the two tests.
Eliminate the wrong options
Two are true. Knock those out and keep the false one.
Survives elimination: B
Why: The survivor is false, and it is the difference that changes answers. A contingency table's margins impose many constraints rather than one, leaving a product rather than a simple subtraction.
Estimation
Example 11.6's statistic of 12.99 gives p = 0.0113 on four degrees of freedom.
Predict first
Using eight degrees of freedom instead would give roughly what p-value?
Correct: About 0.11.
Why: Eight degrees of freedom put the curve's mean at 8, so 12.99 is much less extreme and the tail is nearly ten times larger. The decision flips from reject to do not reject at 5 percent, which is why the count is worth getting right rather than treating as a detail.
Prediction
Commit before reasoning.
Predict first
In a test of independence, what does the null hypothesis take from the observed table?
Correct: Both sets of margins and the grand total.
Why: The expected table is built entirely from the row totals, the column totals and n. That is what makes the test a test of the interior pattern only: the margins are taken as given, and the question is purely whether the cells fall where independence would put them.
Comparison
Fill the blanks. Only two rows differ.
Comparison matrix
| Goodness of fit | Independence | |
|---|---|---|
| Data given | one list of counts plus a claim | a two-way table |
| Expected counts | n times each claimed proportion | row times column over n |
| Degrees of freedom | cells minus one | rows minus one times columns minus one |
| Tail | right | right |
The last row's agreement is not a coincidence: both statistics square every departure, so in both cases only large values can indicate a problem. That is a property of the statistic rather than of either question.
Pattern
Six steps. Only steps two and four differ from section 11.2.
Check that each row and column of the expected table reproduces its observed margin before going further; that catches nearly every arithmetic error.
OpenStax Introductory Business Statistics 2e, §11.4 Test of Independence §11.4 Test of Independence
Check
Expected counts.
Check your understanding
In a table of 600 people, a row totals 150 and a column totals 200. What is that cell's expected count?
Answer: A
Why: One hundred fifty times two hundred over six hundred is 50. Equivalently the row is a quarter of everyone, so it should hold a quarter of the column's 200.
Check
Degrees of freedom.
Check your understanding
A contingency table has 4 rows and 6 columns. What are the degrees of freedom?
Answer: A
Why: Three times five is fifteen: the number of cells still free once every row and column total is fixed.
Check
Interpretation.
Check your understanding
A test of independence on observational data rejects at 5 percent. What may be concluded?
Answer: A
Why: The alternative hypothesis states dependence, and that is precisely what rejection supports.
Real world
A hospital cross-tabulates treatment received against recovery for 800 patients, finds a chi-square statistic of 21.4 on 2 degrees of freedom with a p-value below 0.0001, and reports that the newer treatment works better. A reviewer objects that the sickest patients were preferentially given the older treatment.
Discussion prompt
Assess the calculation and the reviewer's objection separately.
Hint: Ask what the margins were fixed by, and how patients reached their groups.
Answer:
The calculation is fine as far as it goes. Three treatment groups by two recovery outcomes gives two by one, which is 2 degrees of freedom, and a statistic of 21.4 against a mean of 2 sits far out in the tail — so the p-value is genuinely tiny and treatment and recovery are genuinely associated in these data.
\[ \text{df} = (3-1)(2-1) = 2, \qquad \chi^2 = 21.4 \gg \mu = 2 \]
The reviewer's objection is decisive against the causal claim, and no amount of statistical significance answers it. If sicker patients were steered toward the older treatment, then treatment group and prognosis are confounded from the start, and a test of independence cannot separate the treatment's effect from the sorting that produced the groups. The association is real; its explanation is not established.
This is section 1.2's distinction, arriving with real consequences. Assignment is what licenses causal language, and here assignment was by clinical judgement rather than at random — which is exactly the mechanism that creates the confounding. A randomised comparison would have made the groups comparable in prognosis by construction, and only then would the same statistic support the conclusion drawn.
What can be reported: recovery and treatment are dependent in this sample, with the pattern running in the newer treatment's favour, and the comparison is confounded by allocation. Whether the treatment helps needs either randomisation or an analysis that adjusts for severity — and the chi-square test, which uses only the two-way table, has no way to make that adjustment.
Commit first
Answer, then rate your confidence honestly.
Predict first
Why is a cell's expected count its row total times its column total divided by the grand total?
Correct: Because independence makes the joint probability a product, and a count is n times that.
\[ E = n \cdot \frac{R}{n} \cdot \frac{C}{n} = \frac{RC}{n} \]
Why: Example 11.5 does exactly this: it sets the cell's proportion equal to the product of the two marginal proportions, then multiplies by n. Two factors of n appear in the denominator and one in the numerator, so exactly one survives — which is why the grand total is divided out once. The formula is chapter 3's definition of independence turned into counts.
Explain it
They computed a 3 by 4 table's degrees of freedom as 11, using cells minus one.
Discussion prompt
In two sentences or fewer, correct them.
Hint: Ask how many totals the table has to reproduce.
Answer:
Cells minus one is right for a goodness-of-fit test, where the only constraint is the grand total — but a contingency table also has to reproduce every row and column total, which pins down far more of it.
What is left free is a two-by-three block, so the degrees of freedom are six rather than eleven.
Exit ticket
Name the weakest spot before you close the deck.
Predict first
Which of these would you least want handed to you cold?
Correct: Whichever you picked is tonight's ten minutes, and each has a one-line fix.
Why: For the first, set the cell proportion equal to the product of the marginals and multiply by n. For the second, row times column over n, then check every margin. For the third, fixed margins leave a smaller rectangle free. For the fourth, dependence, never causation. Do five problems of your chosen kind rather than twenty mixed ones.
Connect it up
Paper. Fifteen minutes.
Draw it
At the top, derive the expected-count formula in three lines: the definition of independence, the same statement with each probability written as a proportion of 755 using Example 11.5's numbers, and the solved result of 70 times 305 over 755 — then box the general form, row total times column total over grand total. In the middle, draw Example 11.6's observed three-by-three table with its margins of 255, 290, 294 down the side and 298, 379, 162 across the bottom, and beside it the expected table beginning 90.57, 115.19, 49.24. Show the arithmetic for the top-left cell explicitly and check that the first expected row sums to 255. Below, draw a three-by-three grid with the top-left two-by-two block shaded and the remaining cells marked forced, and write the degrees of freedom as two times two. At the bottom right, sketch a chi-square curve on four degrees of freedom with a line at 12.99 and a thin shaded right tail labelled 0.0113, and write the conclusion in words — hours volunteered and volunteer type are dependent, not that one causes the other.
Check your expected table by confirming every row and every column reproduces its observed margin; six independent checks on a three-by-three table means a single slip will break at least two of them. Check your shaded block by confirming that filling it with any four numbers determines the other five.
Recap
Six things, and the first one generates the rest.
| If you see | Then |
|---|---|
| A two-way table of counts | A test of independence, with expected counts from the margins |
| A quoted distribution | A goodness-of-fit test instead |
| An expected count needed | Row total times column total over the grand total |
| An expected table built | Check every row and column against its observed margin |
| Degrees of freedom needed | Rows minus one times columns minus one |
| A rejection | The factors are dependent; describe the cells separately |
| Observational data | No causal claim, whatever the p-value |
Section 11.4 tests for homogeneity, which uses the same table, the same expected counts, the same degrees of freedom and the same statistic. What differs is only the question being asked and how the hypotheses are worded — which is why section 11.5 exists to tell the three tests apart.
OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-577 — everything on these slides traces back here
Want this taught 1-on-1? Alexander tutors Statistics — $55/session, free consultation.