11.3 Test of Independence

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

What this lesson covers

The lesson, slide by slide

1. Test of Independence

Title

Statistics · Chapter 11 — The Chi-Square Distribution

Two factors, one table: are they related? Expected counts from the margins, df as a product, always the right tail

2. What this lesson gives you

Objectives

Section 11.2 compared one row of counts with a distribution someone claimed. This section asks a different question of a two-way table: are the two factors that classify it related, or independent? The statistic is the same sum you already know. What is new is where the expected counts come from, and how to count the degrees of freedom.

Marks in this section are lost in three places: an expected count divided by the grand total twice, degrees of freedom counted as cells minus one, and a conclusion that turns related into causes. Each has its own slide, and each has a one-line check that catches it.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-578 — the section this deck covers

3. Before anything new: independent events

Warm-up

Section 3.2 defined two events as independent when the chance of both is the product of their separate chances. Use that definition on a survey of drivers, before any chi-square appears.

Discussion prompt

Of 755 drivers, 70 had a speeding violation last year and 305 used a cell phone while driving. If the two were independent, what fraction of drivers would have done both, and how many drivers is that?

Notice what you did not need: any data on how many drivers actually did both. The expected count comes from the two totals alone. The test will compare it with what was observed, cell by cell, exactly as the goodness-of-fit test did.

Keep this pattern in mind for the rest of the lesson: two margins in, one expected count out. A test of independence repeats this calculation for every cell of a table, then measures how far the real counts sit from the expected ones, using the very statistic Section 11.2 built for goodness of fit.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §3.2 and §11.3, p. 575 — independent events, then Example 11.5

4. Where the expected counts come from

Section

Part 1

5. Two factors, one table

Concept

Example 11.6 classifies 839 adult volunteers in two ways at once: by type of volunteer and by the number of hours they volunteer each week. A table that counts people by two factors is a contingency table, and every person lands in exactly one cell.

type of volunteer1–3 hours4–6 hours7–9 hoursrow total
community college students1119648255
four-year college students9613361290
nonstudents9115053294
column total298379162839

The question the book asks is whether the number of hours volunteered is independent of the type of volunteer. In plain words: if you knew which group someone came from, would that change your guess about their hours?

The totals around the edge are the margins. The row totals say how many of each type were sampled; the column totals say how the hours were spread over everyone. The inside of the table is where any relationship would show.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Example 11.6, Table 11.15

6. What a relationship looks like in the table

Picture it

Raw counts are hard to compare because the three groups have different sizes. Turn each row into percentages of its own total, so that every volunteer type is drawn on the same hundred-percent bar.

Figure (svg): Three horizontal bars, each 100 percent wide, one per volunteer type, split into hours volunteered per week. Community college students: 43.5 percent 1 to 3 hours, 37.6 percent 4 to 6, 18.8 percent 7 to 9. Four-year college students: 33.1, 45.9 and 21.0 percent. Nonstudents: 31.0, 51.0 and 18.0 percent. A fourth bar for all 839 volunteers reads 35.5, 45.2 and 19.3 percent.

If hours did not depend on volunteer type, all three bars would split the way the yellow-labelled bar for everyone does. The community college bar leans to short hours and the nonstudent bar to medium hours.

Read across the bars. Among community college students, 43.5 percent volunteer only one to three hours, against 35.5 percent of everyone. Among nonstudents, 51.0 percent volunteer four to six hours, against 45.2 percent of everyone. The shapes differ from row to row.

Independence makes a sharp prediction about this picture: every row would have the same shape as the bar for everyone. The test asks whether the differences you can see here are bigger than random sampling of 839 people would produce by chance.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Table 11.15, as row percentages

7. Independence means every row has the same shape

Concept

Chapter 3 gave a second, equivalent way to say that A and B are independent: knowing B does not change the chance of A. In a table, that is a statement about rows. Take A as volunteering one to three hours and B as being a community college student.

\[ P(A \mid B) = P(A) \]

Both sides can be read straight off the observed table. The left side uses only the community college row; the right side uses the column total over everyone.

\[ P(\text{1–3 h} \mid \text{CC}) = \frac{111}{255} = 0.435, \qquad P(\text{1–3 h}) = \frac{298}{839} = 0.355 \]

In the sample the two differ by eight percentage points. If hours were independent of type, the two would be equal in the population, and every row's percentages would match the overall percentages, in every column.

So there are two ways to picture the null hypothesis, and they are the same thing. Either the chance of a cell is the product of its row and column chances, or every row has the same shape as the whole table. The first gives the formula; the second gives the picture of identical bars you will see when the expected table is drawn.

Sample rows never match perfectly, even when the factors are truly independent, because 255 people are a sample. The test exists to decide whether 0.435 against 0.355, together with every other cell's gap, is more than sampling wobble.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §3.2 and §11.3, p. 576 — independence as conditional probability; Table 11.15

8. Independence, written as a count

Concept

Example 11.5 makes the definition into a number. Let A be a speeding violation in the last year and B be using a cell phone while driving. If the two are independent, the chance of both is the product.

\[ P(A \text{ and } B) = P(A)\,P(B) \]

Each probability is a share of the 755 drivers. Write y for the expected number who did both; then the chance of both is y out of 755. Substitute every share.

\[ \frac{y}{755} = \left(\frac{70}{755}\right)\left(\frac{305}{755}\right) \]

Multiply both sides by 755. One factor of 755 cancels on the right, and what is left is the product of the two totals divided by the grand total, once.

\[ y = \frac{(70)(305)}{755} = \frac{21{,}350}{755} \approx 28.28 \]

Nothing about this used phones or speeding. Replace 70 by any row total and 305 by any column total and the same three lines give that cell's expected count. That is where the section's formula comes from.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Example 11.5

9. Reading the expected-count formula

Notation

Here is the formula as the book states it. It is the last line of the previous slide with the numbers replaced by their names. Hover over each piece.

Annotate

On: \( E = \frac{(\text{row total})(\text{column total})}{\text{total number surveyed}} \)

  • The expected count in one cell: how many would land there, on average, if the two factors were independent.
  • The total of the cell's row in the observed table. It carries the share P(A) once divided by n.
  • The total of the cell's column. Divided by n it is P(B).
  • The grand total n, divided only once: the two shares each had an n, and multiplying by n to get a count cancels one.
  • Each cell gets its own E from its own row and column; a 3 by 3 table needs nine of them.

Read the formula a second way, because it is the faster way to check it. The row total times the column's share of everyone: of the 255 community college students, independence says 298 out of 839 should be in the one-to-three-hours column.

\[ E = 255 \times \frac{298}{839} = 90.57 \]

As in Section 11.2, an expected count is an average over imagined samples, so it does not have to be a whole number. Keep two decimal places; rounding to whole people throws away accuracy you need for the statistic.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — the formula for E

10. Example 11.5: cell phones and speeding violations

Worked example

Of 755 drivers surveyed, 70 had a speeding violation and 685 did not; 305 used cell phones while driving and 450 did not. If the two are independent, how many drivers are expected to have done both?

Name the events

Why: the two factors, each with two levels.

\[ A = \text{violation}, \quad B = \text{phone while driving} \]

Each factor splits the 755 drivers in two, so the full table would be two by two. The book gives only its margins, which is all an expected count needs.

Write the independence condition

Why: the definition from Chapter 3.

\[ P(A \text{ and } B) = P(A)\,P(B) \]

Express each probability as a share of 755

Why: y is the expected count of drivers with both.

\[ \frac{y}{755} = \frac{70}{755} \cdot \frac{305}{755} \]

Writing each probability as a count over 755 is the key move. It turns a statement about chances into a statement about people, which is what a contingency table counts.

Multiply both sides by 755

Why: one factor of 755 cancels on the right.

\[ y = \frac{70 \cdot 305}{755} \]

Multiply the totals

Why: the numerator.

\[ 70 \times 305 = 21{,}350 \]

This step is where the derivation pays off. You never need the probabilities as decimals, which would invite rounding error; the two totals multiply as whole numbers, and only one division is left.

Divide by the grand total

Why: once, not twice.

\[ y = \frac{21{,}350}{755} \approx 28.28 \]

Figure (svg): A unit square standing for all 755 drivers. A vertical dashed line splits it at 0.404 of the width, phone users on the left. A horizontal dashed line splits it at 0.093 of the height, drivers with a violation along the top. The small yellow rectangle where the phone strip and the violation strip overlap has area 0.404 times 0.093, which is 0.0375; times 755 drivers that is 28.28 expected drivers.

Under independence the share with both is the width times the height: a thin top strip cut by the phone line. The yellow corner is the expected share, and 755 times it is the expected count.

In context: if phone use and speeding had nothing to do with each other, about 28 of these 755 drivers would be expected both to use a phone while driving and to have a violation. The null hypothesis of a test, in the book's words, says the two are independent events, and 28 is what that null predicts for this cell.

Check by the share route

Why: phone users are 305 of 755, about 40 percent, so independence puts about 40 percent of the 70 violators among them.

\[ 0.4040 \times 70 = 28.28 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Example 11.5

11. Estimate first: music and the honor roll

Estimation

Try It 11.5 surveys 300 students: 50 are music students and 97 are on the honor roll. Before any formula, estimate how many music students independence puts on the honor roll.

Predict first

If being a music student and being on the honor roll are independent, roughly how many music students are expected on the honor roll?

  • about 16
  • about 50
  • about 97
  • about 5

Correct: about 16

Why: About a third of all students are on the honor roll, since 97 out of 300 is just under a third. Independence says music students should match that, and a third of 50 is about 16.

\[ \frac{97}{300} \approx 0.32, \qquad 0.32 \times 50 \approx 16 \]

If you chose about 50, you took every music student as being on the honor roll; about 97 is the whole honor roll. Neither uses independence. The answer near 5 would come from dividing by the total twice and then rescaling carelessly.

The habit of estimating from a share protects you from the two common slips: forgetting to divide by the total, which gives thousands, and dividing by it twice, which gives a fraction. A sensible expected count is never larger than its own row or column total.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Try It 11.5

12. Try It 11.5: the expected count, exactly

Worked example

A sample of 300 students: 50 music students and 250 not; 97 on the honor roll and 203 not. Find the expected number of music students on the honor roll, assuming independence.

Identify the cell's row total

Why: the music students.

\[ \text{row total} = 50 \]

Identify the cell's column total

Why: the honor roll.

\[ \text{column total} = 97 \]

Identify the grand total

Why: everyone surveyed.

\[ n = 300 \]

Three numbers, read from three different places in the table: the edge of the row, the foot of the column and the corner. Naming them before multiplying is the cheapest protection against picking up the wrong total, which is the commonest error in this section.

Multiply the two totals

Why: the numerator of the formula.

\[ 50 \times 97 = 4{,}850 \]

Divide once by 300 and you are done. If you find yourself dividing by 300 a second time, you have turned the count back into a probability; a result below one would be the warning sign.

Divide by the grand total

Why: once.

\[ E = \frac{4{,}850}{300} \approx 16.17 \]

In context: if music and honor-roll status were unrelated, about 16 of the 50 music students would be on the honor roll. Whether the real number is far from 16 is what a test would decide, once the inside of the table is known.

Check against the estimate

Why: the honor roll's share of all students, applied to the 50 music students.

\[ \frac{97}{300} \times 50 = 0.3233 \times 50 = 16.17 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Try It 11.5

13. Example 11.6: the first row of the expected table

Worked example

The volunteer table has nine cells, so it needs nine expected counts. Build the first row, community college students, one cell at a time, and use the margins to check it.

Read the margins

Why: row totals, column totals and the grand total.

\[ R: 255, 290, 294; \quad C: 298, 379, 162; \quad n = 839 \]

Every expected count in this table will be built from these seven numbers alone. The 111, the 96 and the rest of the inside of the table play no part in the expected counts; they come back only when the statistic compares observed with expected.

Top-left cell: community college, 1 to 3 hours

Why: row 255, column 298.

\[ E_{11} = \frac{255 \times 298}{839} = \frac{75{,}990}{839} = 90.57 \]

Top-middle cell: 4 to 6 hours

Why: same row, column 379.

\[ E_{12} = \frac{255 \times 379}{839} = \frac{96{,}645}{839} = 115.19 \]

Top-right cell: 7 to 9 hours

Why: same row, column 162.

\[ E_{13} = \frac{255 \times 162}{839} = \frac{41{,}310}{839} = 49.24 \]

Compare with the observed row: 111, 96, 48. Community college students put in short weeks about twenty more often than independence predicts, and medium weeks about nineteen less often. That is the pattern the bar chart showed.

Check the row against its total

Why: an expected row must add back to the observed row total, 255.

\[ 90.57 + 115.19 + 49.24 = 255.00 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Example 11.6, Table 11.16

14. Example 11.6: the rest of the expected table

Worked example

The other two rows follow the same formula. Each row has its own row total; the three columns keep the same column totals throughout.

Four-year college row

Why: row total 290.

\[ \frac{290 \cdot 298}{839}, \; \frac{290 \cdot 379}{839}, \; \frac{290 \cdot 162}{839} = 103.00, \; 131.00, \; 56.00 \]

Notice that the three column totals reappear in every row: only the row total changes. So each row of the expected table is the same set of column shares, 0.355, 0.452 and 0.193, scaled up to that row's size.

Nonstudent row

Why: row total 294.

\[ \frac{294 \cdot 298}{839}, \; \frac{294 \cdot 379}{839}, \; \frac{294 \cdot 162}{839} = 104.42, \; 132.81, \; 56.77 \]

expected1–3 hours4–6 hours7–9 hoursrow total
community college90.57115.1949.24255
four-year college103.00131.0056.00290
nonstudents104.42132.8156.77294
column total298379162839

These agree with the book's Table 11.16 to every printed digit. The four-year row comes out at almost exactly 103, 131 and 56: a coincidence of these totals, not a rule, so do not round other rows to whole numbers.

Check a column against its total

Why: down the 1 to 3 hours column the expected counts must add to 298.

\[ 90.57 + 103.00 + 104.42 = 298.00 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Example 11.6, Table 11.16

15. One expected count, filled in

Fill the middle

Four-year college students who volunteer one to three hours: row total 290, column total 298, grand total 839. Fill in the column total, then the expected count to two decimal places.

Fill in the blanks

E = \frac298})}103.00 = ___

Why: The cell sits in the one to three hours column, whose total is 298. Then 290 times 298 is 86,420, and 86,420 divided by 839 is 103.004, which is 103.00 to two places.

The quickest way to choose the right totals is to put a finger on the cell and slide it to the edge of the table twice: right to its row total, down to its column total. Using two row totals, or a total from the wrong row, is the usual slip here.

And notice the observed count in this cell was 96, seven below its expected 103. Four-year students are a little under-represented among the short weekly commitments, but only a little; this cell will add less than half a point to the statistic.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Example 11.6

16. Why the expected table keeps the margins

Concept

Every check so far found the same thing: an expected row adds back to the observed row total, and an expected column to its column total. That is not luck. Add the expected counts along row i.

\[ \sum_j E_{ij} = \sum_j \frac{R_i \, C_j}{n} = \frac{R_i}{n} \sum_j C_j \]

The column totals add up to everyone, so their sum is n, and it cancels the n in the denominator.

\[ \frac{R_i}{n} \cdot n = R_i \]

Figure (svg): The expected table for Example 11.6 drawn as a three by three grid: community college 90.57, 115.19, 49.24; four-year college 103.00, 131.00, 56.00; nonstudents 104.42, 132.81, 56.77. Dashed boxes to the right give the row sums 255, 290 and 294, and dashed boxes below give the column sums 298, 379 and 162 and the grand total 839, all identical to the observed table's totals.

Read along any row or down any column: the expected counts add back to the observed totals exactly. Only the inside of the table was rearranged.

So the expected table is the same people, with the same row totals and the same column totals, rearranged inside the table as if the two factors had nothing to do with each other. That gives you a free arithmetic check on every expected table you build: if a row misses its total by more than rounding, one of its cells is wrong.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 575-576 — the formula for E, and Tables 11.15 and 11.16

17. The expected table, drawn

Picture it

Redraw the expected table as row percentages, exactly as the observed table was drawn earlier. Compare this picture with that one.

Figure (svg): The same three bars redrawn from the expected table. Every volunteer type now splits identically: 35.5 percent 1 to 3 hours, 45.2 percent 4 to 6 hours, 19.3 percent 7 to 9 hours, exactly matching the bar for all 839 volunteers.

This is what independence looks like: knowing someone's volunteer type tells you nothing new about their hours, so every row has the same shape as the whole.

All three bars are now identical, and identical to the bar for everyone. That is independence as a picture: the distribution of hours is the same whichever volunteer type you look at, so the type tells you nothing about the hours.

It also explains the formula. A cell's expected share of its own row is the column's share of everyone, the column total over n. Multiply that share by the row total and you have row times column over n again.

\[ \frac{E_{ij}}{R_i} = \frac{C_j}{n} \quad \Longleftrightarrow \quad E_{ij} = \frac{R_i \, C_j}{n} \]

The test measures how far the observed bars are from this picture of identical bars.

18. Trap: dividing by the grand total twice

Trap

The trap

For the volunteer table's top-left cell, a first attempt multiplies the two probabilities and stops:

\[ \frac{255}{839} \cdot \frac{298}{839} \]

\[ = 0.108 \]

Wrong. That is a probability, the chance of both, not a count of volunteers.

The fix

The product of the two shares is the probability of the cell. To turn a probability into a count you multiply by everyone surveyed, and one factor of 839 cancels.

\[ 0.108 \times 839 = 90.57 \]

\[ E = \frac{255 \times 298}{839} \]

A quick test catches it: a count of 0.108 people in a table of 839 is absurd, and an expected table whose rows do not add to 255, 290 and 294 cannot be right.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 575-576 — the formula for E

19. What does the expected table describe?

Prediction

Commit to an answer before reading the explanation. The question is about what the numbers in an expected table actually stand for.

Predict first

An expected contingency table, built from the observed margins, describes which of these?

  • the same sample, rearranged as if the two factors were unrelated
  • a new, larger sample drawn from the same population
  • the observed counts rounded to whole numbers
  • the true counts in the whole population

Correct: the same sample, rearranged as if the two factors were unrelated

Why: It keeps every observed margin, so it describes the same people with the same row and column totals, but it puts them into cells as independence would. It is what the null hypothesis predicts for this sample, on average.

Each wrong answer is a real confusion. The expected table is not a new sample: it has the same grand total. It is not rounding: its counts are usually not whole. And it is not the population: it is a prediction made under a hypothesis that may be false.

That last point is the one to keep. The expected table is the null hypothesis written as numbers, cell by cell. The test asks whether the observed table is too far from it to blame on chance.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Tables 11.15 and 11.16

20. Degrees of freedom as a product

Section

Part 2

21. Counting the cells that are free

Concept

In Section 11.2, degrees of freedom counted the cells that could vary once the total was fixed: cells minus one. A contingency table has more than one total fixed. Every row total and every column total is fixed, because the expected table must share them.

So ask the same question with all those totals in place: how many cells could you fill in freely before the margins force the rest? Try it on the volunteer table.

Figure (svg): The observed volunteer table with its row totals 255, 290, 294 and column totals 298, 379, 162 fixed. The four top-left cells, 111, 96, 96 and 133, are shaded green as free choices. The other five cells are each worked out by subtraction from a margin, for example 255 minus 111 minus 96 equals 48 and 298 minus 111 minus 96 equals 91.

Choose the four green cells and the margins force the other five. Four free choices is four degrees of freedom, and the free block is two rows by two columns.

Choose the four green cells. The last cell of each of the first two rows is then forced by its row total, and every cell of the last row is forced by its column total. Five forced cells, four free ones.

\[ 48 = 255 - 111 - 96, \qquad 91 = 298 - 111 - 96 \]

The free cells always form a block one row short and one column short of the table. That block has rows minus one times columns minus one cells, and that is the degrees of freedom.

\[ df = (r - 1)(c - 1) = (3 - 1)(3 - 1) = 4 \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 575-576 — the df formula, and Example 11.6

22. Reading the statistic and its df

Notation

The test statistic is the goodness-of-fit sum, now taken over every cell of a two-way table. The book writes the sum over i times j to say every row-and-column pair. Hover over each piece.

Annotate

On: \( \chi^2 = \sum_{(i \cdot j)} \frac{(O - E)^2}{E}, \qquad df = (r - 1)(c - 1) \)

  • One term for every cell: i runs over the rows and j over the columns, so a 3 by 3 table has nine terms.
  • The observed count in a cell, from the data.
  • The expected count in that cell: row total times column total over n.
  • The same contribution as in goodness of fit: a squared gap measured against what was expected there.
  • Rows minus one times columns minus one: the free block of cells once every margin is fixed.

The extracted text of the book has lost the count of terms at this point: it is the number of rows times the number of columns, one term per cell. Nine for the volunteers, fifteen for Example 11.7.

Each term is a square over a positive count, so every term is zero or positive and the sum can only grow when any cell misfits. You will meet that fact again when choosing the tail.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 574 — the test statistic for a test of independence

23. A second route: counting the constraints

Concept

You can reach the same number by counting what is fixed instead of what is free. Start with all the cells, then subtract one for every independent constraint the margins impose.

\[ r c \text{ cells}, \qquad r \text{ row totals} + c \text{ column totals} \]

But the row totals and the column totals both add up to the grand total, so once all but one of them are known, the last one is forced. Only r plus c minus one of the margins are independent constraints.

\[ df = rc - (r + c - 1) \]

Expand and factor, and the product appears. This is the algebra behind the picture of the free block.

\[ rc - r - c + 1 = (r - 1)(c - 1) \]

\[ \text{volunteers: } 9 - (3 + 3 - 1) = 9 - 5 = 4 \quad \checkmark \]

Nowhere does the number of people enter. Eight hundred and thirty-nine volunteers or eight thousand, a three by three table has four degrees of freedom.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — df = (number of columns − 1)(number of rows − 1)

24. The two by two table: one free cell

Concept

The smallest contingency table has two rows and two columns, like the drivers of Example 11.5. Its degrees of freedom are one times one, which is one. See why by filling its expected table from a single number.

\[ df = (2 - 1)(2 - 1) = 1 \]

Once the expected count for phone users with a violation is fixed at 28.28, the margins force everything else. The rest of the violation row is 70 minus 28.28; the rest of the phone column is 305 minus 28.28; and the last cell is what the no-violation row still needs.

Figure (svg): A two by two grid for Example 11.5's expected table. Rows: violation, total 70, and no violation, total 685. Columns: phone, total 305, and no phone, total 450. The top-left cell, 28.28, is shaded green as the one free cell. The other three are worked out by subtraction: 70 minus 28.28 is 41.72, 305 minus 28.28 is 276.72, and 685 minus 276.72 is 408.28.

One number and the four margins settle the whole table. That is one degree of freedom, and it is why every two by two table has exactly one.

\[ 70 - 28.28 = 41.72, \quad 305 - 28.28 = 276.72, \quad 685 - 276.72 = 408.28 \]

Check the last column the other way: 41.72 plus 408.28 is 450, the number of drivers who did not use a phone. The table closes, which is the margin check at work again.

A consequence worth noticing: in a two by two table every gap, observed minus expected, has the same size, with signs alternating around the table. Moving one person into one cell forces a matching move in every other cell. So the four contributions differ only through their expected counts.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Example 11.5, completed as an expected table

25. Slide the table's shape

Tweak it

Set the number of rows and columns and watch the chi-square curve the test would use. The readout gives the degrees of freedom as the product; the curve's mean sits at that product.

Parameter explorer

Change the rows and columns. How does the curve move when you add one row to a table with three columns, compared with adding one row to a table with five?

\[ df = ({r} - 1)({c} - 1) \]

  • r — from 2 to 6: rows
  • c — from 2 to 6: columns

With three columns, each extra row adds two degrees of freedom; with five columns, each extra row adds four. That is what a product means: a new row brings one new free cell for every column but the last.

Watch the curve too. A two by two table has one degree of freedom, and its curve shoots up at zero. A six by six table has twenty-five, and its hump sits near 25. A statistic of 12 would be enormous on the first and ordinary on the second, so the df always travels with the statistic.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.1 and §11.3 — a different chi-square curve for each df

26. Example 11.6's df, and the book's teenagers question

Worked example

The volunteer table has three types of volunteer and three bands of hours. Find its degrees of freedom. Then answer the question the book poses: if a fourth type of volunteer, teenagers, had been added, what would the degrees of freedom be?

Count the rows

Why: the volunteer types.

\[ r = 3 \]

Count the columns

Why: the bands of hours.

\[ c = 3 \]

Multiply rows minus one by columns minus one

Why: the free block.

\[ df = (3 - 1)(3 - 1) = 2 \times 2 = 4 \]

Four is the degrees of freedom the book uses for Example 11.6, written there as columns minus one times rows minus one. The order does not matter, since multiplication does not care; what matters is that the two counts multiply.

Add the teenagers row

Why: four rows, the same three columns.

\[ df = (4 - 1)(3 - 1) = 3 \times 2 = 6 \]

Figure (svg): A four by three grid with rows community college, four-year college, nonstudents and teenagers, and columns 1 to 3, 4 to 6 and 7 to 9 hours. The top-left block of three rows by two columns, six cells, is shaded green and marked free; the last column and the last row are marked forced, and all the margins are marked fixed.

One more row adds a row of three cells, but its last cell is forced by its own total and the whole row is then forced by the column totals. The free block grows from two by two to three by two: six.

The new row did not add three degrees of freedom, one per cell, nor one, as cells minus one might suggest. It added two: columns minus one, because the new row's last cell is forced by its own total.

Check by counting constraints

Why: twelve cells, and four plus three minus one independent margins.

\[ 12 - (4 + 3 - 1) = 12 - 6 = 6 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 576-577 — Example 11.6, and the teenagers question

27. Find the error: four answers for one table

Error analysis

A table classifies 500 shoppers by three store locations and four payment methods. Four classmates report four different degrees of freedom. Every arithmetic step is correct; only one rule is. Hover over each line to see where each went.

Annotate

On: \( (3-1)(4-1) = 6, \quad 12 - 1 = 11, \quad 500 - 1 = 499, \quad 2 + 3 = 5 \)

  • Correct: rows minus one times columns minus one, the free block once every margin is fixed.
  • The goodness-of-fit rule, cells minus one. It fixes only the grand total, but here every row and column total is fixed too.
  • The sample size has nothing to do with it. Degrees of freedom count free cells, never people.
  • Added instead of multiplied. Each new row brings columns-minus-one new free cells, so the count is a product.

The cells-minus-one answer is the most tempting, because Section 11.2 has just drilled it. The difference is the number of constraints: one row of counts has one fixed total, but a two-way table has a fixed total for every row and every column.

Each wrong answer changes the conclusion. On 499 degrees of freedom almost any statistic looks tiny; on 11 instead of 6, a statistic of 13 slides from significant at five percent to not significant. The right curve is not a detail.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — the df formula

28. Try It 11.6: hypotheses and df for the jobs table

Worked example

The Bureau of Labor Statistics table counts jobs, in thousands, by industry sector in 2000, 2010 and 2020. The book asks for the hypotheses and the degrees of freedom for a test that the number of jobs in each sector is independent of the year.

sector200020102020total
nonagriculture wage and salary13,24313,04415,01841,305
goods-producing, excl. agriculture2,4571,7711,9506,178
services-providing10,78611,27313,06835,127
agriculture, forestry, fishing, hunting240214201655
nonagriculture self-employed9318949722,797
secondary jobs, agriculture and household14111136
secondary jobs, self-employed196144152492
total27,86727,35131,37286,590

Write the hypotheses in words

Why: the factors are sector and year.

\[ H_0: \text{sector is independent of year} \]

\[ H_a: \text{sector and year are dependent} \]

Count rows and columns

Why: seven sectors, three years.

\[ df = (7 - 1)(3 - 1) = 6 \times 2 = 12 \]

Twelve is the answer the book is after for the table as printed. The total row and total column are margins, not categories, so they are never counted as rows or columns.

Now look closely at the first row: 6,178 plus 35,127 is exactly 41,305. Nonagriculture wage and salary jobs are the goods-producing and services-providing jobs added together, so those jobs are counted twice. A contingency table needs every count in exactly one cell, so this table, as printed, is not valid input for the test.

Figure (svg): Two horizontal bars for the year totals of Try It 11.6. The top bar is the nonagriculture wage and salary row, 41,305. The bottom bar stacks goods-producing, 6,178, and services-providing, 35,127, and ends at exactly the same place, 41,305. A dashed red line marks the shared end.

The table's first row is not a separate category: it is the next two rows added together. Every one of those jobs sits in two cells at once.

Check the table before trusting the df

Why: drop the overlapping total row and six genuine sectors remain.

\[ 6178 + 35127 = 41305, \quad df = (6 - 1)(3 - 1) = 10 \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 577 — Try It 11.6, Table 11.17

29. Table shape to degrees of freedom

Matching

Match each table to its degrees of freedom. Count rows and columns of categories only: total rows and columns are margins, not categories.

Use the free-block picture rather than a memorised rule: shade every cell except the last row and the last column, and count what is shaded.

Match the pairs

  • a. 2 rows by 2 columns
  • b. 3 rows by 5 columns (Example 11.7)
  • c. 4 rows by 3 columns (with teenagers)
  • d. 5 rows by 4 columns
  • w. df = 1
  • x. df = 8
  • y. df = 6
  • z. df = 12

Why: Rows minus one times columns minus one each time: one times one, two times four, three times two, four times three. A two by two table has a single free cell, since one count and the four margins fix the rest.

The two by two case deserves a second look. Pick any one cell, say the drivers who used a phone and had a violation, and the margins force all three others by subtraction. One free cell, one degree of freedom.

Also notice that six and eight are close but come from different shapes. The df alone does not tell you the shape of the table, which is why a write-up states both the table's dimensions and the df.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 575-578 — the df formula and the examples

30. Running the test

Section

Part 3

31. Hypotheses in words, because there is no parameter

Concept

Every test in Chapters 9 and 10 was about a parameter: a mean, a proportion, a difference. A test of independence asks about a relationship between two factors, and no single number captures that. So the book states the hypotheses in words.

\[ H_0: \text{the two factors are independent} \]

\[ H_a: \text{the two factors are not independent (dependent)} \]

For the volunteers, name the factors in the sentence. The null always claims independence, because independence is what lets you compute the expected table at all. Without it there would be nothing to compare the data with.

\[ H_0: \text{hours volunteered is independent of volunteer type} \]

Dependent here means only that the distribution of one factor changes across the levels of the other. It does not say which factor drives which, or that either drives anything; the word is about association. Keep that in mind until the conclusion.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 575-576 — hypotheses stated in words

32. Example 11.6: the statistic, cell by cell

Worked example

The book reports the statistic from a calculator. Compute it by hand so that you can see where it comes from: subtract, square, divide by the expected count, add. Work one row at a time.

Find each gap, observed minus expected

Why: community college row first.

\[ 111 - 90.57 = 20.43, \; 96 - 115.19 = -19.19, \; 48 - 49.24 = -1.24 \]

The three gaps in this row add to zero, as they must, since the expected row has the observed row total. That gives an instant check before any squaring.

Square each gap and divide by its expected count

Why: the community college contributions.

\[ \frac{20.43^2}{90.57}, \; \frac{19.19^2}{115.19}, \; \frac{1.24^2}{49.24} = 4.6074, \; 3.1972, \; 0.0311 \]

Add the first row

Why: its share of the statistic.

\[ 4.6074 + 3.1972 + 0.0311 = 7.8357 \]

The community college row already holds more than half of the final statistic. The first cell, 111 against 90.57, is the largest single contribution in the table: a gap of about twenty volunteers on an expected ninety is a big relative miss.

Four-year college row

Why: the same three moves.

\[ 0.4762 + 0.0305 + 0.4473 = 0.9540 \]

Nonstudent row

Why: the same three moves.

\[ 1.7258 + 2.2255 + 0.2500 = 4.2013 \]

The four-year college row contributes less than one point in total. Its observed counts sit close to their expected ones, so those students look much like the population as a whole; the misfit is concentrated in the other two rows.

Add the three rows

Why: the test statistic.

\[ \chi^2 = 7.8357 + 0.9540 + 4.2013 = 12.9910 \]

That matches the book's 12.99. The calculator reports 12.9909; the last digit here differs only because each term was rounded to four places before adding. The terms use unrounded expected counts, and the two-decimal ones would change only the third decimal.

Check the gaps

Why: in each row the gaps must add to zero, since the expected row has the observed row's total.

\[ 20.43 - 19.19 - 1.24 = 0.00 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Example 11.6, the test statistic

33. Where the evidence sits in the table

Picture it

A single number hides where the misfit is. Draw each cell's contribution in its place in the table, coloured by the direction of the gap: orange where more volunteers were observed than expected, blue where fewer.

Figure (svg): A three by three grid of Example 11.6's nine contributions, coloured orange where more volunteers were observed than expected and blue where fewer, with stronger colour for bigger contributions. Community college: 4.6074 orange at 1 to 3 hours, 3.1972 blue at 4 to 6 hours, 0.0311 blue at 7 to 9 hours. Four-year college: 0.4762 blue, 0.0305 orange, 0.4473 orange. Nonstudents: 1.7258 blue, 2.2255 orange, 0.2500 blue.

Two cells carry most of the statistic, both in the community college row: too many short commitments, too few medium ones. The nonstudents lean the other way.

The community college row alone gives 7.8357 of the 12.9910, about sixty percent. Those students volunteer one to three hours far more than independence predicts and four to six hours far less. The nonstudents show the mirror pattern, weaker.

Two things the statistic cannot tell you on its own: the direction, which you read from the colours, that is from the sign of observed minus expected; and the cells responsible, which you read from the sizes. A good conclusion after a rejection names both.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 576 — Example 11.6, computed per cell

34. Why the test is always right-tailed

Concept

The book says a test of independence is always right-tailed, because of how the statistic is computed. Every term is a squared gap over a positive count, so every misfit in every cell pushes the sum up.

\[ O = E \text{ in every cell} \;\Longrightarrow\; \chi^2 = 0 \]

A statistic near zero means the observed table almost exactly matches the independence picture: that is the best possible news for the null hypothesis. Only large values are evidence that the factors are related, so the p-value is always the area to the right.

\[ p\text{-value} = P(\chi^2_{df} > \chi^2_{\text{obs}}) \]

Notice that the alternative, dependent, has no direction at all: the community college students could volunteer more or less than expected, and either way the squared gap lands in the same right tail. One tail covers every kind of dependence.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — the test of independence is always right-tailed

35. Two thousand volunteer surveys with no relationship

Picture it

Why should a chi-square curve with four degrees of freedom describe this statistic? Check it directly. The computer drew 839 volunteers two thousand times, choosing each person's type and hours separately, with the observed shares, so that type and hours were genuinely independent.

Figure (svg): A histogram of 2000 simulated values of the independence statistic, each from 839 volunteers whose type and hours were drawn independently with the observed shares. The bars rise from zero to a peak near 2 and trail off to the right. The chi-square curve with 4 degrees of freedom lies along the tops of the bars. Bars at 13 and beyond, past the observed 12.99, are yellow and barely visible.

No relationship was built into these tables, yet their statistics pile up under the chi-square curve with four degrees of freedom. Only about one in a hundred reaches the real 12.99.

Nothing but independent draws made these bars, yet they follow the chi-square curve with four degrees of freedom closely. Their average, 4.01, sits next to the curve's mean of 4, the degrees of freedom.

Now place the real survey on the picture. Only 26 of the 2000 independent surveys, about 1.3 percent, produced a statistic of 12.99 or more. That is a simulated p-value, and it agrees with the curve's 0.0113 to within the simulation's own wobble.

This is exactly what the p-value means. If hours and type were unrelated, a table as far from the expected one as the real volunteers' would turn up about once in a hundred surveys. Either the volunteers were that unlucky, or the factors are related.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 576-577 — Example 11.6, checked by simulation

36. Example 11.6: p-value, decision and conclusion

Worked example

The statistic is 12.99 on four degrees of freedom. The book gives no alpha, so use five percent. Finish the test and end it with a sentence about the population of volunteers.

Write the distribution for the test

Why: three by three, so four degrees of freedom.

\[ \chi^2_4 \]

Write the probability statement

Why: right-tailed, the area beyond 12.99.

\[ p\text{-value} = P(\chi^2_4 > 12.99) \]

Before evaluating anything, estimate. The curve with four degrees of freedom has its mean at 4, and 12.99 is more than three times that, so the p-value should be small, on the order of one percent. The calculation should confirm that, not surprise you.

Use the closed form for four degrees of freedom

Why: the same tail formula as in Section 11.2.

\[ P(\chi^2_4 > x) = e^{-x/2}\left(1 + \frac{x}{2}\right) \]

Substitute 12.99

Why: half of 12.99 is 6.4955, and e to the minus 6.4955 is 0.001510.

\[ 0.001510 \times 7.4955 \approx 0.0113 \]

Figure (svg): A chi-square curve with 4 degrees of freedom from 0 to 20. A dashed red line at 9.488 marks the 5 percent cutoff and the region beyond it is shaded red. A yellow line marks the observed statistic 12.99 inside the red region, with the thin area beyond it shaded blue and labelled p-value 0.0113.

The mean of this curve is 4, and the statistic is more than three times that. Only about one percent of the curve lies beyond it, inside the five percent rejection region.

Compare with alpha

Why: the p-value is below five percent.

\[ 0.0113 < 0.05 \Rightarrow \text{reject } H_0 \]

At the one percent level the decision would go the other way, since 0.0113 is just above 0.01. Report the p-value itself, so a reader with a different alpha can make their own decision.

Conclusion, in context: at the 5 percent level, there is sufficient evidence that the number of hours volunteered and the type of volunteer are dependent. In this population, community college students lean toward short weekly commitments. That is a statement of association; it does not say being a community college student causes shorter hours.

Check against the critical value

Why: the five percent cutoff on four degrees of freedom is 9.488, and 12.99 lies beyond it, so the decision agrees.

\[ 12.99 > 9.488 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 576-577 — Example 11.6 and Figure 11.7

37. Rank the evidence

Ranking

A statistic means nothing without its degrees of freedom. Rank these four results from the strongest evidence of dependence to the weakest, that is, from the smallest p-value to the largest.

Put in order

Order these results from the smallest p-value to the largest.

  1. χ² = 48.42 on df 8 (Example 11.7)
  2. χ² = 12.99 on df 4 (Example 11.6)
  3. χ² = 12.99 on df 6
  4. χ² = 12.99 on df 8

Why: The same 12.99 gets weaker as the degrees of freedom grow, because the curve's mean moves right: p is 0.011 on four, 0.043 on six and 0.112 on eight. A statistic of 48.42 on eight is six times its mean, with a p-value near zero.

\[ P(\chi^2_4 > 12.99) = 0.011, \quad P(\chi^2_6 > 12.99) = 0.043, \quad P(\chi^2_8 > 12.99) = 0.112 \]

If you placed the three 12.99 results in a different order, look again at the slider from Part 2. More degrees of freedom move the whole curve to the right, so the same value sits less far into the tail, and its p-value grows.

The comparison with the mean is the quick tool. A statistic near its degrees of freedom is ordinary; one around twice its degrees of freedom is in the region of a few percent; one several times its degrees of freedom is very strong evidence. Use it to sanity-check every p-value you compute.

The pair worth remembering is the first two: the anxiety table's 48.42 and the volunteers' 12.99. Both reject, but on very different scales of evidence, and a report should give the p-value, not only the word reject.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.1 — the mean of a chi-square curve is its df

38. A small table start to finish: study time by year

Worked example

A test from start to finish on a table of our own. A college surveys 100 first-year students and 100 seniors about when they prefer to study. Is preferred study time independent of year, at the 5 percent level?

morningafternoonnighttotal
first-year203050100
senior353035100
total556085200

State the hypotheses

Why: two factors, so in words.

\[ H_0: \text{study time is independent of year} \]

The alternative is that study time and year are dependent: the distribution of study times differs between first-years and seniors. Notice that the null makes no claim about which time is most popular, only that both years share the same pattern.

Build the expected counts

Why: each row total is 100, so both rows expect the same.

\[ \frac{100 \cdot 55}{200} = 27.5, \; \frac{100 \cdot 60}{200} = 30, \; \frac{100 \cdot 85}{200} = 42.5 \]

Check the condition

Why: the smallest expected count is 27.5, well above five.

\[ \min E = 27.5 \ge 5 \]

The picture shows what the test will measure: first-years over-represented at night and under-represented in the morning, seniors the reverse, and the afternoon exactly on its expected line, contributing nothing.

Figure (svg): Grouped bars for 100 first-year students and 100 seniors by preferred study time. Morning: 20 first-years and 35 seniors, against an expected 27.5 for each, drawn as a dashed yellow line. Afternoon: 30 and 30, expected 30. Night: 50 first-years and 35 seniors, expected 42.5.

Because both rows hold 100 students, each row expects the same count in a column. Afternoon sits exactly on its line; morning and night pull apart in opposite directions.

Compute the contributions for first-years

Why: gaps of minus 7.5, 0 and 7.5.

\[ \frac{7.5^2}{27.5} + \frac{0^2}{30} + \frac{7.5^2}{42.5} = 2.045 + 0 + 1.324 \]

The senior row mirrors it

Why: gaps of plus 7.5, 0 and minus 7.5, the same squares.

\[ \chi^2 = 2(2.045 + 1.324) = 6.738 \]

Find df and the p-value

Why: two rows, three columns; on two degrees of freedom the tail is one exponential.

\[ df = (2-1)(3-1) = 2, \quad p = e^{-6.738/2} = 0.0344 \]

Figure (svg): A chi-square curve with 2 degrees of freedom from 0 to 12, starting at its highest point at zero and decaying. A dashed red line at 5.991 marks the 5 percent cutoff. A yellow line marks the statistic 6.74 just beyond it, and the area to its right is shaded blue and labelled p-value 0.0344.

Just past the cutoff. With two degrees of freedom the tail is a single exponential, so the p-value is e to the minus half the statistic.

Decision: 0.0344 is below 0.05, so reject the null. In context: at the 5 percent level there is evidence that preferred study time is related to year, with first-years leaning to night and seniors to morning. At the 1 percent level the same data would not be enough; the evidence is real but modest.

Check against the critical value

Why: the five percent cutoff on two degrees of freedom is 5.991.

\[ 6.74 > 5.991 \quad \checkmark \]

39. Step zero: may you run the test at all?

Step zero

Before computing a single contribution there is one check the book insists on. Decide what it is, and then decide which single cell you need to look at to settle it.

Discussion prompt

For Example 11.7's table of 400 students, with row totals 155, 193 and 52 and column totals 57, 95, 127, 63 and 58, what must be checked before the test, and which one cell decides it?

This shortcut saves you computing fifteen expected counts just to check a condition. It works because the formula multiplies the two margins: making either one smaller makes the product smaller, so nothing can be smaller than the two smallest margins multiplied together.

For Example 11.6, the same shortcut takes one line: the smallest row is 255 and the smallest column 162, so the smallest expected count is 255 times 162 over 839, which is 49.24. No cell of the volunteer table comes anywhere near five.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 574 — NOTE: each expected value at least five

40. The condition: every expected count at least five

Concept

The book's note is short: the expected value for each cell needs to be at least five to use this test. The reason is the same as in Section 11.2. The chi-square curve is an approximation to the true distribution of the statistic, and it is good only when every expected count is reasonably large.

Figure (svg): The expected table for Example 11.7: three rows of need to succeed by five columns of anxiety level, with row totals 155, 193 and 52 and column totals 57, 95, 127, 63 and 58. The smallest expected count, 7.41, sits where the smallest row, low need, meets the smallest column, high anxiety, and is outlined in yellow. Every other expected count is larger.

The expected count is a product of margins, so the smallest one is always at the smallest row crossed with the smallest column. Check that one cell and you have checked the condition for the whole table.

The condition is about expected counts, never observed ones. An observed count of 4, like the low-need, high-anxiety students, is perfectly fine; what matters is that its expected count is 7.41. Observed counts are data and can be anything, including zero.

\[ O = 4 \text{ is allowed}, \quad \text{because } E = 7.41 \ge 5 \]

When a cell does fail, the remedies are to collect more data, which raises every expected count in proportion, or to merge neighbouring categories so the margins grow. Merging lowers the degrees of freedom, so recount them afterwards.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 574 — NOTE: each expected value at least five

41. A table that fails the condition

Counterexample

Here is a small table of our own: 20 patients, 10 given a new treatment and 10 a placebo, classified by whether they improved. Find out whether the chi-square test may be used on it.

Twenty patients is a perfectly reasonable pilot study, and the treatment row does look better: 8 out of 10 improved against 4 out of 10. The question is whether this test is the right tool for so few.

improveddid nottotal
treatment8210
placebo4610
total12820

Discussion prompt

Compute the expected counts. May the chi-square test of independence be used here, and what would you do instead?

The counterexample makes a point worth keeping: software will happily print a p-value for any table. The condition is your responsibility, and it is checked on the expected counts, which the software computed but may not have shown you.

For small two by two tables there is an exact method, Fisher's exact test, that does not rely on the chi-square curve at all. It is beyond this course, but it is what a statistician would reach for here, and it is worth knowing that the chi-square test is not the only option.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 574 — NOTE: each expected value at least five

42. Reading the table after a rejection

Section

Part 4

43. Example 11.7(a): high anxiety and high need

Worked example

De Anza College gave 400 randomly sampled students a test measuring anxiety level and need to succeed in school. How many high-anxiety students are expected to have a high need to succeed, if the two are independent?

need \ anxietyhighmed-highmediummed-lowlowtotal
high need3542531510155
medium need1848633331193
low need4511151752
total57951276358400

Find the cell's row total

Why: high need to succeed.

\[ \text{row total} = 155 \]

Find the cell's column total

Why: high anxiety.

\[ \text{column total} = 57 \]

Read the two totals off the table edges with care: the row total sits at the end of the high-need row, and the column total at the foot of the high-anxiety column. The grand total, 400, sits in the corner where the two total lines meet.

Multiply the totals

Why: the numerator.

\[ 155 \times 57 = 8{,}835 \]

The table is three by five, the largest in the section, but nothing about the method changes with size. One cell needs one row total, one column total and the grand total, whatever the shape of the table around it.

Divide by the number surveyed

Why: once.

\[ E = \frac{8{,}835}{400} = 22.0875 \approx 22.09 \]

In context: if anxiety and need to succeed were independent, about 22 of the 400 students would have both high anxiety and a high need to succeed. The sample actually holds 35 such students, thirteen more than independence predicts.

Check by the share route

Why: high-anxiety students are 57 of 400, about 14 percent; 14 percent of the 155 high-need students is the same number.

\[ \frac{57}{400} \times 155 = 0.1425 \times 155 = 22.09 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 578 — Example 11.7(a)

44. Example 11.7(b): low need and med-low anxiety

Worked example

If the two variables are independent, how many students are expected to have a low need to succeed in school and a med-low level of anxiety?

Find the row total

Why: low need to succeed.

\[ \text{row total} = 52 \]

Find the column total

Why: med-low anxiety.

\[ \text{column total} = 63 \]

Multiply the totals

Why: the numerator.

\[ 52 \times 63 = 3{,}276 \]

Divide by the number surveyed

Why: once.

\[ E = \frac{3{,}276}{400} = 8.19 \]

The book prints this as 8. The exact value is 8.19, and expected counts are averages, not people, so keep the decimals; rounding every cell to a whole number would put a visible error into the statistic.

In context: independence predicts about 8 low-need, med-low-anxiety students. The sample has 15, nearly double. Combined with part (a), a pattern begins to show: more students than expected sit where need and anxiety are both high or both low.

Check the size of the answer

Why: the low-need row is the smallest row, so its expected counts are all small; this one must lie below its row total and below 63.

\[ 8.19 < 52, \quad 8.19 < 63, \quad 8.19 \ge 5 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 578 — Example 11.7(b)

45. Example 11.7 finished: the full test

Worked example

The book stops at two expected counts. Finish the test at the 5 percent level: are anxiety level and need to succeed in school independent?

State the hypotheses

Why: in words, naming both factors.

\[ H_0: \text{need to succeed is independent of anxiety level} \]

Check the condition

Why: the smallest expected count, low need with high anxiety.

\[ \frac{52 \times 57}{400} = 7.41 \ge 5 \]

Build the expected table

Why: row times column over 400, each row in turn.

\[ \text{high need: } 22.09, \;36.81, \;49.21, \;24.41, \;22.48 \]

\[ \text{medium need: } 27.50, \;45.84, \;61.28, \;30.40, \;27.98 \]

\[ \text{low need: } 7.41, \;12.35, \;16.51, \;8.19, \;7.54 \]

Check each expected row against its margin before going on: 155, 193 and 52. Then compute the fifteen contributions, one per cell; the heat map on the next slide shows each of them in its place.

Add the contributions row by row

Why: fifteen terms of observed minus expected, squared, over expected.

\[ 19.12 + 3.98 + 25.31 = 48.42 \]

The low-need row, the smallest row in the table, gives the largest share of the statistic. Small rows are not protected from misfit; dividing by small expected counts makes their gaps count heavily, which is why the condition of at least five matters there most.

Find df and the p-value

Why: three rows and five columns; right tail, by software or calculator.

\[ df = (3-1)(5-1) = 8, \quad P(\chi^2_8 > 48.42) \approx 8.2 \times 10^{-8} \]

Figure (svg): A chi-square curve with 8 degrees of freedom from 0 to 52. A dashed red line at 15.51 marks the 5 percent cutoff with the region beyond shaded red. A yellow line marks the statistic 48.42 far out in the right tail, where the curve is indistinguishable from the axis, labelled p-value about 0.00000008.

The curve's mean is 8; the statistic is six times that and three times the cutoff. The tail beyond it is far too thin to draw.

Decision: the p-value is far below 0.05, so reject the null. In context: there is very strong evidence that, among De Anza students, need to succeed in school and anxiety level are related. Part 4 asks how.

Check with the yardstick

Why: the curve's mean is 8 and the five percent cutoff 15.51; a statistic of 48.42 is six times the mean and three times the cutoff, so a tiny p-value is right.

\[ 48.42 > 15.51 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 578 — Example 11.7, completed

46. How need and anxiety are related

Picture it

Rejecting independence says the factors are related but not how. Draw the fifteen contributions where they sit, orange for more observed than expected and blue for fewer, and the shape of the relationship appears.

Figure (svg): A three by five grid of Example 11.7's fifteen contributions, coloured orange where more students were observed than expected and blue where fewer. High need: 7.55 orange at high anxiety, 0.73 orange, 0.29 orange, 3.63 blue, 6.92 blue at low anxiety. Medium need: 3.28 blue, 0.10, 0.05, 0.22 and 0.32 orange. Low need: 1.57 blue, 4.37 blue, 1.84 blue, 5.66 orange, 11.87 orange at low anxiety.

Orange runs from top-left to bottom-right: high need goes with high anxiety and low need with low anxiety, more often than independence allows. The corners carry the test.

The orange cells run along the diagonal from high-high to low-low; the blue cells sit in the opposite corners. High need goes with high anxiety, and low need with low anxiety, more often than independence allows. The single biggest term, 11.87, is low need with low anxiety: 17 students where 7.54 were expected.

That diagonal pattern is the useful conclusion. A report that said only that the factors are dependent would leave a reader to guess the direction; this one says need and anxiety rise together. It still says nothing about which, if either, causes the other.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 578 — Example 11.7, computed per cell

47. Naming the cells: the signed residual

Concept

A contribution, observed minus expected squared over expected, has lost its sign. To report which way a cell leans, take the square root back with its sign. The result is the cell's residual: the gap measured in units of the cell's natural wobble.

\[ \text{residual} = \frac{O - E}{\sqrt{E}}, \qquad \text{residual}^2 = \frac{(O - E)^2}{E} \]

Work the biggest cell of Example 11.7, low need with low anxiety: 17 observed against 7.54 expected.

\[ \frac{17 - 7.54}{\sqrt{7.54}} = \frac{9.46}{2.746} = 3.45 \]

Its square, 11.87, is the contribution you saw on the heat map, so nothing new was computed: the residual simply keeps the direction. Now do the opposite corner, high need with low anxiety, 10 observed against 22.475 expected.

\[ \frac{10 - 22.475}{\sqrt{22.475}} = \frac{-12.475}{4.741} = -2.63 \]

A rough guide: residuals beyond about 2 in size mark the cells that drive the result. Here they are high need with high anxiety, at 2.75, the two low-anxiety corners, and low need with med-low anxiety, at 2.38, plus low need with med-high anxiety on the negative side. Those are the cells to name in a conclusion.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 578 — Example 11.7, cell by cell

48. Trap: dependent means one causes the other

Trap

The trap

After rejecting independence in Example 11.7, a report concludes:

\[ p \approx 8 \times 10^{-8} \Rightarrow \]

a high need to succeed causes anxiety, so the college should lower expectations to reduce anxiety.

Wrong. The test found an association, nothing more.

The fix

The students were sampled and measured, not assigned a level of need. The arrow could run either way: anxious students might report more need. Or a third factor, such as a heavy course load, could raise both.

\[ H_a: \text{dependent} \ne \text{causal} \]

A fair conclusion: there is strong evidence that need to succeed and anxiety level are related among these students, with the two tending to rise together.

Showing cause needs an experiment that assigns the factor at random, which a survey cannot do.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 578 — Example 11.7

49. Trap: not rejecting proves independence

Trap

The trap

A test on a small survey gives a p-value of 0.40. The write-up says:

\[ p = 0.40 > 0.05 \]

so the two factors are independent, and the study has shown it.

Wrong. Failing to reject is not evidence for the null.

The fix

A large p-value says the data are consistent with independence. They may also be consistent with a real but modest relationship that a small sample cannot detect.

\[ \text{do not reject } H_0 \ne \text{accept } H_0 \]

Say it in the book's frame: there is not sufficient evidence to conclude that the factors are dependent.

The statistic grows in proportion to the sample size for a fixed pattern, so a larger sample might well reject.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §9.4 and §11.3 — the conclusion of a hypothesis test

50. Evidence is not strength: the sample size effect

Concept

Take the study-time table from Part 3 and keep its row percentages exactly as they are, but imagine surveying half as many students, or twice as many. Every count scales, every expected count scales, and so does the statistic.

\[ \frac{(mO - mE)^2}{mE} = m \cdot \frac{(O - E)^2}{E} \]

Multiply every count by m and each contribution is multiplied by m. So the statistic grows in direct proportion to the sample size, while the pattern in the table stays put.

\[ n = 100: \; 3.37, \; p = 0.186 \qquad n = 400: \; 13.48, \; p = 0.0012 \]

Figure (svg): A straight line rising from the origin showing the independence statistic for the study-time table against the total sample size, from 0 to 600 students, when the row percentages stay exactly the same. A dashed red horizontal line at 5.991 marks the 5 percent cutoff on 2 degrees of freedom; the line crosses it at about 178 students. Dots mark 100 students at 3.37, 200 at 6.74 and 400 at 13.48.

The pattern in the table never changes; only the sample size does. Below about 180 students it is not significant, above it it is. The p-value measures evidence, not the size of the relationship.

With 100 students the same pattern is nowhere near significant; with 400 it is overwhelming. The relationship did not get stronger. The evidence did, because more data make a fixed difference harder to blame on chance.

Two lessons follow. A small p-value from a huge survey can come from a difference too small to matter, so always look at the table's percentages before calling a relationship important. And a large p-value from a small survey, like the trap before this slide, may simply mean too few people were asked.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3 — the statistic, at three sample sizes

51. Try It 11.7: expected jobs in 2020

Worked example

Using the jobs table from Try It 11.6, how many services-providing jobs are expected in 2020, and how many nonagriculture wage and salary jobs, if sector and year were independent? The counts are in thousands of jobs.

Services-providing in 2020

Why: row total 35,127, column total 31,372, grand total 86,590.

\[ E = \frac{35{,}127 \times 31{,}372}{86{,}590} \]

Evaluate

Why: multiply, then divide once.

\[ = \frac{1{,}102{,}004{,}244}{86{,}590} \approx 12{,}726.69 \]

The numbers are large because the table counts thousands of jobs, but the formula does not care about scale. With counts this big, every expected count is far above five, and even tiny percentage shifts between years would produce a huge statistic.

Nonagriculture wage and salary in 2020

Why: row total 41,305.

\[ E = \frac{41{,}305 \times 31{,}372}{86{,}590} \approx 14{,}965.01 \]

In context: if the mix of sectors had stayed the same across the three years, about 12,727 thousand services jobs would be expected in 2020; the table shows 13,068 thousand, a little more. About 14,965 thousand wage and salary jobs would be expected, against 15,018 thousand observed.

The arithmetic is fine, but remember the warning from Try It 11.6: the wage and salary row double-counts the other two, so its expected count describes a category that should not be in the table. The services figure stands on its own.

Check by the share route

Why: 2020 holds 31,372 of 86,590 jobs, about 36.2 percent; that share of the services row should match.

\[ 0.36231 \times 35{,}127 \approx 12{,}727 \quad \checkmark \]

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 578 — Try It 11.7

52. What a rejection does and does not show

Sorting

Example 11.6 rejected independence of hours and volunteer type at the 5 percent level. Sort each statement by whether that result supports it.

Before sorting, recall exactly what was tested: whether the distribution of hours is the same across the three volunteer types in the population. Anything beyond that, such as causes, probabilities of hypotheses or how large the effect is, needs more than the test.

Sort into buckets

Sort each statement about Example 11.6 by whether the test result supports it.

supported by the result
hours volunteered and volunteer type are associated in this population; community college students volunteered 1–3 hours more often than independence predicts; if the factors were independent, a table this far from expected would occur about 1.1% of the time
not supported
being a community college student causes people to volunteer fewer hours; there is a 1.13% chance that the two factors are independent; the relationship between type and hours is strong
yes
Association, the direction read from the observed and expected counts, and the correct meaning of the p-value all follow from the test and the table.
no
Causation needs an experiment; a p-value is not the probability that the null is true; and a small p-value measures evidence, not the strength of the relationship.

The p-value statements are the subtle pair. The p-value is computed assuming independence, so it cannot also be the probability of independence. It answers: if the null were true, how surprising would these data be?

And strength is a separate matter. With a large enough sample, even a tiny difference between the row shapes produces a small p-value. The heat map, not the p-value, shows how big the departures are.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 576-577 — Example 11.6

53. Phones, speeding and what a survey can show

Real world

Back to the drivers of Example 11.5. Suppose a full table of the 755 drivers rejected independence, with more phone users holding violations than the 28 expected. A city council wants to cite the result in support of a ban on phone use while driving.

Discussion prompt

What can the survey honestly support, what can it not, and what kind of study would be needed to show that phone use causes speeding violations?

This is the ordinary situation for a test of independence: the data are observational, two factors measured on the same people. The test is still useful. An association is a reason to investigate and sometimes a reason to act, but it should be reported as an association.

Notice also what the council would need beyond the test: the size of the difference in violation rates between phone users and others, read from the table, because a ban is justified by a large effect, not merely by a small p-value.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Example 11.5

54. Independence against goodness of fit

Section

Part 5

55. Same statistic, different source of E

Concept

Put Section 11.2 and this section side by side. The statistic is literally the same sum of squared gaps over expected counts, and both tests are right-tailed. What differs is where the expected counts come from, and so how many cells are free.

Figure (svg): Two panels. Left, goodness of fit: a box labelled outside claim, a proportion for each cell, with an arrow down to one row of five expected cells, and the rule E equals n times p, df equals k minus one. Right, independence: a three by three grid of expected cells with dashed row totals R1 to R3 beside it and column totals C1 to C3 below it, and the rule E equals R times C over n, df equals rows minus one times columns minus one.

Same statistic, different source. On the left the expected counts arrive from outside; on the right they are built from the table's own margins.

In a goodness-of-fit test the claim comes from outside the data: a national distribution, equal shares, a genetic ratio. In a test of independence nothing outside is claimed except unrelatedness; the expected counts are built from the table's own margins.

\[ \text{fit: } E = n p_i, \; df = k - 1 \qquad \text{independence: } E = \frac{R_i C_j}{n}, \; df = (r-1)(c-1) \]

The quick way to tell them apart on a problem: is there one categorical variable and a claimed distribution, or two categorical variables measured on the same individuals? The first is fit, the second independence.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.2 and §11.3, pp. 565 and 574 — the two tests

56. Two chi-square tests, compared

Comparison

Fill in the blanks to finish the comparison. Each blank is one word or one short formula.

Fill each blank from the reasoning, not from memory: ask what the expected counts are built from, and how many cells that leaves free.

Comparison matrix

goodness of fit (§11.2)independence (§11.3)
variablesone categoricaltwo categorical
expected countsn × p, from a claimrow*column/n
degrees of freedomk-1(r − 1)(c − 1)
tailrightright
conditionevery E ≥ 5every E >= 5

Read the table by rows. Two rows are the same for both tests: the tail and the condition. The other three all differ for one reason: independence has two variables, so the expected counts come from two sets of margins, and the margins fix a whole block of cells rather than one.

Section 11.4's test for homogeneity, which compares the distribution of one variable across two populations, uses exactly the right-hand column. The arithmetic is identical; only the sampling design and the wording of the hypotheses change.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3 and §11.4, pp. 574-578 — independence, and the start of homogeneity

57. Fit or independence?

Sorting

For each study, decide which chi-square test it calls for. Ask how many categorical variables there are, and whether the expected distribution is claimed from outside.

Sort into buckets

Sort each study by the chi-square test it calls for.

goodness of fit: one variable, a claimed distribution
are a die's six faces equally likely, from 120 rolls?; do this year's blood types match the published national percentages?; does a coin pair give 0, 1 and 2 heads in the ratio 1 : 2 : 1?
independence: two variables, one sample
is music preference related to age group, from one survey of 500 adults?; is volunteer type related to hours volunteered?; is anxiety level related to need to succeed?
fit
One categorical variable, with expected shares supplied by a claim: equal faces, national percentages or a probability model.
ind
Two categorical variables recorded on the same individuals, with no claimed distribution; the expected counts come from the margins.

The word related is a strong signal for independence, but read the design, not only the wording. If the two variables are measured on the same people from one sample, it is independence; if one variable is compared with a published distribution, it is goodness of fit.

The coins are worth a second look: two coins sound like two variables, but the question is about one variable, the number of heads, against a claimed ratio. That was Example 11.4 in Section 11.2.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.2 and §11.3 — the two tests

58. Putting it together

Section

Part 6

59. Pattern: any test of independence, in order

Pattern

Every test in this section ran through the same sequence. The arithmetic is routine; the decisions at the start and the sentence at the end are where the marks are.

Follow the diagram from the observed table to the conclusion. The single check box is the only place the procedure can stop: if an expected count is below five, the chi-square curve cannot be trusted and you go back for more data or merge categories before computing anything else.

Figure (svg): A flow diagram. A box for the two-way table of observed counts leads to a box for row and column totals, then to expected counts, row times column over n. A check box asks whether every expected count is at least 5; a red arrow labelled no leads down to a box saying the test is not valid, collect more data or merge categories. A green arrow labelled yes leads to the statistic, summed over every cell, then down to the degrees of freedom, rows minus one times columns minus one, then left to the right-tail p-value and finally to a conclusion in context, related or not, never causes.

Everything before the check builds the expected table from the data's own margins. Everything after it is the goodness-of-fit routine you already know, with a new df rule.
  1. Recognise two categorical variables on the same individuals, in a two-way table of counts.
  2. Hypotheses in words: the factors are independent; the factors are dependent.
  3. Expected counts: row total times column total over n, kept to two decimals; check every row and column adds back to its margin.
  4. Condition: every expected count at least 5; check the smallest row crossed with the smallest column.
  5. Statistic: the sum of (O − E)²/E over every cell; df = (r − 1)(c − 1).
  6. Right-tail p-value, decision, and a conclusion in context: related or not, with the direction from the cells, never causes.

\[ E = \frac{R \cdot C}{n}, \qquad \chi^2 = \sum \frac{(O - E)^2}{E} \]

\[ df = (r-1)(c-1), \qquad p = P(\chi^2_{df} > \chi^2_{\text{obs}}) \]

Most wrong answers here are right arithmetic on the wrong thing: a probability reported as a count, cells minus one used for the df, the condition checked on observed counts, or an association reported as a cause. Each has a one-line check, and the pattern puts each check where it belongs.

The two ends of the pattern deserve the most care. At the start, make sure you have two variables on the same individuals, not one variable against a claim. At the end, the sentence names the population, the factors and the direction, and stops short of cause.

60. Check: one expected count

Check

Build the expected count from the two totals and the grand total. Then ask whether the answer is a sensible number of people.

Of the 500 voters, 200 form the row and 180 the column. Try the share route first: what fraction of all voters favour the measure, and what is that fraction of the younger voters?

Check your understanding

A survey of 500 voters finds 200 are under 40 and 180 favour a ballot measure. If age group and opinion are independent, how many voters under 40 are expected to favour the measure?

  • A. 72 (correct)
  • B. 0.144
  • C. 36,000
  • D. 380

Answer: A

Why: Multiply the row total by the column total and divide by the grand total once: 200 times 180 is 36,000, and 36,000 over 500 is 72. As a share, 180 out of 500 is 36 percent, and 36 percent of 200 is 72.

Why B tempts people
That is the probability of both, 0.4 times 0.36. It must be multiplied by the 500 voters to become a count.
Why C tempts people
That is the product of the totals before dividing by the grand total. No cell can exceed its own row total of 200.
Why D tempts people
That adds the two totals. Under independence the probabilities multiply; they are never added.

Every wrong option here comes from one step of the formula done wrongly or skipped. The size check catches all three: an expected count must be positive and no larger than its row total or its column total.

In context: if age and opinion were unrelated, about 72 of the 200 younger voters would favour the measure. A test would ask whether the observed number is too far from 72, together with the other three cells, to be chance.

61. Check: degrees of freedom

Check

Count categories, not people, and multiply.

This is the rule that most often goes wrong under exam pressure, because Section 11.2 made cells minus one feel automatic.

A table of 1,000 people has four rows and five columns. Before you look at the options, say which numbers in the question cannot affect the answer.

Check your understanding

A survey of 1,000 shoppers is classified by four age groups and five preferred payment methods. What are the degrees of freedom for a test of independence?

  • A. 12 (correct)
  • B. 19
  • C. 999
  • D. 7

Answer: A

Why: Rows minus one times columns minus one: three times four is twelve. The sample size never enters, and the two counts multiply because each extra row brings one free cell per column but the last.

Why B tempts people
That is the goodness-of-fit rule, twenty cells minus one. A two-way table fixes every row and column total, not just the grand total.
Why C tempts people
That is the sample size minus one. Degrees of freedom here count free cells, never people.
Why D tempts people
That adds three and four. The free cells form a three by four block, which holds twelve cells.

The thousand shoppers are there to tempt you. Only the shape of the table matters: four by five, so a free block of three by four.

If you are unsure, sketch the grid, shade the block one row short and one column short, and count it. That picture never gives the wrong rule.

And use the size check from the slider: with twelve degrees of freedom the curve is centred near 12, so a statistic in the low teens would be ordinary for this table and a statistic of forty would be strong evidence.

62. Check: the conclusion

Check

Decide first what the test can establish, then read the options.

The data are observational: people were surveyed, not assigned.

That single fact limits the conclusion more than any number in the question does. Read every option against it.

Check your understanding

A survey of 600 adults finds a test of independence between exercise frequency and sleep quality with p-value 0.003. Which conclusion at the 5 percent level is correct?

  • A. There is strong evidence that exercise frequency and sleep quality are related among adults like these. (correct)
  • B. Exercising more causes better sleep.
  • C. There is a 0.3% chance that exercise and sleep are independent.
  • D. Do not reject the null; the factors are independent.

Answer: A

Why: The p-value is below 0.05, so reject independence. The data are a survey, so the conclusion is an association in the population sampled, stated in context, with no claim about cause.

Why B tempts people
A survey cannot establish cause: people who sleep well may have more energy to exercise, or a third factor may drive both.
Why C tempts people
The p-value assumes independence; it is the chance of data this extreme if the factors were independent, not the chance that they are.
Why D tempts people
The p-value 0.003 is below alpha, so the decision is to reject. And even a non-rejection would not prove independence.

Each wrong option is one of the traps from this deck: causation from a survey, the p-value read as the probability of the null, and the decision rule reversed.

A full answer would add the direction from the table, for example that frequent exercisers reported good sleep more often than independence predicts, because a reader will want to know how the two are related.

63. Explain why the margins come back

Explain it to yourself

The fact that an expected table reproduces the observed row and column totals was your main arithmetic check all through this lesson. Explaining it in your own words tests whether the formula has landed.

Discussion prompt

Explain in two or three sentences why the expected counts in any row always add up to that row's observed total, and why that makes a good check on your arithmetic.

A strong answer names the column shares adding to one. A very strong one adds why that matters for the test: the expected table is the same people with the same margins, rearranged as independence would place them, so the only thing the statistic can measure is how the inside of the table differs.

The same fact explains the degrees of freedom. Because the margins are shared, they fix every cell outside the free block, which is why the count is rows minus one times columns minus one.

64. Exit ticket: music students on the honor roll

Exit ticket

Return to Try It 11.5: 300 students, 50 music students, 97 on the honor roll. Suppose 24 of the music students are on the honor roll; these interior counts are ours, not the book's.

Work it exactly as the volunteers were worked: expected counts from the margins, the condition, the statistic cell by cell, the degrees of freedom, the right-tail p-value and a sentence in context.

honor rollnottotal
music242650
not music73177250
total97203300

Discussion prompt

Build the expected table, compute the statistic and its degrees of freedom, and state a conclusion at the 5 percent level in context.

Check yourself on the four cells: the gaps are 7.83 in two cells and minus 7.83 in the other two, because a two by two table has a single free cell. Every expected count is above five, the smallest being 16.17, so the test was allowed.

If you got a statistic of about 3.80, you stopped at the music, honor-roll cell. Every cell of the table contributes, and the other three add almost three more.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, p. 575 — Try It 11.5, extended

65. Recap

Recap

A test of independence asks whether two categorical factors, measured on the same individuals, are related. It uses the goodness-of-fit statistic on a contingency table, with expected counts built from the table's own margins under the assumption that the factors are unrelated.

ideaformularead it as
hypothesesH₀: independent; Hₐ: dependentin words: there is no parameter
expected countE = (row total)(column total) / nfrom P(A and B) = P(A)P(B), times n
marginsexpected rows and columns add to observed totalsthe free arithmetic check
conditionevery E ≥ 5smallest row × smallest column decides
statisticχ² = Σ (O − E)²/E over all r·c cellssame sum as goodness of fit
df(r − 1)(c − 1)the free block once margins are fixed
p-valueP(χ² > observed), always right tailany misfit makes χ² larger
conclusionrelated or not, with the directionassociation, never causation

The book's examples carried all of it: 28.28 expected phone-using violators; the volunteers' 12.99 on four degrees of freedom with p equal to 0.0113; and the anxiety table's 48.42 on eight, with need and anxiety rising together. In every case the evidence was read from the cells as well as the total.

The Introductory Business Statistics text treats the same test in its own §11.4, with business contexts, if you want more practice in a different setting. Section 11.4 of this book turns to the test for homogeneity, which runs the same arithmetic to compare two populations.

OpenStax Introductory Statistics 2e, §11.3 Test of Independence §11.3, pp. 574-578 — the whole section

OpenStax Introductory Business Statistics 2e, §11.4 Test of Independence §11.4 Test of Independence — the same test in business contexts

Sources

  1. OpenStax Introductory Statistics 2e, §11.3 Test of Independence — Illowsky & Dean, OpenStax / Rice University, CC BY 4.0, pp. 573-578
  2. OpenStax Introductory Business Statistics 2e, §11.4 Test of Independence — Illowsky & Dean, OpenStax / Rice University, CC BY 4.0

Want this taught 1-on-1? Alexander tutors Statistics — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108