A summary section, and a necessary one. The chi-square statistic has now been used in three different circumstances, and since all three share the statistic, the right tail and the at-least-five condition, nothing in the arithmetic distinguishes them. The book's list separates them by the study instead, and two counts settle nearly every case: how many populations were sampled, and how many questions were asked. A goodness-of-fit test has one population, one question, and a known distribution to test against; a test of independence has one population and two questions, arranged in a contingency table; a test for homogeneity has two populations, one question, and no known distribution at all. The surest signal of all is how the hypotheses are worded, and this lesson works through the book's three pairs.
Subject: Statistics · 64 slides · symbolic lesson
Open the interactive version of this deck
Title
Statistics · Chapter 11 — The Chi-Square Distribution
One statistic, three questions: which test fits the study?
Objectives
Sections 11.2 to 11.4 taught three tests that share one formula, one curve and one right tail. Done correctly, the arithmetic looks almost identical in all three. That is exactly why students pick the wrong test: nothing in the numbers tells you which one you are running. This section is the book's answer, a short summary that sorts the three by the study, not by the arithmetic.
You will run every example from the chapter again, but this time the first step of each one is the routing decision. By the end, choosing the test should take you two questions and ten seconds, and you will know exactly which mistakes change the answer and which only change the sentence you write at the end.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the section this deck covers
Warm-up
Section 11.3 built expected counts for a contingency table from its margins. Recall the rule on Example 11.6, the 839 adult volunteers.
Discussion prompt
Of the 839 volunteers, 255 were community college students and 298 gave one to three hours a week. If type and hours were unrelated, how many community college students would you expect in the one-to-three-hour column?
Now the puzzle this lesson solves. Section 11.4 told you to compute a test for homogeneity in exactly the same way: the same row-times-column rule, the same sum, the same curve. So if someone hands you a finished two-way table and its statistic, you cannot tell from the numbers which of the two tests they ran.
The difference lives in how the data were collected and in what the hypotheses say. Keep that in mind: every slide that follows starts from the study, not from the table.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, pp. 575-577 — Example 11.6 and the expected-count formula
Section
Part 1
Concept
The book opens the section with one sentence: you have seen the chi-square test statistic used in three different circumstances. Here is that statistic once more. It is the same sum in all three tests.
\[ \chi^2 = \sum \frac{(O - E)^2}{E} \]
Every test in Sections 11.2 to 11.4 compared observed counts with expected counts, squared each gap, divided by the expected count, and added. A large total means the data sit far from what the null hypothesis predicts, so all three tests reject in the right tail of a chi-square curve.
Because the arithmetic is shared, the arithmetic cannot help you choose. What differs is the question the study asks. The book's summary gives three bullets, one per test, and each bullet answers the same three things: what the test decides, what the study looks like, and how the hypotheses read.
| test | decides whether… | study looks like |
|---|---|---|
| goodness of fit | a population fits a known distribution | one population, one question |
| independence | two variables are independent | one population, two questions |
| homogeneity | two populations share one distribution | two populations, one question |
Read the last column first. That is where the routing decision is made, and the rest of this lesson is practice at reading it off a description.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the opening sentence and the three bullets
Notation
Since the statistic is the one thing every test has in common, read it piece by piece once, and notice which piece is the only one that depends on the test. Hover over each label.
Annotate
On: \( \chi^2 = \sum_{\text{cells}} \frac{(O - E)^2}{E} \)
Read it as a sentence: for every cell, take how far the data missed the null's prediction, square it, scale it by the prediction, and add up. A small total means the null predicted the table well; a large total means it did not.
Now notice the one piece the annotations flagged. Where E comes from is decided by the test, and the test is decided by the study. Get the routing right and the rest of this formula is the same mechanical sum every time.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2-§11.3, pp. 565-574 — the goodness-of-fit and independence statistics
Concept
The first bullet. Use the goodness-of-fit test to decide whether a population with an unknown distribution fits a known distribution. The study has a single qualitative survey question, or a single outcome of an experiment, from a single population.
\[ H_0: \text{The population fits the given distribution.} \]
\[ H_a: \text{The population does not fit the given distribution.} \]
Notice the two sides of the comparison. One is unknown: the population you sampled. The other is known: a distribution you write down before collecting any data. The known side supplies the expected counts directly, as the sample size times each given proportion.
\[ E_i = n \cdot p_i \]
The book names three typical uses. You test whether the population is uniform, with all outcomes equally frequent; whether it is normal; or whether it is the same as another population whose distribution is known, such as national figures from a census. All three uses have a fully specified distribution on the known side, and that is the defining feature.
goodness-of-fit test — A chi-square test of whether one population, measured on one categorical variable, fits a distribution that is fully specified in advance.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the goodness-of-fit bullet
Concept
The second bullet. Use the test for independence to decide whether two variables, which the book also calls factors, are independent or dependent. The study has two qualitative survey questions, or two experiments, and the answers are cross-classified into a contingency table.
\[ H_0: \text{The two variables (factors) are independent.} \]
\[ H_a: \text{The two variables (factors) are dependent.} \]
The key picture is one sample in which every subject answers two questions. In Example 11.6, each of 839 volunteers was classified twice: by type of volunteer and by hours given. The rows and columns are the two questions, not two populations. Nothing is known in advance, so the expected counts come from the table's own margins.
\[ E = \frac{(\text{row total})(\text{column total})}{\text{grand total}} \]
The goal, in the book's words, is to see whether the two variables are unrelated or related. Rejecting the null says the answer to one question carries information about the answer to the other, for subjects in that one population.
test of independence — A chi-square test of whether two categorical variables, both measured on each subject of one sample, are independent.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the independence bullet
Concept
The third bullet. Use the test for homogeneity to decide whether two populations with unknown distributions have the same distribution as each other. The study gives a single qualitative survey question, or experiment, to two different populations.
\[ H_0: \text{The two populations follow the same distribution.} \]
\[ H_a: \text{The two populations have different distributions.} \]
Here neither side of the comparison is known. You draw two separate samples, ask both the same question, and ask whether the two sets of answers could have come from one shared distribution. Since that shared distribution is unknown, you estimate it by pooling both samples, which is why the expected counts use the same row-times-column rule as independence.
The book's examples are men against women, before against after, east against west. The word that matters in the bullet is unknown: both distributions are unknown. If one of them were known, you would be back to goodness of fit, and Part 4 shows what goes wrong when a sample is mistaken for a known distribution.
test for homogeneity — A chi-square test of whether two populations, each sampled separately and asked the same categorical question, share the same distribution.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the homogeneity bullet
Picture it
Here are the three bullets as pictures. Each oval is a population you sampled from; each card is a question you asked every subject. Look at the counts before you read the labels.
Figure (svg): Three panels. Goodness of fit: one oval of people labelled one population, one question card, and a dashed box of bars labelled a known distribution. Independence: one oval, two question cards, and a small three by three grid labelled a contingency table. Homogeneity: two ovals labelled population A and population B, one question card labelled the same question, and the words nothing known, compare A with B.
Goodness of fit is one oval and one card, with a known distribution sitting outside the study as the yardstick. Independence is one oval and two cards. Homogeneity is two ovals sharing one card. No two panels match on both counts, so the pair of counts identifies the test.
\[ (\text{populations}, \text{questions}): \quad (1, 1), \quad (1, 2), \quad (2, 1) \]
One more feature separates the first panel from the third. Both can be described as comparing one group with another. The difference is whether the other side is a fixed, known distribution or a second sample with its own sampling error. Hold on to that; it is the subject of a trap later in the lesson.
And the fourth combination, two populations each asked two questions, has no panel. It falls outside this chapter: none of the three tests is built for it.
Notation
The surest signal of which test is running is the subject of its null hypothesis. Each of the book's three nulls is about a different kind of thing. Hover over each piece.
Annotate
On: \( \text{fits given} \quad \text{independent} \quad \text{same distribution} \)
This matters most when a problem's description of its sampling is thin. A table and a question such as are the groups different does not route itself, but once you can write the null in one of these three forms, the subject of the sentence tells you the test.
Notice also that each alternative is simply the negation of its null, with no direction. That is why all three tests use only the right tail: any departure from the null, in any cell and in either direction, makes the statistic bigger.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the three pairs of hypotheses
Worked example
Before running any test again, route five studies from Sections 11.2 to 11.4. For each one, count the populations sampled and the questions asked, then name the test. Nothing else is needed.
For goodness of fit there is one extra thing to confirm, because one population with one question is not enough on its own: the comparison distribution must be fixed in advance. Watch for it in the first two studies, where it is a uniform claim and a set of national figures.
The habit to build: read the sampling sentence, not the table. A table with three rows might be three populations or one population answering a three-way question, and only the description says which.
Example 11.2: 60 managers, which weekday has most absences
Why: one sample, one question, tested against equal frequencies, which are fixed in advance.
\[ (1, 1) + \text{known uniform} \;\Rightarrow\; \text{goodness of fit} \]
Example 11.3: 600 far-western families, number of streaming services
Why: one sample, one question, compared with published national percentages.
\[ (1, 1) + \text{known percentages} \;\Rightarrow\; \text{goodness of fit} \]
Example 11.6: 839 volunteers, type of volunteer and hours
Why: one sample, and each person answers two questions.
\[ (1, 2) \;\Rightarrow\; \text{independence} \]
Example 11.8: 250 men and 300 women, living arrangements
Why: two separate samples, one question asked of both.
\[ (2, 1) \;\Rightarrow\; \text{homogeneity} \]
Example 11.9: voters surveyed before and after an earthquake
Why: two separate surveys, one question about the candidate.
\[ (2, 1) \;\Rightarrow\; \text{homogeneity} \]
Every routing came from the sampling description alone; none of them needed a single count from a table. Notice too that the volunteers' table has three rows, yet it is one population: the rows are answers to a question, not separate samples.
Check against the book's own hypotheses
Why: each example states its null, and its subject matches the route.
\[ \text{11.2: fits uniform} \quad \text{11.6: independent} \quad \text{11.8: same distribution} \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2-§11.4, pp. 568-581 — Examples 11.2, 11.3, 11.6, 11.8 and 11.9
Sorting
Each item describes a study. Count populations and questions, then sort it to its test. Where a known distribution is mentioned, notice that it is not a second sample.
Sort into buckets
Sort each study by the chi-square test that fits it.
The pets and the coins are the two to slow down on. Both compare a sample with something else, which can sound like two populations. But the national pet percentages and the fair-coin probabilities are given, not sampled, so there is only one sample in each study.
The music students are the opposite trap: the table has two rows, music and not music, which looks like two groups. But the 300 students were one sample, each asked two yes-or-no questions, so it is independence. These are Try Its 11.3, 11.5, 11.8 and 11.9 and Examples 11.4 and 11.7.
Prediction
A classmate hands you a two-row, four-column table of counts and its chi-square statistic, 10.13 on 3 degrees of freedom, but nothing about how the data were collected. Commit to an answer before reading on.
Predict first
Which test produced it?
Correct: You cannot tell from the table alone
Why: Independence and homogeneity build the same expected counts, the same statistic and the same degrees of freedom from a two-way table. Two rows could be two populations or two answers to one question in a single sample, so only the study's description decides.
\[ \text{same } E, \quad \text{same } \chi^2, \quad \text{same df}, \quad \text{same } p \]
These are in fact the numbers of Example 11.8, men and women sampled separately, which makes it homogeneity. If instead 550 students had been sampled at once and each asked two questions, sex and living arrangement, the identical table would be a test of independence.
Goodness of fit is ruled out for a different reason: with eight cells it would have seven degrees of freedom, not three. That is the one place where the arithmetic does give a hint, and Part 5 returns to it.
Section
Part 2
Concept
Goodness of fit stands apart from the other two tests because one side of its comparison is not data. Before you collect anything, you can write down exactly what proportion of the population the null puts in each category. That is what the book means by a known distribution.
| source of the proportions | example | known? |
|---|---|---|
| a symmetry or equal-chance claim | absences equally likely on each of 5 days: 1/5 each | yes |
| probability theory | two fair coins: 1/4, 1/2, 1/4 heads | yes |
| a published census or national figure | streaming services: 10, 16, 55, 11, 8 percent | yes |
| a model with stated parameters | a normal distribution with a given mean and sd | yes |
| another sample's percentages | 300 women's living arrangements | no |
The first four rows are fixed numbers: nobody measured them from your data, and they carry no sampling error of their own. The last row is different in kind. Percentages from a sample of 300 women are estimates, and a second sample of 300 would give slightly different ones.
\[ E_i = n \cdot p_i \quad \text{only when every } p_i \text{ is fixed in advance} \]
So the test for whether a comparison is goodness of fit is simple: could you have written the expected proportions on the board before any data existed? If yes, it is goodness of fit. If the proportions have to be measured from another group, the comparison is between two samples, and that is homogeneity.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — uniform, normal, or the same as a population with a known distribution
Worked example
A random sample of 60 managers each named the weekday with the most employee absences: 15 Monday, 12 Tuesday, 9 Wednesday, 9 Thursday, 15 Friday. Do the days occur with equal frequencies? Test at the 5 percent level.
This is the simplest goodness-of-fit test there is, so use it to see the routing at work. The phrase equal frequencies is a distribution you can write down without any data, one fifth per day, and that single observation decides the test, the expected counts and the degrees of freedom before you add anything up.
Route the study
Why: one sample of managers, one question, against equal frequencies fixed in advance.
\[ (1, 1) + \text{uniform} \;\Rightarrow\; \text{goodness of fit} \]
State the hypotheses in the book's form
Why: the given distribution is the uniform.
\[ H_0: \text{absent days fit a uniform distribution} \quad H_a: \text{they do not} \]
Expected counts
Why: a uniform over five days puts one fifth of the 60 on each day.
\[ E = 60 \cdot \tfrac{1}{5} = 12 \text{ for every day} \]
Each cell's contribution
Why: Monday and Friday are 3 over, Wednesday and Thursday 3 under; Tuesday is exact.
\[ \frac{(15 - 12)^2}{12} = \frac{9}{12} = 0.75, \quad \frac{(12 - 12)^2}{12} = 0 \]
Add the five contributions
Why: four cells give 0.75 and one gives zero.
\[ \chi^2 = 0.75 + 0 + 0.75 + 0.75 + 0.75 = 3 \]
Degrees of freedom and p-value
Why: cells minus one; the right tail beyond 3.
\[ df = 5 - 1 = 4, \quad p = P(\chi^2 > 3) = 0.5578 \]
Figure (svg): A bar chart of the number of managers naming each weekday as the day of most absences: Monday 15, Tuesday 12, Wednesday 9, Thursday 9, Friday 15. A dashed horizontal line at 12 marks the expected count for every day.
Decision: 0.5578 is far above 0.05, so do not reject the null. In context: from this sample of 60 managers there is not enough evidence to conclude that the days with the most absences occur with unequal frequencies across the five-day week.
Check the expected counts and the critical value
Why: the expected counts must add to the sample size, and a statistic of 3 sits well below the 5 percent cutoff for df 4.
\[ 12 \times 5 = 60 = 15 + 12 + 9 + 9 + 15, \quad 3 < 9.49 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2, pp. 568-569 — Example 11.2 and Figure 11.4
Worked example
Nationally, families have 0, 1, 2, 3, or 4 or more streaming services in the proportions 10, 16, 55, 11 and 8 percent. A random sample of 600 far-western families gave 66, 119, 340, 60 and 15. At the 1 percent level, is the far-western distribution different?
The wording sounds like a comparison of two populations, far-western families and American families, so it is worth slowing down. Only one of them was sampled. The national percentages are given as fact, so they are the known yardstick, and the test is goodness of fit, not homogeneity.
Route the study
Why: one sample of families, one question, against national percentages that are given, not sampled.
\[ (1, 1) + \text{known percentages} \;\Rightarrow\; \text{goodness of fit} \]
Expected counts
Why: the sample size times each national proportion.
\[ E = 600(0.10, 0.16, 0.55, 0.11, 0.08) = 60, 96, 330, 66, 48 \]
Gaps between observed and expected
Why: observed minus expected in each cell.
\[ O - E = 6, \; 23, \; 10, \; -6, \; -33 \]
Square and divide by E
Why: one term per cell.
\[ \tfrac{36}{60} + \tfrac{529}{96} + \tfrac{100}{330} + \tfrac{36}{66} + \tfrac{1089}{48} \]
Add the terms
Why: the last cell dominates.
\[ 0.60 + 5.51 + 0.30 + 0.55 + 22.69 = 29.65 \]
Degrees of freedom and p-value
Why: five cells minus one, not 600 minus one.
\[ df = 5 - 1 = 4, \quad p = P(\chi^2 > 29.65) = 0.0000058 \]
Figure (svg): A bar chart of each cell's contribution to the chi-square statistic for streaming services: 0 services 0.60, 1 service 5.51, 2 services 0.30, 3 services 0.55, 4 or more 22.69. The last bar towers over the rest.
Decision: the p-value is far below 0.01, so reject the null. In context: at the 1 percent level there is strong evidence that the number of streaming services among far-western families is distributed differently from the American population, chiefly because far fewer of them have four or more.
Check the totals
Why: the expected counts must add to 600, and the gaps must add to zero.
\[ 60 + 96 + 330 + 66 + 48 = 600, \quad 6 + 23 + 10 - 6 - 33 = 0 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2, pp. 569-572 — Example 11.3: 29.65 and p = 0.000006
Worked example
Two coins were flipped together 100 times: 20 times two heads, 27 heads-tails, 30 tails-heads and 23 two tails. Are the coins fair? Test at the 5 percent level.
Here the known distribution comes from probability theory rather than from a census. Fair coins make two heads a quarter of the time, one head half the time and no heads a quarter of the time. Those proportions exist before any coin is flipped, which is exactly what makes this goodness of fit.
Route the study
Why: one sequence of flips, one outcome per flip, against probabilities fixed by theory.
\[ (1, 1) + \text{fair-coin probabilities} \;\Rightarrow\; \text{goodness of fit} \]
Choose the cells as the number of heads
Why: the book combines heads-tails and tails-heads into one head.
\[ O = 23, \; 27 + 30 = 57, \; 20 \quad (0, 1, 2 \text{ heads}) \]
Expected counts under fairness
Why: a quarter, a half and a quarter of 100 flips.
\[ E = 100\left(\tfrac{1}{4}, \tfrac{1}{2}, \tfrac{1}{4}\right) = 25, \; 50, \; 25 \]
Contributions
Why: two over 25 and one over 50.
\[ \tfrac{(23 - 25)^2}{25} + \tfrac{(57 - 50)^2}{50} + \tfrac{(20 - 25)^2}{25} = 0.16 + 0.98 + 1.00 \]
Statistic, df and p-value
Why: three cells, so two degrees of freedom.
\[ \chi^2 = 2.14, \quad df = 3 - 1 = 2, \quad p = 0.3430 \]
Figure (svg): A grouped bar chart for the number of heads in 100 flips of two coins. Zero heads: observed 23, expected 25. One head: observed 57, expected 50. Two heads: observed 20, expected 25.
Decision: 0.3430 is above 0.05, so do not reject the null. In context: there is not enough evidence to conclude that the coins are unfair. That is not proof they are fair; it says only that 100 flips this close to the fair split are entirely ordinary.
Check against the critical value
Why: the 5 percent cutoff for two degrees of freedom is 5.99, and 2.14 is well short of it, matching a p-value above 0.05.
\[ 2.14 < 5.99 \quad \Leftrightarrow \quad p = 0.3430 > 0.05 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, p. 573 — Example 11.4 and Figure 11.6
Trap
After Example 11.4's coin test, a first attempt concludes:
\[ p = 0.3430 > 0.05 \]
\[ \Rightarrow \text{ the coins are fair} \]
Wrong. The test cannot prove the null.
Failing to reject means the data are consistent with fairness, not that fairness is established. Slightly biased coins would often give 100 flips just like these.
\[ \text{do not reject } H_0 \]
The book's own sentence is the model: there is insufficient evidence to conclude that the coins are not fair. The same caution applies in all three tests: no evidence of dependence, or of a difference, is not evidence of independence or sameness.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, p. 573 — Example 11.4's conclusion
Estimation
Faculty expected 100 students to fall into absence bands of 0 to 2, 3 to 5, 6 to 8 and 9 or more in the counts 50, 30, 12 and 8, after the book combined the last two bands so every expected count reaches five. A survey found 35, 40, 20 and 5.
Figure (svg): A grouped bar chart of absences per term for 100 students. 0 to 2 absences: observed 35, expected 50. 3 to 5: observed 40, expected 30. 6 to 8: observed 20, expected 12. 9 or more: observed 5, expected 8.
Predict first
Before computing, roughly where will the goodness-of-fit statistic land, given that the 5 percent cutoff for 3 degrees of freedom is 7.81?
Correct: Well above 7.81: reject the faculty's perception
Why: The lowest band is 15 short of 50, and the 6 to 8 band is 8 over an expected 12. The second gap alone gives 64 over 12, more than 5, so the total comfortably passes the cutoff.
\[ \chi^2 = \tfrac{225}{50} + \tfrac{100}{30} + \tfrac{64}{12} + \tfrac{9}{8} = 4.50 + 3.33 + 5.33 + 1.13 = 14.29 \]
\[ df = 4 - 1 = 3, \quad p = P(\chi^2 > 14.29) = 0.0025 \]
The book stops this example at the degrees of freedom; finished, it rejects the null at any usual level. In context: student absenteeism does not fit the faculty's perception, and the bars say how: students miss more class than faculty believe. Routing was again one sample, one question, and expected counts the faculty wrote down in advance.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2, pp. 565-567 — Example 11.1 and Tables 11.3-11.4
Discrimination
For each distribution a study might compare its sample against, decide whether it is known in the book's sense. Ask: could these proportions be written down before any of this study's data existed, with no sampling error of their own?
Sort into buckets
Sort each comparison distribution.
Last year's survey is the trap. It feels like an established benchmark, and people often call it the known figure. But 80 customers is a sample, and its percentages carry sampling error just as this year's do. A fair comparison of the two years is a test for homogeneity.
The census is the opposite case. It is published data, but it measures the whole population rather than a sample, so its percentages are the population's own. That is the third typical use of goodness of fit from the book's bullet.
Trap
For Example 11.3's 600 families, a first attempt takes the degrees of freedom the way earlier chapters did:
\[ df = n - 1 = 600 - 1 = 599 \]
\[ P(\chi^2 > 29.65) \approx 1 \]
Wrong. That reads a strong result as no evidence at all.
In every chi-square count test the degrees of freedom count cells, not people. The book prints the warning beside the example: df is not 600 minus one.
\[ df = 5 - 1 = 4 \]
\[ P(\chi^2 > 29.65) = 0.0000058 \]
The sample size enters only through the expected counts. The cells are what can vary freely once the total is fixed, and Part 5 draws that picture.
The habit that prevents it: before looking up a p-value, say aloud what is being counted. Five categories means five cells, whatever the sample size.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2, p. 571 — the note that df is not 600 − 1
Section
Part 3
Concept
A test of independence has no outside distribution to supply its expected counts. It builds them from the probability rule for independent events, which you met in Chapter 3. If events A and B are independent, the chance of both is the product of their chances.
\[ P(A \text{ and } B) = P(A)\,P(B) \]
Estimate each probability from the table's margins: the row total over the grand total, and the column total over the grand total. Then multiply by the grand total to turn the probability into a count.
\[ E = n \cdot \frac{\text{row total}}{n} \cdot \frac{\text{column total}}{n} \]
One n cancels against one denominator, leaving the familiar rule. It is not a new formula; it is the multiplication rule for independent events, written as a count.
\[ E = \frac{(\text{row total})(\text{column total})}{n} \]
This is also why independence must be the null hypothesis and not the alternative. Independence supplies a definite number for every cell. Dependence is a vague claim that supplies no numbers at all, so there would be nothing to compare the data with.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, p. 575 — Example 11.5 and the expected-count formula
Worked example
Of 755 drivers surveyed, 70 had a speeding violation in the last year and 305 used a cell phone while driving. If the two are independent, how many drivers are expected to have done both? Then Try It 11.5: of 300 students, 50 are music students and 97 are on the honor roll.
Both are one sample with two yes-or-no questions per person, so both are independence, and both need only the multiplication rule. The plan is the same in each: two shares, multiply, scale back up to the sample.
The two shares among the drivers
Why: each margin over the grand total.
\[ P(A) = \tfrac{70}{755} = 0.0927, \quad P(B) = \tfrac{305}{755} = 0.4040 \]
Multiply, then scale to 755 drivers
Why: independence makes the joint share a product.
\[ y = 755(0.0927)(0.4040) = \frac{(70)(305)}{755} = 28.28 \]
Figure (svg): A rectangle representing 755 drivers. A narrow orange strip at the left, 70 out of 755 of the width, is the drivers with a speeding violation. A blue band across the top, 305 out of 755 of the height, is the cell phone users. Their overlap in the top left corner is shaded yellow and labelled speeding and phone, 0.0927 times 0.4040 equals 0.0375 of 755, about 28.
The same rule for the music students
Why: row total times column total over the grand total.
\[ E = \frac{(50)(97)}{300} = \frac{4{,}850}{300} = 16.17 \]
In context: about 28 of the 755 drivers would be expected to be both speeders and phone users if the two behaviours were unrelated, and about 16 of the 300 students to be both musicians and on the honor roll. A test of independence then asks whether the observed counts sit far enough from these to rule out chance.
Check by the proportion of a proportion
Why: music students are one sixth of the sample, so under independence one sixth of the 97 honor-roll students should be musicians.
\[ \tfrac{1}{6}(97) = 16.17 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, p. 575 — Example 11.5 and Try It 11.5
Worked example
A sample of 839 adult volunteers was classified by type (community college student, four-year college student, nonstudent) and by hours given per week (1 to 3, 4 to 6, 7 to 9). Is the number of hours independent of the type of volunteer? No level is given, so use 5 percent.
The table has three rows, which might tempt you to call the volunteer types three populations. Read the description instead: one sample of 839 people, each classified twice. That makes it independence, and it means the conclusion will be a sentence about two variables among volunteers, not about three separate groups.
Route the study
Why: one sample of volunteers; each person is classified by two questions.
\[ (1, 2) \;\Rightarrow\; \text{independence} \]
Hypotheses
Why: the subject is the two variables.
\[ H_0: \text{hours and type are independent} \quad H_a: \text{dependent} \]
Margins
Why: row totals by type and column totals by hours.
\[ \text{rows } 255, 290, 294; \quad \text{columns } 298, 379, 162; \quad n = 839 \]
Expected counts, first row
Why: row total times column total over 839.
\[ \tfrac{255 \cdot 298}{839} = 90.57, \; \tfrac{255 \cdot 379}{839} = 115.19, \; \tfrac{255 \cdot 162}{839} = 49.24 \]
The other six expected counts
Why: the same rule; all nine are well above five.
\[ 103.00, \; 131.00, \; 56.00, \; 104.42, \; 132.81, \; 56.77 \]
The largest contributions
Why: community college students giving 1 to 3 hours, and 4 to 6 hours.
\[ \tfrac{(111 - 90.57)^2}{90.57} = 4.61, \quad \tfrac{(96 - 115.19)^2}{115.19} = 3.20 \]
Add all nine contributions
Why: seven more terms, from 0.03 to 2.23; keep three decimals, since two-decimal terms add to 13.01.
\[ 4.607 + 3.197 + 0.031 + 0.476 + 0.030 + 0.447 + 1.726 + 2.225 + 0.250 \]
\[ \chi^2 = 12.99 \]
Degrees of freedom and p-value
Why: rows minus one times columns minus one.
\[ df = (3 - 1)(3 - 1) = 4, \quad p = P(\chi^2 > 12.99) = 0.0113 \]
Figure (svg): Four horizontal bars, each split into the shares of volunteers giving 1 to 3, 4 to 6 and 7 to 9 hours. Community college students: 44, 38, 19 percent. Four-year college students: 33, 46, 21 percent. Nonstudents: 31, 51, 18 percent. All volunteers combined: 36, 45, 19 percent.
Decision: 0.0113 is below 0.05, so reject the null. In context: there is sufficient evidence that, among adult volunteers in this program, the number of hours given per week depends on the type of volunteer; community college students are over-represented in the shortest band.
Check the expected counts against a margin
Why: independence's expected counts reproduce every row total exactly.
\[ 90.57 + 115.19 + 49.24 = 255.00 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, pp. 575-577 — Example 11.6 and Tables 11.15-11.16
Picture it
The previous slide ended at a p-value. Here is what that number means, drawn. The curve is the chi-square distribution with four degrees of freedom: the spread of statistics you would see from samples of 839 volunteers if hours and type really were independent.
Figure (svg): A chi-square curve with 4 degrees of freedom, x from 0 to 18. A red dashed line at 9.49 marks the 5 percent critical value, with the region beyond it shaded red. A yellow line marks the observed statistic 12.99, with the small tail beyond it shaded yellow and labelled p equals 0.0113.
Most of the curve's area sits below about 8. Beyond the red dashed line at 9.49 lies the most extreme 5 percent, and a statistic there is called significant at the 5 percent level. The observed 12.99 falls inside that region, and the small yellow tail beyond it holds the p-value, 0.0113.
Notice the picture is identical in shape to the one you would draw for a goodness-of-fit test or a test for homogeneity with four degrees of freedom. The curve knows only the degrees of freedom. Everything about which test you are running has to be settled before you reach this picture, which is the point of the whole section.
Notice also what the curve cannot tell you. A large statistic says the table is far from independence; it does not say which cells are responsible, or why. For that you go back to the contributions and the stacked bars.
Worked example
A random sample of 400 De Anza students was measured on need to succeed (high, medium, low) and on anxiety level (five bands, high to low). (a) How many high-anxiety students are expected to have a high need? (b) How many low-need, medium-low-anxiety students? Then finish the test the book leaves open.
The book asks only for two expected counts, but each one is a piece of a full test, so it is worth completing. The plan: route, compute the two requested cells, confirm the smallest expected count passes the condition, and then read the result off the whole table.
Route the study
Why: one sample of students, two measurements each.
\[ (1, 2) \;\Rightarrow\; \text{independence} \]
Part (a): high need, high anxiety
Why: row total 155, column total 57, grand total 400.
\[ E = \frac{(155)(57)}{400} = \frac{8{,}835}{400} = 22.09 \]
Part (b): low need, medium-low anxiety
Why: row total 52, column total 63.
\[ E = \frac{(52)(63)}{400} = \frac{3{,}276}{400} = 8.19 \]
Smallest expected count in the table
Why: low need with high anxiety; the test needs every cell at five or more.
\[ E = \frac{(52)(57)}{400} = 7.41 \ge 5 \]
Statistic and degrees of freedom
Why: fifteen contributions; three rows and five columns.
\[ \chi^2 = 48.42, \quad df = (3 - 1)(5 - 1) = 8 \]
p-value
Why: far beyond the 5 percent cutoff of 15.51.
\[ p = P(\chi^2 > 48.42) = 0.00000008 \]
Figure (svg): A three by five grid of cells for need to succeed against anxiety level. Each cell shows observed versus expected count and its contribution to the statistic. The darkest cells are the corners: high need with high anxiety, 35 vs 22.1, contribution 7.55, more than expected; high need with low anxiety, 10 vs 22.5, contribution 6.92, fewer; low need with low anxiety, 17 vs 7.5, contribution 11.87, more.
The book prints part (a) as about 22 and part (b) as 8, rounded from 22.09 and 8.19. In context: there is overwhelming evidence that, among De Anza students, anxiety level and need to succeed are dependent; high need goes with high anxiety and low need with low anxiety.
Check one cell's contribution
Why: the darkest cell, low need with low anxiety, observed 17 against 7.54 expected.
\[ \frac{(17 - 7.54)^2}{7.54} = \frac{89.49}{7.54} = 11.87 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, p. 578 — Example 11.7 and Table 11.18
Fill the middle
Try It 11.6's employment table has a 2020 column total of 31,372 and a grand total of 86,590 jobs. Under independence of sector and year, fill in the expected number of service-providing jobs in 2020, whose row total is 35,127, and of nonagriculture wage and salary jobs, row total 41,305. Round to whole jobs.
Fill in the blanks
\frac12727127)(3114965372)}___590} = ___ \qquad \frac___305)(31___372)}___590} = ___
Why: Row total times column total over the grand total in each case: about 12,727 service-providing jobs and 14,965 nonagriculture wage and salary jobs would be expected in 2020 if the mix of sectors did not change with the year.
The arithmetic is the warm-up rule again; the numbers are just bigger. What deserves a second look is the routing. Every job is classified twice, by sector and by year, which makes it one population and two questions. The next slide shows why this particular table cannot actually be tested as printed.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, pp. 577-578 — Try It 11.6 and Try It 11.7
Worked example
The Bureau of Labor Statistics table lists seven industry sectors across 2000, 2010 and 2020. The book asks for the hypotheses and degrees of freedom of a test of whether the number of jobs in each sector is independent of the year.
Routing is quick here; the interesting step is a check the book skips. Any contingency table must put each counted item in exactly one cell. Before trusting the degrees of freedom, add a couple of rows and see whether any row is secretly the total of others.
Route the study
Why: each job is classified by sector and by year.
\[ (1, 2) \;\Rightarrow\; \text{independence} \]
Hypotheses
Why: the subject is the two variables.
\[ H_0: \text{sector and year are independent} \quad H_a: \text{dependent} \]
Degrees of freedom as printed
Why: seven rows and three columns.
\[ df = (7 - 1)(3 - 1) = 12 \]
Add the second and third rows
Why: goods-producing plus services-providing, in each year.
\[ 2{,}457 + 10{,}786 = 13{,}243, \quad 1{,}771 + 11{,}273 = 13{,}044 \]
Compare with the first row
Why: the first row, nonagriculture wage and salary, is exactly that sum.
\[ \text{row 1} = 13{,}243, \; 13{,}044, \; 15{,}018 \]
So the first row is a subtotal of the next two, and those jobs are counted twice. A contingency table needs categories that do not overlap: each job in exactly one row. With the subtotal row removed, the table has six rows and the degrees of freedom are 10. Either way the statistic is enormous, over 220, because the share of goods-producing jobs fell sharply after 2000.
Check the corrected degrees of freedom
Why: six genuine sector rows and three year columns.
\[ df = (6 - 1)(3 - 1) = 10 \quad \text{(book: 12, with the subtotal row)} \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, p. 577 — Try It 11.6 and Table 11.17
Prediction
In every test of independence the null says independent and the alternative says dependent. Commit to a reason before reading on.
Predict first
Why does the null hypothesis claim independence rather than dependence?
Correct: Independence gives a definite expected count for every cell; dependence gives none
Why: A test compares data with what the null predicts. Independence predicts row total times column total over the grand total in every cell; dependent could mean any of infinitely many patterns, so it predicts nothing to compare with.
The same logic runs through all three tests. Goodness of fit puts the given distribution in the null because it supplies the expected counts. Homogeneity puts same distribution in the null because a single shared distribution, estimated from the pooled samples, supplies them.
So in each test the null is the hypothesis that can be turned into numbers. That is also why a large p-value never proves the null: it only says the data are close to the numbers the null produced, which many other patterns could also do.
Section
Part 4
Concept
Section 11.4 introduces homogeneity with a warning: the goodness-of-fit test can decide whether a population fits a given distribution, but it will not suffice to decide whether two populations follow the same unknown distribution. You need two samples, and the test compares them with each other.
Its expected counts come from pooling. If the two populations share one distribution, the best estimate of it is the combined sample, so each population's expected count in a category is its sample size times the pooled share of that category. Written out, that is exactly the independence rule.
\[ E = n_{\text{group}} \cdot \frac{\text{column total}}{n} = \frac{(\text{row total})(\text{column total})}{n} \]
The book states the degrees of freedom for homogeneity as the number of columns minus one. That is correct for the two-row tables the section uses, but it is a special case: with two rows, rows minus one is one. The general rule is the same product as for independence.
\[ df = (r - 1)(c - 1) \quad \xrightarrow{r = 2} \quad df = c - 1 \]
The conditions are those of every count test: random samples, here two independent ones, and every expected count at least five. The book's list of common uses gives the flavour: men against women, before against after, east against west, on a categorical variable with more than two possible answers.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.4, pp. 578-579 — hypotheses, df, requirements and common uses
Worked example
250 randomly selected college men and 300 college women were asked about their living arrangements: dormitory, apartment, with parents, other. Men gave 72, 84, 49, 45; women 91, 86, 88, 35. Do the two populations have the same distribution? Use the 5 percent level.
Two samples were drawn separately, with their sizes fixed by the researcher at 250 and 300. Neither group's living arrangements are known in advance, so the comparison is sample against sample. The expected counts come from pooling, which is the only reasonable estimate of a shared distribution when nobody knows what it is.
Route the study
Why: two separate samples, one question asked of both, neither distribution known.
\[ (2, 1) \;\Rightarrow\; \text{homogeneity} \]
Hypotheses
Why: the subject is the two populations.
\[ H_0: \text{men and women follow the same distribution} \quad H_a: \text{not the same} \]
Pooled column totals
Why: both samples together, 550 students.
\[ 163, \; 170, \; 137, \; 80 \quad (n = 550) \]
Expected counts for the men
Why: 250 times each pooled share.
\[ \tfrac{250 \cdot 163}{550} = 74.09, \; 77.27, \; 62.27, \; 36.36 \]
Expected counts for the women
Why: 300 times each pooled share.
\[ \tfrac{300 \cdot 163}{550} = 88.91, \; 92.73, \; 74.73, \; 43.64 \]
Contributions, men then women
Why: with parents and other carry the weight.
\[ 0.059 + 0.586 + 2.829 + 2.051 + 0.049 + 0.488 + 2.357 + 1.709 \]
Statistic, df and p-value
Why: two rows, four columns.
\[ \chi^2 = 10.1287, \quad df = (2 - 1)(4 - 1) = 3, \quad p = 0.0175 \]
Figure (svg): A grouped bar chart of living arrangements as a percent of each sample. Dormitory: men 28.8, women 30.3. Apartment: men 33.6, women 28.7. With parents: men 19.6, women 29.3. Other: men 18.0, women 11.7.
Decision: 0.0175 is below 0.05, so reject the null. In context: there is sufficient evidence that college men and college women do not share the same distribution of living arrangements. As the book adds, the test says only that the distributions differ, not how; the bars suggest where to look.
Check that the gaps cancel in each column
Why: pooling forces the men's and women's gaps in a column to be equal and opposite.
\[ 72 - 74.09 = -2.09, \quad 91 - 88.91 = +2.09 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.4, pp. 579-580 — Example 11.8 and Table 11.19
Worked example
Separate surveys before and after an earthquake asked voters which of three city council candidates they planned to vote for. Before: Perez 167, Chung 128, Stevens 135. After: 214, 197, 225. Has the distribution of preferences changed? Use the 5 percent level.
Before and after are two moments, and the voters surveyed at each were different people, so they are two populations answering one question. If the same voters had been asked twice, the samples would be paired and none of these three tests would apply as it stands.
Route the study
Why: two separate samples of voters, one question each.
\[ (2, 1) \;\Rightarrow\; \text{homogeneity} \]
Hypotheses
Why: the subject is the before and after populations.
\[ H_0: \text{same distribution before and after} \quad H_a: \text{not the same} \]
Totals
Why: 430 before, 636 after; columns pooled.
\[ 381, \; 325, \; 360 \quad (n = 1{,}066) \]
Expected counts, before
Why: 430 times each pooled share.
\[ \tfrac{430 \cdot 381}{1066} = 153.69, \; 131.10, \; 145.22 \]
Expected counts, after
Why: 636 times each pooled share.
\[ 227.31, \; 193.90, \; 214.78 \]
Add the six contributions
Why: Perez before is the largest gap.
\[ 1.15 + 0.07 + 0.72 + 0.78 + 0.05 + 0.49 = 3.26 \]
Degrees of freedom and p-value
Why: two rows, three columns.
\[ df = (2 - 1)(3 - 1) = 2, \quad p = P(\chi^2 > 3.2603) = 0.1959 \]
Figure (svg): A chi-square curve with 2 degrees of freedom, which falls steadily from 0.5 at zero. A yellow line marks the statistic 3.26 with the region beyond it shaded yellow and labelled p equals 0.1959. A red dashed line marks the 5 percent critical value 5.99.
Decision: 0.1959 is above 0.05, so do not reject the null. In context: there is insufficient evidence that the distribution of voter preferences changed after the earthquake. Perez's share fell from about 39 to 34 percent, but shifts that size occur by chance in samples of this size.
Check against the critical value
Why: the 5 percent cutoff for two degrees of freedom is 5.99.
\[ 3.26 < 5.99 \quad \Leftrightarrow \quad p = 0.1959 > 0.05 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.4, pp. 580-581 — Example 11.9 and Table 11.21
Worked example
100 randomly selected families and 200 singles were asked what type of car they drive: sport, sedan, hatchback, truck, van or SUV. Families: 5, 15, 35, 17, 28. Singles: 45, 65, 37, 46, 7. Do the two groups have the same distribution of cars? Test at 5 percent.
The samples are different sizes, 100 and 200, so compare percentages by eye and counts in the arithmetic. Because the singles' sample is exactly twice the families', every expected count for the singles will be exactly twice the families' count in the same column, which saves half the work.
Route the study
Why: two separate samples, one question.
\[ (2, 1) \;\Rightarrow\; \text{homogeneity} \]
Pooled shares
Why: column totals over 300.
\[ \tfrac{50}{300}, \; \tfrac{80}{300}, \; \tfrac{72}{300}, \; \tfrac{63}{300}, \; \tfrac{35}{300} \]
Expected counts for families
Why: 100 times each share; the singles' are exactly double.
\[ 16.67, \; 26.67, \; 24.00, \; 21.00, \; 11.67 \]
The largest contribution
Why: families driving vans or SUVs.
\[ \frac{(28 - 11.67)^2}{11.67} = 22.87 \]
Statistic, df and p-value
Why: ten contributions; two rows and five columns.
\[ \chi^2 = 62.91, \quad df = (2 - 1)(5 - 1) = 4, \quad p \approx 7 \times 10^{-13} \]
Figure (svg): A grouped bar chart of car type as a percent of each sample. Sport: families 5, singles 22.5. Sedan: 15 and 32.5. Hatchback: 35 and 18.5. Truck: 17 and 23. Van or SUV: 28 and 3.5.
The book prints no answer for this Try It. Decision: reject the null. In context: families and singles clearly do not share one distribution of car types; families favour hatchbacks and vans, singles sport cars and sedans.
Check the expected counts add to the family sample
Why: they must return the row total, up to rounding.
\[ 16.67 + 26.67 + 24.00 + 21.00 + 11.67 = 100.01 \approx 100 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.4, p. 580 — Try It 11.8 and Table 11.20
Worked example
Six Ivy League schools accepted regular applications 2,115, 1,792, 5,306, 1,734, 2,685 and 1,245 times (Brown, Columbia, Cornell, Dartmouth, Penn, Yale), and early-decision applications 577, 627, 1,228, 444, 1,195 and 761 times. Do the two types of acceptance follow the same distribution across schools?
The question is the book's: does the number of regular acceptances follow the same distribution as the number of early ones? Two groups, one question each, namely which school, and no distribution given in advance. The counts run into thousands, so the condition of five per cell is no worry; the size of the statistic will be.
Route the study
Why: two groups of acceptances, one question: which school?
\[ (2, 1) \;\Rightarrow\; \text{homogeneity} \]
Hypotheses, in the book's wording
Why: the two populations are the two types of acceptance.
\[ H_0: \text{same distribution across schools} \quad H_a: \text{different} \]
Totals
Why: 14,877 regular and 4,832 early, 19,709 in all.
\[ \text{Cornell column: } 5{,}306 + 1{,}228 = 6{,}534 \]
One expected count
Why: Yale's early-decision acceptances under a shared distribution.
\[ E = \frac{(4{,}832)(2{,}006)}{19{,}709} = 491.81 \quad (O = 761) \]
Statistic, df and p-value
Why: twelve contributions; Yale's early cell alone gives 147.35.
\[ \chi^2 = 430.06, \quad df = (2 - 1)(6 - 1) = 5, \quad p < 0.0001 \]
Figure (svg): Two horizontal bars split into the shares of accepted applications at six schools. Regular acceptances: Brown 14, Columbia 12, Cornell 36, Dartmouth 12, Penn 18, Yale 8 percent. Early decision acceptances: 12, 13, 25, 9, 25, 16 percent.
The book prints no answer here either. Decision: reject the null. In context: early-decision and regular acceptances are spread across these six schools in clearly different proportions. One honest caveat: these are complete counts for one year, not random samples, so the test describes how unusual the difference would be for samples, not a sampling result.
Check the critical value
Why: the 5 percent cutoff for five degrees of freedom is 11.07; the statistic is nearly forty times it.
\[ 430.06 > 11.07 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.4, pp. 581-582 — Try It 11.9 and Table 11.22
Trap
To compare the 250 men with the women of Example 11.8, a first attempt treats the women's sample percentages as the known distribution and runs goodness of fit:
\[ E = 250\left(\tfrac{91}{300}, \tfrac{86}{300}, \tfrac{88}{300}, \tfrac{35}{300}\right) \]
\[ \chi^2 = 18.99, \quad p = 0.0003 \]
Wrong. It ignores the women's sampling error.
The women's percentages come from a sample of 300, so they are estimates, not known values. Two samples with no known distribution is homogeneity, which pools both:
\[ \chi^2 = 10.13, \quad p = 0.0175 \]
The wrong test nearly doubles the statistic and shrinks the p-value about sixty-fold, from 0.0175 to 0.0003, so the evidence looks far stronger than it is.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — two populations with unknown distributions
Worked example
The trap gave two statistics for the same men. Work through where the gap comes from, because it is the clearest picture of what known means and why homogeneity pools.
Both versions use the same observed counts for the men, 72, 84, 49 and 45. Only the expected counts differ, so line the two sets up cell by cell and find the cell where they disagree most.
Goodness of fit against the women, men's expected counts
Why: 250 times each women's share, treated as exact.
\[ 75.83, \; 71.67, \; 73.33, \; 29.17 \]
Homogeneity, men's expected counts
Why: 250 times each pooled share of all 550 students.
\[ 74.09, \; 77.27, \; 62.27, \; 36.36 \]
Compare the with-parents cell
Why: men observed 49 in both versions.
\[ \frac{(49 - 73.33)^2}{73.33} = 8.07 \quad \text{against} \quad \frac{(49 - 62.27)^2}{62.27} = 2.83 \]
Figure (svg): A grouped bar chart of the 250 men's living arrangements with three bars per category. Observed: 72, 84, 49, 45. Expected from pooled margins: 74.1, 77.3, 62.3, 36.4. Expected if the women's sample percentages were known: 75.8, 71.7, 73.3, 29.2.
Pooling pulls the expected counts part of the way towards the men's own data, because the men are part of the pool. That is not a flaw: if the two populations share one distribution, the pooled sample is the best estimate of it, and the test's degrees of freedom already account for that estimate. Treating the women's figures as exact pretends that their own sampling wobble does not exist.
In context: the honest conclusion is the homogeneity one, a p-value of 0.0175. The evidence that men and women live differently is real, but moderate; the goodness-of-fit version, p equal to 0.0003, overstates it.
Check that both sets of expected counts total 250
Why: each is a distribution of the same 250 men.
\[ 75.83 + 71.67 + 73.33 + 29.17 = 250 = 74.09 + 77.27 + 62.27 + 36.36 \]
Counterexample
A common shortcut says: count the rows of the table, and if there are two or more, it is homogeneity. Break that shortcut with an example from this chapter.
Discussion prompt
Give a table from Sections 11.3 or 11.4 that has two or more rows but comes from a single population, and say which test it needs and why.
The rows of a two-way table are always the categories of some variable. Sometimes that variable is which sample you came from, and then the rows are populations; sometimes it is an answer the subject gave, and then they are not. The table looks the same either way.
So the shortcut fails precisely on the cases where it matters. The reliable route is the sampling description: were separate samples drawn from each row's group, with the group sizes fixed by the researcher, or was one sample drawn and then sorted?
Matching
Each null below is written in the style of the book. Read its subject, what the sentence is about, and match it to the test that would use it. One of them belongs to a chi-square test that is not among the three.
Match the pairs
Why: A given distribution means goodness of fit; two variables means independence; two populations means homogeneity. A null that names a parameter, here a variance, is Section 11.6's test, which also uses a chi-square curve but is not a count test.
The last pair is the one to notice. A null with a number in it, a parameter equal to a value, is a different kind of hypothesis altogether. The three count tests never name a parameter, which is also why the chapter offers no confidence interval for them: there is nothing to put an interval around.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5-§11.6, pp. 582-583 — the three pairs and the single-variance null
Section
Part 5
Concept
Line the three tests up and most of the columns are identical. That is the reason this section exists: the features you notice while calculating are exactly the ones that cannot tell the tests apart.
| feature | goodness of fit | independence | homogeneity |
|---|---|---|---|
| statistic | Σ (O − E)² / E | the same | the same |
| distribution | chi-square | chi-square | chi-square |
| tail | right | right | right |
| condition | every E ≥ 5 | every E ≥ 5 | every E ≥ 5 |
| hypotheses | in words | in words | in words |
| expected counts | n times given p | row × column / n | row × column / n |
| degrees of freedom | cells − 1 | (r − 1)(c − 1) | (r − 1)(c − 1) |
The first five rows are shared by all three. The last two are where the tests differ, and even there independence and homogeneity agree with each other. So the only computational line that separates any pair is goodness of fit's expected counts and degrees of freedom.
One more shared feature is an absence: none of the three has a parameter. Every test in Chapters 9 and 10 was about a mean, a proportion or a difference of them, and came with a confidence interval. These tests are about whole distributions, so they end with a sentence, not an interval.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2-§11.5, pp. 565-582 — the statistic, the condition and the df rules
Intuition
Each term of the statistic is a squared gap divided by a positive count. Squares are never negative, so every term is zero or positive, and the total is zero only when every observed count equals its expected count exactly.
\[ \frac{(O - E)^2}{E} \ge 0 \quad \text{in every cell} \]
Now think about what each end of the curve means. A small statistic says the data sit close to what the null predicts, which is evidence for the null, not against it. A large statistic says the data sit far away, in some cells, in some direction. Only the large end is evidence against the null.
\[ \text{reject } H_0 \iff \chi^2 \text{ is large} \iff p = P(\chi^2 > \text{observed}) \text{ is small} \]
Squaring throws away the direction of every gap. Too many Monday absences and too few Monday absences add to the statistic in the same way. That is why the alternatives in all three tests are simply not the null, with no direction to choose, and why there is never a left-tailed or two-tailed version.
Contrast the single-variance test of Section 11.6, which also uses a chi-square curve. Its statistic is a ratio of variances rather than a sum of squared gaps, so a small value means something, and that test can be left-tailed. Same curve, different logic.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, p. 575 — the test is always right-tailed because of the calculation of the statistic
Tweak it
All three tests require every expected count to be at least five. The slider shows why, using one cell's contribution to the statistic as the observed count varies. Before you move it, guess what a small expected count does to the curve.
Parameter explorer
The curve is one cell's contribution, (O − E)² / E, plotted against the observed count O, for the expected count E on the slider. Set E to 2, then to 20. How large is the contribution when the observed count misses by 4 in each case?
\[ \text{contribution} = \frac{(O - E)^2}{E}, \quad E = {E} \]
What to notice: the parabola's width grows with E. When E is large, the observed count can wander several units with little effect, as chance variation should. When E is small, the parabola is narrow, and a miss of three or four, which is ordinary for a count averaging two, sends the contribution soaring.
\[ E = 2: \; \frac{4^2}{2} = 8 \qquad E = 20: \; \frac{4^2}{20} = 0.8 \]
The chi-square curve is only a good model for the statistic when the cells behave like large counts. That is why Example 11.1 combined its two smallest absence bands, and why the condition is the same in all three tests.
Concept
Degrees of freedom count how many cells could be filled in freely before the fixed totals decide the rest. That single idea gives both rules, and the picture shows it.
Figure (svg): Two diagrams. Left: a row of five cells holding 15, 12, 9, 9 and a question mark, with total 60; the first four are shaded as free and the fifth as forced, so df equals 5 minus 1, 4. Right: a three by three table with row totals 255, 290, 294 and column totals 298, 379, 162; the top-left two by two block is shaded free and the last row and column are forced, so df equals 2 times 2, 4.
In goodness of fit only the grand total is fixed, because the expected counts come from outside. Fill in four of Example 11.2's five days and the fifth is forced, since all five must add to 60. One constraint, one lost degree of freedom.
\[ df_{\text{fit}} = k - 1 \]
In a contingency table every row total and every column total is fixed, because the expected counts were built from them. Fill in the top-left block and the last cell of every row and every column is forced. What remains free is a block one row shorter and one column narrower.
\[ df_{\text{table}} = (r - 1)(c - 1) \]
Independence and homogeneity share the rule because they share the constraint: both take their expected counts from the margins. So the degrees of freedom differ only between goodness of fit and the other two, and that is the one place a wrong routing changes the number.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.2-§11.4, pp. 565-579 — df = cells − 1 and df = (columns − 1)(rows − 1)
Worked example
Suppose someone sees Example 11.6's nine cells, computes the same 12.99, but treats the table as nine categories of one variable and takes the degrees of freedom as cells minus one. What happens to the decision at the 5 percent level?
The correct routing
Why: one population, two questions: a three by three table.
\[ df = (3 - 1)(3 - 1) = 4 \]
The misrouted degrees of freedom
Why: nine cells minus one.
\[ df = 9 - 1 = 8 \]
The same statistic on the correct curve
Why: the tail beyond 12.99 with four degrees of freedom.
\[ P(\chi^2_4 > 12.99) = 0.0113 < 0.05 \;\Rightarrow\; \text{reject} \]
The same statistic on the wrong curve
Why: the tail beyond 12.99 with eight degrees of freedom.
\[ P(\chi^2_8 > 12.99) = 0.1122 > 0.05 \;\Rightarrow\; \text{do not reject} \]
Figure (svg): Two chi-square curves on the same axes, x from 0 to 24. The df 4 curve, blue, peaks near 2; the df 8 curve, orange, is lower and peaks near 6. A yellow line marks the statistic 12.99. The tail beyond it under the df 4 curve holds 0.0113; under the df 8 curve it holds 0.1122.
The decision flips. With more degrees of freedom the curve shifts right, its mean equal to the degrees of freedom, so the same statistic looks ordinary. In context, the misrouted analyst would report no evidence that hours depend on type of volunteer, when the correct test finds it at the 5 percent level.
Compare the other confusion, independence with homogeneity: the expected counts, the statistic, the degrees of freedom and the p-value are all identical, so the decision never changes. Only the conclusion's wording is wrong. Confusing either with goodness of fit is the costly error.
Check with the critical values
Why: the 5 percent cutoffs are 9.49 for four degrees of freedom and 15.51 for eight; 12.99 sits between them.
\[ 9.49 < 12.99 < 15.51 \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.3, pp. 576-577 — Example 11.6: df = (3 − 1)(3 − 1) = 4
Worked example
Imagine Example 11.8 run differently: a single random sample of 550 college students, each asked two questions, their sex and their living arrangement, happens to give exactly the same table. Which numbers change, and which sentence?
Route the new study
Why: one sample, two questions.
\[ (1, 2) \;\Rightarrow\; \text{independence} \]
Expected counts
Why: row total times column total over 550, the same rule as before.
\[ \tfrac{250 \cdot 163}{550} = 74.09, \; \ldots \; \text{(all eight unchanged)} \]
Statistic and degrees of freedom
Why: the same eight contributions and the same table shape.
\[ \chi^2 = 10.1287, \quad df = (2 - 1)(4 - 1) = 3 \]
p-value and decision
Why: the same right tail.
\[ p = 0.0175 < 0.05 \;\Rightarrow\; \text{reject } H_0 \]
Everything numerical is identical. What changes is the claim. The homogeneity conclusion was about two populations: college men and college women have different distributions of living arrangements. The independence conclusion is about one population and two variables: among college students, living arrangement and sex are related.
Those sound close, and in this case they describe the same reality. But they rest on different sampling. A homogeneity study fixes how many men and how many women are sampled, so it cannot estimate what share of all students are men; an independence study lets those numbers fall where they may, so it can.
Check that the two conclusions name different subjects
Why: homogeneity speaks of two populations; independence speaks of two variables in one population.
\[ H_0^{\text{hom}}: \text{men and women share a distribution} \]
\[ H_0^{\text{ind}}: \text{sex and living are independent} \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.4, p. 578 — follow the same procedure as with the test of independence
Concept
The routing decision shows up one last time, in the final sentence. Each test licenses a different kind of claim, and the conclusion must name the right subject: a population against a yardstick, two variables in one population, or two populations against each other.
| test | if you reject the null | if you do not reject |
|---|---|---|
| goodness of fit | the population does not fit the given distribution | not enough evidence that it does not fit |
| independence | the two variables are dependent in this population | not enough evidence that they are dependent |
| homogeneity | the two populations have different distributions | not enough evidence that they differ |
Every conclusion also carries the significance level and the context: which population, which variables, in the units of the problem. Compare the book's sentence for Example 11.6: at a 5 percent level of significance, from the data, there is sufficient evidence to conclude that the number of hours volunteered and the type of volunteer are dependent on one another.
Two limits apply to all three. A rejection says the null is wrong, not how it is wrong; the book stresses this for homogeneity, and to describe the difference you go back to the percentages or the cell contributions. And a non-rejection is never proof of fit, independence or sameness.
\[ \text{reject} \Rightarrow \text{evidence against } H_0 \qquad \text{do not reject} \not\Rightarrow H_0 \text{ true} \]
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.4, p. 580 — we cannot use the test for homogeneity to draw conclusions about how they differ
Comparison
Fill in the blanks from memory, then check against the summary. Every entry is something the routing or the arithmetic depends on.
Comparison matrix
| test | populations | questions | anything known? | expected count | df |
|---|---|---|---|---|---|
| goodness of fit | 1 | 1 | yes: the given distribution | n times p | k-1 |
| independence | 1 | 2 | no | row × column / n | (r − 1)(c − 1) |
| homogeneity | 2 | 1 | no | row × column / n | (r − 1)(c − 1) |
Read the grid by columns. The populations and questions columns route the study; no two rows agree on both. The anything known column separates the two tests that each compare something with something else: only goodness of fit has a fixed yardstick.
The last two columns show the arithmetic. Independence and homogeneity have identical rows there, which is why confusing those two costs nothing numerically. Goodness of fit differs in both, which is why confusing it with either of the others can change the decision.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the summary list
Error analysis
Four people wrote hypotheses for chi-square count tests. Two are correct in the book's form, and two contain a real error. Hover over each label to see which, and why.
Annotate
On: \( H_0: \text{dependent} \quad H_0: p_1 = p_2 = p_3 \quad H_0: \text{fits} \quad H_a: \text{different} \)
The first error is the one worth guarding against most, because it reverses the logic of the whole test. If the null claimed dependence, rejecting it would mean concluding independence, and a large statistic would somehow be evidence that the variables are unrelated, which is backwards.
The second error is more forgivable. Writing equal proportions for one category across groups is a correct idea for a two-proportion test from Chapter 10, but a chi-square count test compares every category at once, which is why its hypotheses are stated as sentences about distributions.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the three pairs of hypotheses
Ranking
Here are the steps of a complete chi-square count test, from reading the problem to writing the conclusion. Put them in the order you should do them. The order is the lesson: the decisions come first and the arithmetic comes last.
Put in order
Order the steps of a chi-square count test.
Why: Routing comes from the design, so the counts and the known-or-estimated decision come first. The hypotheses follow from the test. Expected counts depend on the test, and their size must pass the condition before the statistic is worth computing. The p-value and a sentence in context come last.
Notice that the expected counts sit after the routing. In goodness of fit they come from the given proportions; in the other two they come from the margins. You cannot build them correctly until you know which test you are running.
The condition check sits before the statistic for a practical reason. If a cell fails it, you combine categories, as Example 11.1 did, and that changes both the statistic and the degrees of freedom. Computing first and checking afterwards means computing twice.
Concept
The page that ends the summary begins Section 11.6, and it is worth a look here because it uses the same curve for a different job. A test of a single variance asks about one population's variance, assuming the population is normal.
\[ \chi^2 = \frac{(n - 1)s^2}{\sigma^2} \]
In Example 11.11 a post office had a waiting-time standard deviation of 7.2 minutes and tried a single line; a sample of 25 customers had a standard deviation of 3.5 minutes. The claim is that the single line reduces variation.
\[ \chi^2 = \frac{(25 - 1)(3.5)^2}{(7.2)^2} = \frac{24(12.25)}{51.84} = 5.67, \quad df = 24 \]
Figure (svg): A chi-square curve with 24 degrees of freedom, a hump centred near 22, x from 0 to 50. A yellow line at 5.67 sits far in the left tail, where the shaded area is too small to see and is labelled p equals 0.000042. A red dashed line marks the left-tail 5 percent critical value 13.85.
Here the evidence is in the left tail: a small statistic means the sample varies less than the claimed population. The p-value is the area below 5.67, about 0.000042. The book rejects the null: the single line reduces the variation in waiting times.
Set this beside the three count tests. Its null names a parameter, the variance; its data are measurements, not counts in categories; and it can be left-tailed. If a problem mentions a variance or a standard deviation, it is not goodness of fit, independence or homogeneity, whatever curve it uses.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.6, pp. 582-583 — the single-variance statistic and Example 11.11
Real world
Real reports rarely say which test they used. Practise routing from a plain description, the way you would meet it in a newspaper or a research summary.
Discussion prompt
A health agency surveyed 1,200 randomly chosen adults in one state, asking each whether they had received a flu shot this season and which of four age bands they were in. A separate report compared the state's age bands with the national census percentages. Name the test for each analysis and write its null hypothesis.
Both analyses use the same 1,200 people, which is the point. Which test you run depends on the question you put to the data, not on the data set. Using the age question alone against a known yardstick is goodness of fit; crossing it with a second question is independence.
Had the agency drawn separate samples in two states and compared their age bands, it would have been homogeneity, and the census would have played no part.
Step zero
A problem gives you a table of counts and asks you to test at the 5 percent level. The temptation is to start building expected counts at once. Resist it for ten seconds.
Discussion prompt
A gym manager records, for one random sample of 150 members, their preferred workout time (morning, afternoon, evening) and whether they hold a premium membership. What two questions should you answer before computing anything, and what are the answers here?
Those two counts take seconds and settle three things at once: the wording of the hypotheses, where the expected counts come from, and the degrees of freedom. Everything after that is arithmetic you have already practised.
If the description is too thin to count, fall back on the other signal: try to write the null. Whichever of the three forms fits the question being asked names the test.
Section
Part 6
Pattern
Every example in this lesson ran through the same sequence. The decision tree settles the test from the design before any arithmetic; the list below it is the full procedure.
Start at the top box every time, even when the answer feels obvious. The cases that went wrong in this lesson, the volunteer table read as three populations, last year's survey read as a known distribution, all felt obvious too. The tree forces you to ask about samples, not about the table's shape.
Figure (svg): A decision tree. The top box asks how many populations were sampled. Two populations leads to a box for the test for homogeneity. One population leads to a second box asking how many questions each subject answered. Two questions leads to the test of independence; one question, compared with a known distribution, leads to the goodness-of-fit test. Under each test its df rule is written.
\[ \text{fit: } df = k - 1 \qquad \text{independence, homogeneity: } df = (r - 1)(c - 1) \]
Most wrong answers in this chapter are correct arithmetic for the wrong test, and they come in two kinds. Confusing independence with homogeneity changes only the wording of the conclusion. Confusing either with goodness of fit, or treating a sample as known, changes the numbers and can change the decision.
Check
Count before you choose.
Read the sampling sentence and count populations and questions. Then ask whether anything in the comparison is fixed in advance.
Check your understanding
A researcher randomly samples 200 commuters in Seattle and 200 in Denver and asks each how they usually get to work: car, bus, train, bike, or walk. Which test answers whether the two cities differ?
Answer: A
Why: Two separately drawn samples, one question asked of both, and neither city's distribution is known in advance: two populations and one question is the homogeneity design. Its null is that the two cities follow the same distribution of commuting modes.
In context: the null says commuters in Seattle and Denver share one distribution of ways to get to work, and the alternative says they do not. The degrees of freedom would be one times four, which is four.
The goodness-of-fit option is the tempting one, and it is the costly mistake from Part 4: it gives a different statistic and can flip the decision. The independence option would give the right numbers, but a conclusion about the wrong kind of claim.
The quick test: could you have written the comparison percentages down before collecting any data? Seattle's could not, so nothing is known.
Check
Decide which numbers move.
Think about where the expected counts come from in each test, and which rule gives the degrees of freedom.
Check your understanding
A three-row, four-column table from one sample, each subject answering two questions, is analysed by mistake as a test for homogeneity. Compared with the correct analysis, what changes?
Answer: A
Why: Independence and homogeneity build expected counts from the margins in exactly the same way, so the statistic, the degrees of freedom and the p-value are identical. Only the claim changes: two variables in one population rather than separate populations.
Seeing why is the useful part. The analyst who calls it homogeneity still builds every expected count as row total times column total over the grand total, still sums twelve contributions, and still reads the curve with six degrees of freedom. Nothing computed on the way to the decision depends on the label.
In context: the analyst's decision would stand, but the sentence written about it would describe the wrong study, a comparison of populations that were never separately sampled.
Set this beside the misrouting in Part 5, where treating a table as goodness of fit changed the degrees of freedom from 4 to 8 and flipped Example 11.6's decision. The two kinds of error are not equally serious.
That does not make the cheaper error acceptable. A conclusion is the only part of a test anyone else reads, and one that describes separate populations when the study sampled one group tells the reader something about how the data were gathered that is simply false.
Check
Ask where the percentages came from.
A known distribution is fully specified before the data, by a claim, a theory or a census. Anything measured from another sample is an estimate.
Check your understanding
A school compares this year's 120 cafeteria choices with the percentages found in last year's survey of 90 students. A teacher calls it a goodness-of-fit test against last year's distribution. What is wrong?
Answer: A
Why: Ninety students give estimated percentages that carry sampling error. Comparing two samples with no known distribution is the homogeneity design, which pools both years for its expected counts.
In context: the null should say this year's and last year's students follow the same distribution of cafeteria choices.
The independence option is worth a second thought. If one sample of students had been asked their year and their choice, it would be independence. Here the two years were sampled separately, so the year is a population label.
Treated as goodness of fit, the test would overstate the evidence, exactly as the living-arrangements trap did, by a factor that can easily change the decision.
Explain it to yourself
The section is short, but the idea behind it is one you will use in every statistics course that follows: choose the method from the design, not from the data's appearance.
Discussion prompt
A classmate asks why the book needs a whole section to compare three tests it has already taught. In three or four sentences, explain what the section adds and what goes wrong without it.
A strong answer names the shared features and the routing counts. A very strong one adds the cost of each error: confusing the two table tests changes only the conclusion's wording, while confusing either with goodness of fit can change the degrees of freedom and the decision.
If your explanation leaned on the shape of the table, two rows meaning two groups, go back to the counterexample slide: the shape of the table is exactly what cannot be trusted.
Exit ticket
A university randomly samples 500 first-year students and records each one's residence (campus or off campus) and their main study location (library, home, cafe). A second analysis compares the 500 students' residence split with the registrar's exact figures for all first-years: 62 percent on campus.
Discussion prompt
Route each analysis, write its null hypothesis, and give its degrees of freedom. Then say which analysis would become a test for homogeneity, and how the study would have to change.
The registrar's figure counts as known because it covers every first-year, not a sample. If it had come from a survey of 300 students instead, the second comparison would be two samples and therefore homogeneity, not goodness of fit.
If you gave the first analysis cells minus one, five degrees of freedom, you treated a two-way table as six categories of one variable: the costly misrouting from Part 5.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — the three bullets
Recap
The three chi-square count tests share a statistic, a curve, a right tail and a condition, so the arithmetic cannot choose between them. The book's summary chooses by the study: count populations and questions, and ask whether the comparison distribution is known.
| test | design | decides whether… | null in words | df |
|---|---|---|---|---|
| goodness of fit | 1 population, 1 question, known distribution | a population fits a known distribution | the population fits the given distribution | cells − 1 |
| independence | 1 population, 2 questions | two variables are independent | the two variables are independent | (r − 1)(c − 1) |
| homogeneity | 2 populations, 1 question | two populations share a distribution | the two populations follow the same distribution | (r − 1)(c − 1) |
Two errors are worth remembering by their cost. Confusing independence with homogeneity changes nothing numerical, only the claim in the conclusion. Confusing either with goodness of fit, or treating another sample's percentages as known, changes the degrees of freedom or the expected counts and can flip the decision.
A chi-square test whose null names a parameter, such as Section 11.6's single variance, is none of the three. The Introductory Business Statistics text has the same comparison in its own §11.6, if you want the summary in business contexts.
OpenStax Introductory Statistics 2e, §11.5 Comparison of the Chi-Square Tests §11.5, p. 582 — Comparison of the Chi-Square Tests
OpenStax Introductory Business Statistics 2e, §11.6 Comparison of the Chi-Square Tests §11.6 Comparison of the Chi-Square Tests — the same summary in business contexts
Want this taught 1-on-1? Alexander tutors Statistics — $55/session, free consultation.