The chi-square distribution's first use, and the chapter's first genuinely new question: instead of testing a single mean or proportion, a goodness-of-fit test asks whether a whole set of observed counts is consistent with a claimed distribution. The statistic sums observed minus expected, squared, over expected across the cells, so a departure in any cell and in either direction makes it larger — which is why the test is almost always right-tailed and why small statistics mean good agreement. The degrees of freedom are the number of categories minus one, never the number of observations minus one, and every expected count must be at least five, a condition that in the book's first example forces two categories to be combined before the test can be run at all. Worked through the book's four examples: absenteeism, absences by weekday, streaming services and a pair of coins.
Subject: Statistics · 67 slides · symbolic lesson
Open the interactive version of this deck
Title
Statistics · Chapter 11 — The Chi-Square Distribution
Do a whole set of observed counts fit the distribution someone claims? One statistic, one tail, cells minus one
Objectives
Chapters 9 and 10 tested one number at a time: one mean, one proportion, one difference. This section asks a bigger question in one go. Someone claims a whole distribution, a percentage for every category, and you have counts in every category. Do the counts fit the claim, or not?
The arithmetic is a table of subtractions, squares and divisions. The marks are lost elsewhere: in expected counts built wrongly, in degrees of freedom counted from the sample size instead of the cells, and in conclusions that claim a large p-value proves the claim. Each of those gets its own slide.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565-574 — the section this deck covers
Warm-up
In Example 11.2, 60 managers each named the weekday with the most absences, and 15 of them named Monday. You already own a test for one proportion. Try it on Monday alone, and then notice what it cannot do.
Discussion prompt
If absences were spread equally, Monday's share would be one fifth. Using Chapter 9's one-proportion z test, how far is 15 out of 60 from one fifth, in standard errors? And how many such tests would you need to judge all five days at once?
Hold on to that last point. A claimed distribution makes one joint statement about every category, so it deserves one test that weighs all the categories together. The goodness-of-fit statistic is that test, and its degrees of freedom will come straight from the fact that the shares must add to one.
There is a second problem with five separate tests. Each one compares one day with everything else, so a pattern spread thinly over several days, each a little off, might pass every single test and still be real. A single statistic that pools the evidence from all five cells is built to see exactly that.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §9.3 and §11.2 — a single proportion, then a whole distribution
Section
Part 1
Concept
Example 11.2 asks whether employee absences are spread equally over a five-day week. Sixty randomly sampled managers each named the day on which they had the most absences, and here is what they said.
| day | Monday | Tuesday | Wednesday | Thursday | Friday | total |
|---|---|---|---|---|---|---|
| observed count | 15 | 12 | 9 | 9 | 15 | 60 |
The claim being tested is not about Monday or Friday on its own. It is a statement about the whole distribution: every day carries the same share of the busiest-absence days. A test of that claim has to look at all five counts at once.
Figure (svg): Grouped bar chart for Monday to Friday. Orange bars show how many of 60 managers named each day: 15, 12, 9, 9 and 15. Blue bars show the 12 per day expected if absences were spread equally. Monday and Friday stand 3 above the blue bars, Wednesday and Thursday 3 below, and Tuesday matches exactly.
The book calls this a goodness-of-fit test, because you ask how well the data fit a particular distribution. The hypotheses are usually written in sentences, and that is the clearest way to write them here.
\[ H_0: \text{ the absent days occur with equal frequencies} \]
\[ H_a: \text{ the absent days do not occur with equal frequencies} \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565 and 568 — the goodness-of-fit idea and Example 11.2
Concept
The book says the hypotheses of a goodness-of-fit test may be written in sentences or as equations. For the weekday question, the equation form names a proportion for each day: the share of all employees' busiest-absence days that fall on that day.
\[ H_0: p_{\text{Mon}} = p_{\text{Tue}} = p_{\text{Wed}} = p_{\text{Thu}} = p_{\text{Fri}} = 0.2 \]
The alternative is simply that the null is false: at least one of those proportions is not 0.2. It does not say which day, and it does not say whether too high or too low. That is why you will see no greater-than or less-than sign anywhere in this section.
\[ H_a: \text{ at least one } p_i \ne 0.2 \]
A common slip is to write the alternative as every proportion differs from 0.2. That is far too strong: a single unusual day is enough to make the null false. Another slip is to write the hypotheses about the sample counts, such as the observed Monday count equals 12. Hypotheses are always about the population, here all employees' absences, never about the sixty managers you happened to ask.
For most problems the sentence form is clearer and is what the book uses: the data fit the claimed distribution, against the data do not fit it.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — sentences, equations or inequalities
Concept
Every goodness-of-fit test compares two columns of numbers. The observed counts, O, are the data: what actually happened in each category. The expected counts, E, are what the null hypothesis says should happen, on average, in a sample of this size.
The expected counts come from the claim and the sample size alone. If the null hypothesis gives category i a probability, then in n observations you expect n times that probability to land there.
\[ E_i = n \cdot p_i \]
For the managers, n is 60 and the null gives each of the five days probability one fifth, so every expected count is the same.
\[ E = 60 \cdot \frac{1}{5} = 12 \text{ managers per day} \]
Two properties are worth checking every time. The expected counts must add up to the same total as the observed counts, because both describe the same sixty managers. And an expected count does not have to be a whole number: it is an average over many imaginary samples, so 12.4 would be perfectly fine.
\[ \sum E_i = 5 \times 12 = 60 = \sum O_i \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 568 — Example 11.2: the expected values
Concept
You want a single number that is small when the observed counts sit close to the expected ones and large when they do not. Build it in three moves and watch why each move is needed. The first idea is the gap in each cell.
\[ O_i - E_i: \quad 3, \; 0, \; -3, \; -3, \; 3 \]
Adding the gaps fails at once. They always add to zero, because the observed and expected columns have the same total, so a plain sum cannot tell a perfect fit from a terrible one.
\[ \sum (O_i - E_i) = \sum O_i - \sum E_i = 60 - 60 = 0 \]
Squaring fixes that: a gap of three in either direction becomes nine, and nothing can cancel. Then divide each square by its own expected count, so that a gap is judged against how much was expected in that cell.
\[ \frac{(O_i - E_i)^2}{E_i}: \quad \frac{9}{12}, \; \frac{0}{12}, \; \frac{9}{12}, \; \frac{9}{12}, \; \frac{9}{12} \]
Figure (svg): Two number lines. The upper one shows the five differences between observed and expected absences for Example 11.2: plus 3 for Monday and Friday, 0 for Tuesday, minus 3 for Wednesday and Thursday; they add to zero. The lower one shows each day's squared difference divided by 12: four days at 0.75 and Tuesday at 0, adding to 3.
Finally add over all the cells. That sum is the goodness-of-fit statistic, and for the managers it comes to exactly 3.
\[ \chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i} = 0.75 + 0 + 0.75 + 0.75 + 0.75 = 3 \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — the test statistic
Notation
Here is the statistic as the book writes it. Every symbol is doing a job, and the most important one is the one at the top of the sum. Hover over each piece.
Annotate
On: \( \chi^2 = \sum_{i=1}^{k} \frac{(O - E)^2}{E}, \qquad df = k - 1 \)
The book says there are n terms of this form, directly after naming k as the number of cells. That is a slip: there is one term per cell, so there are k terms. With 60 managers and five days you add five terms, not sixty. It matters because confusing the cells with the observations is exactly the mistake the degrees of freedom rule is there to prevent.
Every term is a square divided by a positive count, so every term is zero or positive, and the statistic can never be negative. That one fact will decide the direction of the test.
Keep an eye on what each term measures. It is a squared gap judged against the expected count, roughly a squared standard score, so terms from cells of very different sizes sit on one common scale and can sensibly be added.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — the statistic, its symbols and the df rule
Picture it
Two cells, each missing its expected count by exactly six. Should they count equally toward the evidence? Look at the pictures before you answer.
Figure (svg): Two bar panels. Left: an expected count of 12 and an observed count of 18, a gap of 6 that is half the expected bar again; contribution 36 over 12 equals 3. Right: an expected count of 300 and an observed count of 306, where the gap of 6 is barely visible; contribution 36 over 300 equals 0.12.
In the small cell, 18 instead of 12 is half as much again as expected. In the large cell, 306 instead of 300 is a two percent ripple, the kind of difference that random sampling produces all the time. Dividing the squared gap by E turns those into 3 and 0.12, which ranks them the way your eye does.
\[ \frac{6^2}{12} = 3.00 \qquad \text{versus} \qquad \frac{6^2}{300} = 0.12 \]
There is a deeper reason too. For counts, the natural chance variation in a cell grows with its expected size: a cell expecting 300 wobbles by about the square root of 300, roughly 17, while a cell expecting 12 wobbles by about 3.5. Dividing by E measures each squared gap against that natural wobble, so each term is roughly a squared standard score.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — O and E in the statistic
Prediction
Commit to an answer before computing. Both cells come from Example 11.3's streaming-service table, where 600 families were surveyed.
Predict first
In the two-services cell, 340 families were observed where 330 were expected. In the four-or-more cell, 15 were observed where 48 were expected. Which cell adds more to the statistic?
Correct: the four-or-more cell, by a wide margin
Why: The two-services gap is 10 on an expected 330, giving 100 over 330, about 0.30. The four-or-more gap is 33 on an expected 48, giving 1089 over 48, about 22.69. A shortfall of two thirds of the expected count is enormous; a three percent excess is noise.
\[ \frac{(340 - 330)^2}{330} = \frac{100}{330} \approx 0.30, \qquad \frac{(15 - 48)^2}{48} = \frac{1089}{48} \approx 22.69 \]
If you chose the two-services cell, the size of the counts misled you. The statistic never asks how big a cell is; it asks how surprising the cell's gap is for a cell of that size. Here the biggest cell is almost silent and the smallest one is shouting.
The same reasoning tells you where to look first in any table: at cells whose expected count is small and whose gap is a large fraction of it. In this table that is the last cell, and it is the one the final conclusion will name.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 570-571 — Example 11.3
Worked example
The book asks you to compute this one by hand, with a chart of columns. Sixty managers, five days, and the claim that every day is equally likely. Build the table one column at a time.
Total the observations
Why: every expected count is built from this total.
\[ 15 + 12 + 9 + 9 + 15 = 60 \]
Notice that the total comes from the data, but the shares come from the claim. Both columns are about the same sixty managers, which is what makes it fair to compare them cell by cell.
Find each expected count
Why: the null gives each day one fifth of the sixty.
\[ E = 60 \times 0.2 = 12 \text{ for each day} \]
Subtract expected from observed
Why: the gap in each cell, Monday to Friday.
\[ O - E: \quad 3, \; 0, \; -3, \; -3, \; 3 \]
Before squaring, glance at the gaps: they add to zero, as they must. If your gaps do not add to zero, an expected count is wrong, and nothing after this line can be right.
Square each gap
Why: removes the signs so nothing cancels.
\[ (O - E)^2: \quad 9, \; 0, \; 9, \; 9, \; 9 \]
Divide each square by its expected count
Why: judges each gap against twelve.
\[ \frac{(O-E)^2}{E}: \quad 0.75, \; 0, \; 0.75, \; 0.75, \; 0.75 \]
Add the last column
Why: the sum is the test statistic.
\[ \chi^2 = 0.75 + 0 + 0.75 + 0.75 + 0.75 = 3 \]
Every day contributes the same 0.75 except Tuesday, because every gap had the same size, three, and every cell expected the same twelve. The statistic does not care which days were high and which were low; swap Monday's and Wednesday's counts and you get exactly 3 again.
Count the cells for the degrees of freedom
Why: five days, minus one.
\[ df = 5 - 1 = 4 \]
Check the gaps and the totals
Why: the gaps sum to zero and the expected column sums to sixty, so the table is consistent; and a statistic of 3 is below 4, the mean of a chi-square with four degrees of freedom, so you should expect an unremarkable p-value.
\[ 3 + 0 - 3 - 3 + 3 = 0, \quad 5 \times 12 = 60 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 568 — Example 11.2
Fill the middle
Example 11.3's last cell, families with four or more streaming services, observed 15 where 48 were expected. Fill in the middle of its term. Square the gap, then divide by the expected count.
Fill in the blanks
\frac108922.69 = \frac___}___ = ___
Why: The gap is 15 minus 48, which is minus 33. Its square is 1089, and 1089 divided by 48 is 22.6875, or 22.69 to two places. A negative gap gives a positive term once squared.
Notice how a single small cell can dominate. This one term is 22.69 out of the whole statistic's 29.65, more than three quarters. When you report a significant goodness-of-fit result, naming the cell that drives it is the most useful thing you can add.
And notice that the sign of the gap vanished. The statistic says how badly a cell misfits, never in which direction; to say that there were too few heavy streamers rather than too many, you go back and read the O and E columns themselves.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 570-571 — Example 11.3
Concept
The degrees of freedom count how many cells are free to vary once the total is fixed. Picture filling in the managers' table day by day, knowing only that the total must be 60.
\[ 15 + 12 + 9 + 9 + \underline{\quad} = 60 \]
You could have chosen the first four counts freely. The fifth is then forced, because it has to make the total sixty. Four free choices, so four degrees of freedom.
\[ \text{Friday} = 60 - (15 + 12 + 9 + 9) = 15, \qquad df = 5 - 1 = 4 \]
The same holds for every goodness-of-fit test: with k cells and a fixed total, k minus one counts are free and the last one is determined. The number of observations never enters. Sixty managers or six thousand, five days give four degrees of freedom.
\[ df = k - 1 = (\text{number of cells}) - 1 \]
Two consequences follow. When cells are combined to satisfy the condition on expected counts, k goes down, and so must the degrees of freedom. And when a random variable lumps outcomes together, as two coins lumping HT and TH into one head, the cells are the values of the variable, not the raw outcomes.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565 and 571 — df = number of categories minus one; df is not 600 minus 1
Trap
Example 11.3 surveys 600 families in five cells. A first attempt reasons from earlier chapters:
\[ df = n - 1 = 600 - 1 = 599 \]
and reads the p-value of 29.65 from a chi-square curve with 599 degrees of freedom.
The habit comes from Chapters 8 to 10, where the t distribution's degrees of freedom were the sample size minus one, so the number of observations feels like the natural thing to count.
Wrong. That curve is centred near 599, so 29.65 would look absurdly small.
The book adds a note for exactly this slip: df is not 600 minus one. The free quantities are the cell counts, not the families.
\[ df = k - 1 = 5 - 1 = 4 \]
On four degrees of freedom, 29.65 lies far out in the right tail, with a p-value of about six in a million: the opposite conclusion.
\[ P(\chi^2_4 > 29.65) \approx 0.000006 \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 571 — NOTE: df is not 600 minus 1
Section
Part 2
Concept
To turn a statistic of 3 into a p-value you need its distribution when the null hypothesis holds. Section 11.1 gave you the key fact: a chi-square variable with k degrees of freedom is a sum of k squared independent standard normal variables.
\[ \chi^2_{k} = Z_1^2 + Z_2^2 + \cdots + Z_k^2 \]
Each term of the goodness-of-fit statistic is roughly a squared standard score, a gap divided by its natural wobble. There are k of them, but they are tied together by the fixed total, which removes one degree of freedom. So, approximately, the statistic follows a chi-square distribution with k minus one degrees of freedom.
\[ \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i} \;\dot\sim\; \chi^2_{k-1} \quad \text{when } H_0 \text{ is true} \]
The dot over the tilde says approximately. The approximation is good when every expected count is reasonably large, which is where the condition of at least five comes from. Two facts about the curve make quick checks possible: its mean equals its degrees of freedom, and its standard deviation is the square root of twice that.
\[ \mu = df, \qquad \sigma = \sqrt{2 \cdot df} \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.1, p. 564 — facts about the chi-square distribution
Notation
Every example in the book ends its calculation with one line, the probability statement. It packs the whole decision into a few symbols, so read it piece by piece before you use it.
Annotate
On: \( p\text{-value} = P\left(\chi^2_{4} > 29.65\right) = 0.000006 \)
Notice what the statement does not say. It is not the probability that the far-western families fit the national distribution. It is the probability of data this far from the claim, if the claim were exactly right. A tiny value makes the claim hard to believe; it does not put a number on how likely the claim is.
On a TI-83 or TI-84 this is the chi-square cdf from 29.65 to a huge number, on four degrees of freedom. Without a calculator you can bracket it with a table of critical values: 29.65 is beyond every cutoff the table lists for four degrees of freedom, so the p-value is smaller than the smallest tail area in the table.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 571-572 — Example 11.3's probability statement and calculator steps
Picture it
Here are five members of the family. Every goodness-of-fit test picks one of them, by its number of cells minus one, and reads its p-value from that curve.
Figure (svg): Five chi-square density curves on one axis from 0 to 22. With 2 degrees of freedom the curve starts at its highest point at zero and falls. With 3, 4, 6 and 10 degrees of freedom each curve rises from zero to a peak and then falls, the peaks moving right and getting lower and wider as the degrees of freedom grow. Each curve is labelled with its degrees of freedom.
All the curves start at zero, because the statistic cannot be negative, and all of them are skewed right. With only two degrees of freedom the curve is highest at zero; from three upward it rises to a peak just left of its mean and trails off to the right.
Use the mean as a yardstick. A statistic close to its degrees of freedom is entirely typical; one several times its degrees of freedom is far out in the tail. That one comparison will tell you roughly what any p-value in this section should be before you compute it.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.1, pp. 564-565 — Figures 11.2 and 11.3
Tweak it
Move the slider from 2 to 12 degrees of freedom and watch the curve. Read off where the peak sits each time, and compare it with the readout of the mean.
Parameter explorer
Drag the degrees of freedom. Where is the peak compared with the mean, and how does the spread change?
\[ df = {k}, \qquad \mu = {k}, \qquad \sigma = \sqrt{2 \times {k}} \]
The peak sits at the degrees of freedom minus two, always a little left of the mean, which is the right skew showing itself. As the degrees of freedom grow, the curve moves right, flattens, and becomes more symmetric.
This is why the same statistic can mean opposite things. A value of 9 is the 5 percent cutoff region for four degrees of freedom, but it is barely past the middle for ten. You can never judge a chi-square statistic without its degrees of freedom beside it.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.1, p. 564 — a different chi-square curve for each df
Picture it
Is the chi-square curve really the right yardstick for sixty managers? Check it directly. The computer surveyed sixty managers two thousand times, with every weekday exactly equally likely, and computed the statistic each time.
Figure (svg): A histogram of 2000 simulated values of the goodness-of-fit statistic, each from 60 managers whose busiest day was chosen with every weekday equally likely. The bars rise from zero to a peak between 2 and 3 and trail off to the right past 12. The chi-square curve with 4 degrees of freedom lies along the tops of the bars. Bars at 3 and above are drawn in yellow.
The bars come only from random weekdays, with no formula involved, yet they follow the chi-square curve with four degrees of freedom closely. Their average is 4.12, close to the curve's mean of 4.
Now place the real survey on the picture. 1169 of the 2000 fair surveys, about 58 percent, gave a statistic of 3 or more. That is the simulated p-value, and it agrees with the 0.5578 from the curve to within the simulation's own wobble. When the days really are equal, a value like the managers' 3 is the commonest thing in the world.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 568-569 — Example 11.2, checked by simulation
Concept
In Chapter 9 you chose the tail from the wording of the alternative hypothesis. Here the choice is made for you by the statistic itself. Every term is a squared gap over a positive count, so any misfit, in any cell, in either direction, can only make the statistic bigger.
\[ \text{perfect fit: } O_i = E_i \text{ for all } i \Rightarrow \chi^2 = 0 \]
A statistic near zero means the counts sit almost exactly where the null hypothesis put them. That is the best possible news for the null, so it can never be evidence against it. Only large values are evidence of misfit, and the p-value is the area to the right.
\[ p\text{-value} = P(\chi^2_{df} > \chi^2_{\text{obs}}) \]
The book puts it this way: if the observed and expected values are not close, the statistic gets very large and lands way out in the right tail. Note that the alternative here, does not fit, has no direction at all; it is not a two-sided test in Chapter 9's sense, because two sides of misfit both land in the same tail.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — the goodness-of-fit test is almost always right-tailed
Counterexample
The book says the test is almost always right-tailed. Find the exception yourself: what would it mean for a statistic to sit in the far left tail, suspiciously close to zero?
Discussion prompt
Suppose 600 families had produced observed counts of exactly 60, 96, 330, 66 and 48, matching the expected counts perfectly. Compute the statistic and its p-value. Is this evidence for the claim, or could a fit this good itself be suspicious?
That is the almost. The statistician R. A. Fisher famously argued that Gregor Mendel's pea counts sat too close to their expected ratios to be honest chance, a left-tail argument. In ordinary use, and in every example of this section, you test fit, so you shade the right tail.
So a statistic of exactly zero is not a triumph for the claim. It is either a coincidence, which is rare with many cells, or a sign that someone has been tidying the data. Real counts wobble, and a good fit looks like a statistic near its degrees of freedom, not near zero.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — almost always right-tailed
Worked example
The statistic was 3 on four degrees of freedom. Finish the test at the 5 percent level, and end it with a sentence about the population of employees, not about the sixty managers.
Four degrees of freedom means the yardstick curve has mean 4 and standard deviation the square root of 8, about 2.83. Before computing, a statistic of 3 already looks typical.
Write the distribution for the test
Why: five cells, so four degrees of freedom.
\[ \chi^2_4 \]
Write the probability statement
Why: the test is right-tailed, so the p-value is the area beyond 3.
\[ p\text{-value} = P(\chi^2_4 > 3) \]
Evaluate the tail
Why: for an even number of degrees of freedom the tail has a closed form; with four it is this.
\[ P(\chi^2_4 > x) = e^{-x/2}\left(1 + \frac{x}{2}\right) \]
Substitute 3
Why: e to the minus 1.5 is 0.2231.
\[ e^{-1.5}(1 + 1.5) = 0.2231 \times 2.5 \approx 0.5578 \]
That closed form is not something to memorise; it simply lets you see where the calculator's 0.5578 comes from without a TI-83. On the calculator the same number is the chi-square cdf from 3 to a huge value, on four degrees of freedom.
Figure (svg): A chi-square curve with 4 degrees of freedom from 0 to 14. A yellow line marks the observed statistic 3. The area to the right of 3 is shaded blue and labelled p-value 0.5578. A dashed red line at 9.488 marks the 5 percent critical value, with the small area beyond it shaded red.
Compare with the significance level
Why: the p-value is far above alpha.
\[ 0.5578 > 0.05 \Rightarrow \text{do not reject } H_0 \]
Conclusion, in the book's frame: at the 5 percent level, from the sample data, there is not sufficient evidence to conclude that the absent days do not occur with equal frequencies. That is not a proof that they are equal; it says sixty managers cannot detect a difference, if there is one.
Check against the yardstick
Why: the mean of the chi-square with four degrees of freedom is 4, and 3 lies below it, so more than half the curve must be beyond 3; the simulation gave the same answer.
\[ 3 < 4 = \mu \Rightarrow p > 0.5 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 568-569 — Example 11.2 and Figure 11.4
Estimation
Try It 11.2: 56 students each named the night on which they did most of their homework. The goodness-of-fit statistic for equal nights comes to 4.5. Estimate the p-value before anyone computes it.
| night | Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|---|
| students | 11 | 8 | 10 | 7 | 10 | 5 | 5 |
Predict first
Seven nights, a statistic of 4.5. Roughly where is the p-value?
Correct: above one half
Why: Seven cells give six degrees of freedom, so the curve's mean is 6. A statistic of 4.5 is below the mean, which puts more than half of the curve to its right. The exact value is 0.6093.
\[ df = 7 - 1 = 6, \qquad 4.5 < 6 = \mu \Rightarrow p > 0.5 \]
The habit worth building is the comparison of the statistic with its degrees of freedom. Below them, the p-value is above about a half; at about twice them, it is in the region of a few percent; at several times them, it is tiny. It catches wrong curves and wrong arithmetic before they reach a conclusion.
Here the comparison already settles the decision at any usual significance level: no p-value above one half can be below 0.05. The exact value matters only for the report, and the next slides show how to read it.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 569 — Try It 11.2
Intuition
You will not always have a calculator, and you should never trust one blindly. A small table of the chi-square curves this section uses lets you place any statistic in seconds.
| df | mean | standard deviation | 5% cutoff | 1% cutoff |
|---|---|---|---|---|
| 2 | 2 | 2.00 | 5.991 | 9.210 |
| 3 | 3 | 2.45 | 7.815 | 11.345 |
| 4 | 4 | 2.83 | 9.488 | 13.277 |
| 6 | 6 | 3.46 | 12.592 | 16.812 |
Read across a row. The 5 percent cutoff sits roughly two standard deviations above the mean, and the 1 percent cutoff roughly three, a little further than for a normal curve because of the long right tail.
\[ \text{df} = 4: \quad 4 + 2(2.83) = 9.66 \approx 9.488 \]
Now place this section's statistics. The weekday 3 and the homework 4.5 sit below their means: ordinary. The coins' 2.14 is barely above its mean of 2: ordinary. Example 11.1's 14.29 is past the 1 percent cutoff for three degrees of freedom, and the streaming 29.65 is more than twice the 1 percent cutoff for four. The decisions follow before any p-value is computed.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.1, p. 564 — μ = df and σ = √(2df); cutoffs computed in node
Worked example
Do students do the majority of their homework equally on all seven nights? The book asks what type of test fits; here is the test run in full, at the 5 percent level.
Name the test and the hypotheses
Why: one categorical variable, a claimed distribution: a goodness-of-fit test against the uniform.
\[ H_0: \text{ nights equally likely}, \quad H_a: \text{ not equally likely} \]
Find the expected counts
Why: 56 students over 7 nights.
\[ E = \frac{56}{7} = 8 \text{ per night} \]
Every expected count is 8, which clears the condition of at least five, so no cells need combining. Fifty-six students is a small sample for seven cells; with forty-two students the expected counts would drop to six, and with thirty-four they would fall below five.
Find the gaps
Why: Sunday to Saturday.
\[ O - E: \quad 3, \; 0, \; 2, \; -1, \; 2, \; -3, \; -3 \]
Square each gap
Why: nothing cancels now.
\[ (O-E)^2: \quad 9, \; 0, \; 4, \; 1, \; 4, \; 9, \; 9 \]
Divide by 8 and add
Why: every cell expects 8, so add the squares first and divide once.
\[ \chi^2 = \frac{9 + 0 + 4 + 1 + 4 + 9 + 9}{8} = \frac{36}{8} = 4.5 \]
Find the p-value
Why: seven cells, six degrees of freedom, right tail.
\[ p = P(\chi^2_6 > 4.5) \approx 0.6093 \]
The book's question only asks which test to use, and the answer is this one: a goodness-of-fit test against the uniform distribution. Running it to the end shows that the hunch of the teachers, homework done equally through the week, survives the data.
Figure (svg): A chi-square curve with 6 degrees of freedom from 0 to 20. A yellow line marks the statistic 4.5 and the area to its right is shaded blue, labelled p-value 0.6093. A dashed red line at 12.59 marks the 5 percent cutoff.
Decide
Why: the p-value is far above alpha.
\[ 0.6093 > 0.05 \Rightarrow \text{do not reject } H_0 \]
In context: at the 5 percent level, there is not sufficient evidence that students' main homework nights are unequally spread over the week. The weekend dip, five and five against an expected eight, is the kind of gap fifty-six students produce by chance.
Check the totals and the gaps
Why: the expected counts total 56, the gaps total zero, and every expected count of 8 is at least five, so the test was allowed.
\[ 7 \times 8 = 56, \quad 3 + 0 + 2 - 1 + 2 - 3 - 3 = 0 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 569 — Try It 11.2
Section
Part 3
Concept
Every expected count is the sample size times a claimed proportion. What changes from problem to problem is the form in which the claimed proportions reach you, and turning them into proportions is the first real step of every test.
| the claim arrives as | example | proportions | expected counts |
|---|---|---|---|
| equal shares | absences equal on 5 days, n = 60 | 1/5 each | 60 × 0.2 = 12 each |
| percentages | streaming services: 10, 16, 55, 11, 8 % | 0.10, 0.16, 0.55, 0.11, 0.08 | 60, 96, 330, 66, 48 for n = 600 |
| a probability model | two fair coins, X = number of heads | 1/4, 1/2, 1/4 | 25, 50, 25 for n = 100 |
Equal shares are the simplest: divide the total by the number of cells. Percentages must be turned into proportions and multiplied by this sample's total. A probability model, such as fair coins or a binomial, needs its probabilities worked out first, and that is where a tree diagram earns its place.
\[ E_i = n \cdot p_i, \qquad \sum p_i = 1 \Rightarrow \sum E_i = n \]
The last line is your built-in check. The claimed proportions must add to one, so the expected counts must add to the sample size. If they do not, either the claim is incomplete or the arithmetic has slipped, and the test cannot be run until you find out which.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 568-573 — Examples 11.2, 11.3 and 11.4
Intuition
An expected count is easy to misread as a prediction of what the sample will show. It is not. It is the long-run average of that cell's count over many imaginary samples drawn from a population that matches the claim exactly.
\[ E_i = n p_i = \text{average of } O_i \text{ over many samples, if } H_0 \text{ is true} \]
Two things follow. First, an expected count need not be a whole number. With 56 students and a claim of one third, one half and one sixth, the expected counts would be 18.67, 28 and 9.33, and those are exactly the numbers to use; rounding them throws away precision and breaks the check that they add to 56.
\[ 56 \times \tfrac{1}{3} = 18.67, \quad 56 \times \tfrac{1}{2} = 28, \quad 56 \times \tfrac{1}{6} = 9.33 \]
Second, observed counts are supposed to differ from expected ones. Even when the claim is exactly true, the managers' counts wobble from survey to survey, as the simulation showed. The test never asks whether O equals E; it asks whether the gaps are bigger than that ordinary wobble.
Keep that in mind when a gap looks large. A shortfall of five in a cell expecting twenty-five is a fifth of the cell, but chance alone produces gaps of that size routinely; the statistic, not your eye, decides.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — expected values: what you would expect if the null were true
Worked example
A study says the number of streaming services American families have is distributed as below. A random sample of 600 far-western families gave the observed counts beside it. First, turn the national percentages into expected counts for 600 families.
| streaming services | 0 | 1 | 2 | 3 | 4+ |
|---|---|---|---|---|---|
| national percent | 10 | 16 | 55 | 11 | 8 |
| observed, far West | 66 | 119 | 340 | 60 | 15 |
Check the percentages describe a whole distribution
Why: they must add to 100.
\[ 10 + 16 + 55 + 11 + 8 = 100 \]
If they had added to 97 or 103, the claim would be incomplete or rounded, and you would need to ask where the missing share went before testing anything. Here the claim covers every family, so it is a complete distribution.
Convert each percentage to a proportion
Why: divide by 100.
\[ 0.10, \; 0.16, \; 0.55, \; 0.11, \; 0.08 \]
Multiply each proportion by the sample size
Why: 600 families in the sample.
\[ 0.10 \times 600 = 60, \quad 0.16 \times 600 = 96, \quad 0.55 \times 600 = 330 \]
Finish the last two cells
Why: the same multiplication.
\[ 0.11 \times 600 = 66, \quad 0.08 \times 600 = 48 \]
The percentages describe the whole American population, but the expected counts describe this sample: what 600 families drawn from a population that matched the national distribution would show on average. That is why the multiplier is 600 and not anything about the population's size.
Check the condition on expected counts
Why: the smallest expected count is 48, far above five.
\[ \min E = 48 \ge 5 \]
Check the totals agree
Why: the expected counts must add to 600, the same as the observed.
\[ 60 + 96 + 330 + 66 + 48 = 600 = 66 + 119 + 340 + 60 + 15 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 569-571 — Example 11.3, Tables 11.9 to 11.11
Worked example
Now build the statistic from the two columns. The book lets the calculator do it; here every cell is visible, so you can see which one carries the result.
On a TI-83 or TI-84 the book puts the observed counts in one list, the expected in another, and asks for the sum of the squared gaps over the expected counts. That is exactly the column you are about to build by hand.
Subtract expected from observed
Why: 0, 1, 2, 3 and 4 or more services.
\[ O - E: \quad 6, \; 23, \; 10, \; -6, \; -33 \]
Before going on, read the gaps. Four of the five are modest, between six and twenty-three families. The last is a shortfall of thirty-three families in a cell that expected only forty-eight, and you can already guess which term will dominate.
Square each gap
Why: removes the signs.
\[ (O-E)^2: \quad 36, \; 529, \; 100, \; 36, \; 1089 \]
Divide the first three squares by their expected counts
Why: 60, 96 and 330.
\[ \frac{36}{60} = 0.6000, \quad \frac{529}{96} = 5.5104, \quad \frac{100}{330} = 0.3030 \]
Divide the last two
Why: 66 and 48.
\[ \frac{36}{66} = 0.5455, \quad \frac{1089}{48} = 22.6875 \]
Keep four decimal places until the end. Rounding each term to one place would give 0.6, 5.5, 0.3, 0.5 and 22.7, which add to 29.6, close but not the book's 29.65; carrying the precision is what makes your answer match.
Add the five terms
Why: the goodness-of-fit statistic.
\[ \chi^2 = 0.6000 + 5.5104 + 0.3030 + 0.5455 + 22.6875 = 29.6464 \]
Count the degrees of freedom
Why: five cells, minus one; not 600 minus one.
\[ df = 5 - 1 = 4 \]
Check the gaps and the dominant cell
Why: the gaps add to zero, as they must; and the four-or-more cell is 22.69 of the 29.65, so the result rests mainly on that one shortfall.
\[ 6 + 23 + 10 - 6 - 33 = 0, \quad \frac{22.6875}{29.6464} \approx 0.77 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 571 — Example 11.3: the test statistic 29.65
Picture it
Draw the five terms as bars and the structure of the result is obvious at a glance.
Figure (svg): Horizontal bars for the five cells of Example 11.3. Zero services contributes 0.60, one service 5.51, two services 0.30, three services 0.55 and four or more services 22.69, a bar far longer than the rest. The total is 29.65, and the four-or-more cell is 77 percent of it.
The middle cell, two services, holds more than half of all the families, yet its term is the smallest of the five: 340 against 330 is a three percent excess, ordinary sampling noise. The four-or-more cell holds fifteen families and supplies three quarters of the evidence.
The one-service cell is the second contributor: 119 against 96, about a quarter more than expected. So the far-western distribution differs in a specific way: families there are much less likely than the nation to have four or more services and somewhat more likely to have exactly one. That is a far richer conclusion than reject the null hypothesis, and it costs nothing but reading the table you already built.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 570-571 — Example 11.3
Worked example
Test at the 1 percent level whether the far-western distribution differs from the distribution for the American population as a whole. The statistic is 29.65 on four degrees of freedom.
The significance level is 1 percent this time, stricter than the 5 percent in the other examples. A stricter alpha asks for stronger evidence before rejecting, so the bar for the statistic moves further right, to 13.28.
Write the hypotheses in sentences
Why: the null is that the far-western distribution is the same as the nation's.
\[ H_0: \text{ far West fits the national distribution}, \quad H_a: \text{ it does not} \]
The book says this test is always right-tailed. The reason is the one from Part 2: every misfit in any cell makes the statistic larger, so evidence against the national distribution can only sit to the right.
Write the probability statement
Why: right tail on four degrees of freedom.
\[ p\text{-value} = P(\chi^2_4 > 29.65) \]
Evaluate with the four-df tail formula
Why: e to the minus 14.82 is about 3.65 in ten million.
\[ e^{-14.823}(1 + 14.823) \approx 3.65 \times 10^{-7} \times 15.82 \approx 0.0000058 \]
Figure (svg): A chi-square curve with 4 degrees of freedom from 0 to 32. A dashed red line at 13.28 marks the 1 percent cutoff, with the region beyond it shaded red. A yellow line marks the observed statistic 29.65, far out in the right tail where the curve is indistinguishable from the axis. A label says the p-value is 0.000006.
Compare with alpha
Why: alpha is 0.01 here.
\[ 0.000006 < 0.01 \Rightarrow \text{reject } H_0 \]
Conclusion: at the 1 percent significance level, from the data, there is sufficient evidence to conclude that the number-of-streaming-services distribution for the far western United States is different from the distribution for the American population as a whole. Add what the bars showed: far fewer far-western families have four or more services than the national figures predict.
Check against the yardstick and the cutoff
Why: the mean on four df is 4 and the standard deviation about 2.83, so 29.65 is about nine standard deviations above the mean; it also more than doubles the 1 percent cutoff of 13.28.
\[ \frac{29.65 - 4}{\sqrt{8}} \approx 9.1, \qquad 29.65 > 13.28 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 571 — Example 11.3 and Figure 11.5
Ranking
Try It 11.3 compares 1,000 Eastern students with the national distribution of pets at home. Before computing anything, rank the five cells by how much each will add to the statistic. Think about the gap relative to the expected count, not the gap alone.
| pets | 0 | 1 | 2 | 3 | 4+ |
|---|---|---|---|---|---|
| expected | 180 | 250 | 300 | 180 | 90 |
| observed | 210 | 240 | 320 | 140 | 90 |
Put in order
Order the cells from the largest contribution to the smallest.
Why: The contributions are 1600 over 180, about 8.89, for three pets; 900 over 180, exactly 5, for none; 400 over 300, about 1.33, for two; 100 over 250, 0.4, for one; and zero for four or more, where observed equals expected.
The three-pet cell wins because its gap of 40 is large and its expected count of 180 is modest. The two-pet gap of 20 is half as large and sits over a bigger expected count, so its squared gap is a quarter of the size and is divided by more.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 572 — Try It 11.3
Worked example
At the 1 percent level, does the distribution of number of pets among Eastern students differ from the national student distribution? What is the p-value? The book gives the percentages; the expected counts are yours to build.
This is Example 11.3 again with new numbers: percentages for a national population, a sample from one region, and a 1 percent significance level. Follow the same steps, keeping every column visible.
Convert the national percentages to expected counts
Why: multiply each proportion by 1,000 students.
\[ 0.18, 0.25, 0.30, 0.18, 0.09 \;\to\; 180, \; 250, \; 300, \; 180, \; 90 \]
Check the expected column before using it: 180 plus 250 plus 300 plus 180 plus 90 is 1,000, the sample size, and the smallest expected count, 90, is far above five. Nothing needs merging.
Find the gaps
Why: observed minus expected, 0 pets to 4 or more.
\[ O - E: \quad 30, \; -10, \; 20, \; -40, \; 0 \]
Square them
Why: all signs gone.
\[ (O-E)^2: \quad 900, \; 100, \; 400, \; 1600, \; 0 \]
Divide by the expected counts
Why: 180, 250, 300, 180 and 90.
\[ 5.0000, \; 0.4000, \; 1.3333, \; 8.8889, \; 0 \]
Add
Why: the statistic.
\[ \chi^2 = 5 + 0.4 + 1.3333 + 8.8889 + 0 = 15.6222 \]
The ranking slide's order is confirmed: three pets first, none second, and the four-or-more cell contributing nothing at all because observed and expected agree exactly.
Figure (svg): Grouped bar chart for number of pets: 0, 1, 2, 3, 4 or more. Orange observed counts for 1,000 Eastern students: 210, 240, 320, 140, 90. Blue expected counts from the national percentages: 180, 250, 300, 180, 90. The biggest gaps are at 0 pets, 30 above, and 3 pets, 40 below.
Find the p-value on four degrees of freedom
Why: five cells minus one, right tail.
\[ p = P(\chi^2_4 > 15.62) = e^{-7.811}(1 + 7.811) \approx 0.0036 \]
Decide at the 1 percent level
Why: the p-value is below alpha.
\[ 0.0036 < 0.01 \Rightarrow \text{reject } H_0 \]
In context: at the 1 percent level there is sufficient evidence that the number-of-pets distribution for Eastern students differs from the national one, mainly because fewer Eastern students have three pets and more have none.
Check the totals and the cutoff
Why: the expected counts total 1,000 like the observed, and 15.62 exceeds the 1 percent cutoff of 13.28, agreeing with the p-value.
\[ 180 + 250 + 300 + 180 + 90 = 1000, \quad 15.62 > 13.28 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 572 — Try It 11.3
Matching
Each claim below is tested on a sample of 200. Match it to its expected counts. One pair of claims looks almost the same; the difference is in how the probabilities were produced.
Match the pairs
Why: Equal shares of 200 over four faces give 50 each. The seed percentages times 200 give 80, 60, 40 and 20. Two coins give zero, one or two heads with chances one quarter, one half and one quarter, so 50, 100 and 50. The blood-type proportions times 200 give 90, 80, 22 and 8.
Look again at the blood types. The last expected count is 8, which passes the condition of at least five, but only just. With a sample of 100 instead of 200 it would be 4, and the AB cell would have to be combined with a neighbour before the test could run.
And notice that the coins have three cells, not four, because the claim is about the number of heads. Part 5 returns to that.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 568-573 — expected values from theory
Trap
For Example 11.3, a first attempt puts the national percentages straight into the E column:
\[ \frac{(66-10)^2}{10} = 313.6 \]
\[ \frac{(119-16)^2}{16} = 663.1 \]
\[ \frac{(340-55)^2}{55} = 1476.8 \]
\[ \chi^2 \approx 2677.9 \text{ (five cells)} \]
Wrong. The columns describe different things: counts of families against percents of a population.
Expected counts must be counts for this sample. Multiply each proportion by 600 first, so both columns add to 600.
\[ E_1 = 0.10 \times 600 = 60 \]
\[ E = 60, 96, 330, 66, 48 \]
A quick alarm for this slip: the E column should add to the sample size. Here it added to 100, not 600.
\[ \sum E = 100 \]
\[ \sum O = 600 \]
And the statistic itself is a warning: thousands, on four degrees of freedom, where a typical value is about 4.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 570 — multiply the percentage by 600
Section
Part 4
Concept
The book attaches one condition to this test: the expected value for each cell needs to be at least five. It is a condition on the expected counts, which you can check before collecting a single observation, not on the observed ones.
\[ E_i \ge 5 \quad \text{for every cell } i \]
The reason is the approximation underneath. The chi-square curve is the right yardstick only when each cell's term behaves like a squared normal score. A count with a large expected value wobbles in a roughly normal way; a count expecting 2 is lumpy and skewed, mostly 0, 1, 2 or 3, now and then much more.
Worse, a tiny E sits in the denominator. One stray observation in a cell expecting 2 swings that cell's term a long way: observe 4 instead of 2 and the term is 2 by itself; observe 6 and it is 8.
\[ \frac{(4 - 2)^2}{2} = 2, \qquad \frac{(6 - 2)^2}{2} = 8 \]
Such cells inflate the statistic in ways the chi-square curve does not expect, so the p-value comes out too small and a fit is rejected too often. A small observed count, such as 1 or 4, is no problem in itself; only the expected count is checked.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — NOTE: the expected value for each cell needs to be at least five
Worked example
Faculty expected 100 students to miss class as in the first row below; a survey across mathematics courses observed the second row. Can you run a goodness-of-fit test on the tables as they appear?
Absenteeism matters to instructors because missing class appears to raise the drop rate, so the faculty's picture of how often students miss shapes how they plan. The study asks whether the actual pattern follows that perception.
| absences per term | 0–2 | 3–5 | 6–8 | 9–11 | 12+ |
|---|---|---|---|---|---|
| expected students | 50 | 30 | 12 | 6 | 2 |
| observed students | 35 | 40 | 20 | 1 | 4 |
Write the hypotheses in sentences
Why: the faculty's perception is the claimed distribution.
\[ H_0: \text{ absenteeism fits faculty perception}, \quad H_a: \text{ it does not} \]
Check the totals
Why: both columns should describe 100 students.
\[ 50 + 30 + 12 + 6 + 2 = 100 = 35 + 40 + 20 + 1 + 4 \]
Check every expected count against five
Why: scan the expected row, not the observed one.
\[ 50, \; 30, \; 12, \; 6 \ge 5, \quad 2 < 5 \]
The 9 to 11 cell observed only 1 student, and that is not the problem. The problem is the 12-or-more cell, which expects only 2. The book's answer to part (a) is therefore no: the test cannot be run on the tables as they stand.
Why not simply drop the small cell? Because the four students in it are real data, and throwing them away would change the sample and the total. Merging keeps every student in the test and every count in the total.
Choose the cell to merge with
Why: combine the small cell with its neighbour on the same scale, the 9 to 11 cell, to keep the categories meaningful.
\[ \text{9--11} + \text{12+} = \text{9+} \]
Check the merged cell
Why: the expected counts add, and so do the observed.
\[ E = 6 + 2 = 8 \ge 5, \quad O = 1 + 4 = 5 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565-566 — Example 11.1(a), Tables 11.1 and 11.2
Picture it
The faculty's expected counts, drawn against the line at five. One bar falls below it.
Figure (svg): Two bar panels of expected numbers of students. Left, the faculty's five categories 0-2, 3-5, 6-8, 9-11 and 12 or more with expected counts 50, 30, 12, 6 and 2; a dashed red line at 5 shows the 12-or-more bar falling below it. Right, after merging the last two categories into 9 or more: 50, 30, 12 and 8, every bar above the line.
Merging rules are common sense rather than formula. Combine a too-small cell with a neighbour, so the new category still means something: 9 or more absences is a sensible group, whereas lumping 12-plus with 0 to 2 would not be. Add the expected counts, add the observed counts, and keep the totals unchanged.
Merging is not free. Every merge costs a cell, and therefore a degree of freedom, and it blurs a distinction the faculty had made: the test can no longer say whether 9 to 11 and 12-plus behave differently. Merge only as much as the condition requires, and say in the report that you did.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 566-567 — Tables 11.3 and 11.4
Prediction
A survey of 120 commuters classifies one-way travel time in five bands, and the claimed distribution gives these expected counts. One band fails the condition. Decide what to merge before reading on.
| minutes | under 10 | 10–19 | 20–29 | 30–44 | 45+ |
|---|---|---|---|---|---|
| expected | 3 | 36 | 48 | 27 | 6 |
Predict first
The under-10 band expects only 3 commuters. What is the best repair?
Correct: merge it with the 10 to 19 band, giving under 20 minutes
Why: Merge a small cell with its neighbour on the scale, so the new band still means something: under 20 minutes expects 39. Joining the shortest and longest commutes would make a meaningless category, deleting data changes the sample, and the condition looks only at expected counts.
\[ 3 + 36 = 39 \ge 5, \qquad k = 4, \qquad df = 4 - 1 = 3 \]
The 45-plus band expects 6, which passes, so it stays as it is; merging it too would cost a second degree of freedom for no reason. After the single merge there are four cells, and the degrees of freedom drop from four to three.
If two small cells sit at opposite ends of a scale, merge each with its own neighbour. The goal is the fewest merges that make every expected count at least five while keeping categories a reader can interpret.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 566 — combine that group with the neighbouring group
Worked example
After combining, the tables have four categories. Part (b) asks for the degrees of freedom, and the only trap is counting from the wrong table.
Combining also changed the meaning of the last category. It now reads 9 or more absences, and any conclusion about it applies to that wider group, not to 9 to 11 or 12-plus separately.
| absences per term | 0–2 | 3–5 | 6–8 | 9+ |
|---|---|---|---|---|
| expected students | 50 | 30 | 12 | 8 |
| observed students | 35 | 40 | 20 | 5 |
Count the cells of the table you will test
Why: the merged table, not the original.
\[ k = 4 \]
Notice that the observed count in the merged cell is exactly 5. That is irrelevant to the condition, which looks only at the expected count of 8; an observed count of 0 there would have been allowed too.
Subtract one
Why: the four counts are tied to a total of 100.
\[ df = k - 1 = 4 - 1 = 3 \]
The original table had five cells and would have given four degrees of freedom. That number is now wrong, because three counts plus the fixed total determine the fourth. If you merge, you must recount.
Check the totals survived the merge
Why: merging moves counts between columns of the table but never creates or loses any.
\[ 50 + 30 + 12 + 8 = 100, \quad 35 + 40 + 20 + 5 = 100 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 567 — Example 11.1(b): df = 4 − 1 = 3
Worked example
The book stops at the degrees of freedom. Run the test to the end: does student absenteeism fit faculty perception?
The merged table has four cells with expected counts 50, 30, 12 and 8, all at least five, and observed counts 35, 40, 20 and 5. The steps are exactly those of Example 11.2.
Find the gaps on the merged table
Why: 0 to 2, 3 to 5, 6 to 8, 9 or more.
\[ O - E: \quad -15, \; 10, \; 8, \; -3 \]
The signs already tell a story. The faculty expected 50 students in the lightest band and saw 35, while the middle bands came out heavier than expected. Squaring is about to throw that direction away, so note it now for the conclusion.
Square them
Why: signs removed.
\[ 225, \; 100, \; 64, \; 9 \]
Divide by the expected counts
Why: 50, 30, 12 and 8.
\[ \frac{225}{50} = 4.5, \quad \frac{100}{30} = 3.3333, \quad \frac{64}{12} = 5.3333, \quad \frac{9}{8} = 1.125 \]
Add
Why: the statistic.
\[ \chi^2 = 4.5 + 3.3333 + 5.3333 + 1.125 = 14.2917 \]
Find the p-value on three degrees of freedom
Why: right tail.
\[ p = P(\chi^2_3 > 14.29) \approx 0.0025 \]
Figure (svg): A chi-square curve with 3 degrees of freedom from 0 to 18. A dashed red line at 7.815 marks the 5 percent cutoff, with the region beyond shaded red. A yellow line marks the statistic 14.29, well inside the red region, labelled p-value 0.0025.
Decide
Why: the p-value is below alpha.
\[ 0.0025 < 0.05 \Rightarrow \text{reject } H_0 \]
In context: at the 5 percent level there is sufficient evidence that student absenteeism does not fit the faculty's perception. The pattern is specific: fewer students than expected miss only 0 to 2 classes, and more than expected miss 3 to 8, so absenteeism is worse than the faculty assume.
Check the gaps and the cutoff
Why: the gaps add to zero, and 14.29 is beyond the 5 percent cutoff of 7.815 on three degrees of freedom.
\[ -15 + 10 + 8 - 3 = 0, \quad 14.29 > 7.815 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565-567 — Example 11.1, finished
Comparison
Fill in the blanks. The middle column is the test run illegally on the five original cells; the right-hand column is the legal merged test. The last row is a third version: merged cells but the old degrees of freedom left in place.
Comparison matrix
| five cells, unmerged (not allowed) | four cells, merged | |
|---|---|---|
| smallest expected count | 2 | 8 |
| degrees of freedom | 4 | 3 |
| statistic | 19.33 | 14.29 |
| p-value | 0.0007 | 0.0025 |
| merged statistic read on df 4 by mistake | — | 0.0064 |
The unmerged statistic is bigger, 19.33 against 14.29, and most of the difference comes from the 12-plus cell: 4 observed against 2 expected gives a term of 2 from a cell that should not be in the test. A tiny expected count inflating the statistic is exactly what the condition guards against.
\[ \frac{(4-2)^2}{2} = 2, \qquad \frac{(1-6)^2}{6} = 4.17 \]
Reading the merged 14.29 on the old four degrees of freedom gives 0.0064 instead of 0.0025, more than double. Here the decision survives either way, but a test nearer the boundary would not be so forgiving, and the wrong curve is wrong whatever the decision.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565-567 — Example 11.1, three ways
Sorting
For each set of expected counts, decide whether the test can run as it stands or whether cells must first be combined. Look only at the expected counts.
Sort into buckets
Sort each table by whether the condition on expected counts is met.
The two items that catch people are the last table, whose observed 3 looks too small but is not checked, and the table with an expected 4.5, which fails even though it rounds to 5. The condition is at least five, read exactly.
The other borderline case, an expected count of exactly 5, passes. If you find yourself merging a cell that expects 5, you are spending a degree of freedom for nothing.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — at least five in each cell
Step zero
A factory manager lists expected defects for five production bands as 5, 6, 7, 8 and 10, and a sample shows 5, 7, 8, 9 and 11. The book asks for the hypotheses and the degrees of freedom. Before you write either, check the two columns against each other.
| number produced | 0–100 | 101–200 | 201–300 | 301–400 | 401–500 |
|---|---|---|---|---|---|
| expected defects | 5 | 6 | 7 | 8 | 10 |
| observed defects | 5 | 7 | 8 | 9 | 11 |
Discussion prompt
What do you check first, what goes wrong, and what are the hypotheses and degrees of freedom once it is repaired?
The book's own answer, df equal to 4, survives the repair, because the number of cells is unchanged. But a statistic computed from the printed columns, 0.53, would be wrong: with rescaled expectations it is 0.08. A step zero of adding both columns catches this in seconds.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 567-568 — Try It 11.1, Tables 11.5 and 11.6
Error analysis
Here is a write-up of Example 11.1 that combines the cells correctly and then goes wrong. Find the line that fails, and say what it does to the conclusion.
Annotate
On: \( \chi^2 = 14.29, \quad df = 5 - 1 = 4, \quad p = P(\chi^2_4 > 14.29) = 0.0064 \)
The degrees of freedom belong to the table you actually test. Combining cells changes that table, so the count of cells has to be redone after every merge, not copied from the problem statement.
A habit that prevents this slip is to write the df line directly under the final table, never under the original one. Then the k you count is the k you just looked at.
Notice too which direction the error runs. More degrees of freedom move the curve right, which always makes a fixed statistic less surprising, so this slip can only make evidence look weaker than it is; on a closer call it would have hidden a real misfit.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 567 — Example 11.1(b)
Section
Part 5
Concept
In Example 11.4 you flip two coins 100 times and get 20 HH, 27 HT, 30 TH and 23 TT. Are the coins fair? Before computing, the book decides what the categories are, by naming a random variable.
\[ X = \text{number of heads in one flip of the two coins}, \qquad X \in \{0, 1, 2\} \]
Three values of X means three cells, not four. HT and TH both give one head, so they are poured into the same cell, and their counts add.
\[ O: \quad X = 2: 20, \qquad X = 1: 27 + 30 = 57, \qquad X = 0: 23 \]
Figure (svg): A probability tree for flipping two fair coins. The first flip branches to H and T with probability one half each; each branch splits again into H and T, giving the four outcomes HH, HT, TH and TT, each with probability one quarter. HH is labelled X equals 2, HT and TH are labelled X equals 1, TT is labelled X equals 0. On the right, three boxes: X equals 2 with probability one quarter and expected count 25; X equals 1 with probability one half and expected count 50; X equals 0 with probability one quarter and expected count 25.
The expected counts come from the tree: with fair coins each of the four outcomes has probability one quarter, so two heads and zero heads each expect a quarter of the 100 flips, and one head expects a half.
\[ E: \quad 25, \quad 50, \quad 25, \qquad df = 3 - 1 = 2 \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 573 — Example 11.4: X takes the values 0, 1, 2
Worked example
Test at the 5 percent level whether the two coins are fair, using the three cells for the number of heads.
The cells, the observed counts 20, 57 and 23, and the expected counts 25, 50 and 25 all come from the previous slide. Every expected count is at least five, so the test is allowed as it stands.
Write the hypotheses
Why: fair coins give the 1 to 2 to 1 distribution.
\[ H_0: \text{ the coins are fair}, \quad H_a: \text{ the coins are not fair} \]
Find the gaps
Why: two heads, one head, no heads.
\[ O - E: \quad 20 - 25 = -5, \quad 57 - 50 = 7, \quad 23 - 25 = -2 \]
The one-head cell has the largest gap, seven, but it also expects twice as much as the other cells, so its term ends up slightly smaller than the two-heads cell's. Gaps are always judged against their own expected counts.
Square and divide by the expected counts
Why: 25, 50 and 25.
\[ \frac{25}{25} = 1, \quad \frac{49}{50} = 0.98, \quad \frac{4}{25} = 0.16 \]
Add
Why: the statistic.
\[ \chi^2 = 1 + 0.98 + 0.16 = 2.14 \]
Find the p-value on two degrees of freedom
Why: with two df the right tail is a plain exponential.
\[ P(\chi^2_2 > x) = e^{-x/2} \Rightarrow p = e^{-1.07} \approx 0.3430 \]
Figure (svg): A chi-square curve with 2 degrees of freedom from 0 to 10, starting at its highest point at zero and falling steadily. A yellow line marks the statistic 2.14, with the area to its right shaded blue and labelled p-value 0.3430. A dashed red line at 5.991 marks the 5 percent cutoff.
Decide
Why: the p-value is above alpha.
\[ 0.3430 > 0.05 \Rightarrow \text{do not reject } H_0 \]
Conclusion, as the book writes it: there is insufficient evidence to conclude that the coins are not fair. That double negative is deliberate. The data are consistent with fair coins; they do not prove fairness.
Read the counts once more in context. Two heads came up a little less often than expected and one head a little more, gaps of five and seven in a hundred flips. Fair coins produce gaps that size about a third of the time.
Check the totals and the cutoff
Why: both columns total 100 flips, and 2.14 is well short of the 5 percent cutoff of 5.991 on two degrees of freedom.
\[ 20 + 57 + 23 = 100 = 25 + 50 + 25, \quad 2.14 < 5.991 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 573 — Example 11.4 and Figure 11.6
Worked example
Nothing forbids testing the four raw outcomes instead, each expecting 25. It is a different test of a slightly different claim, and comparing the two shows why the choice of cells must be made before looking at the data.
The four-cell null hypothesis says each ordered outcome has probability one quarter. That is true for two fair coins tossed independently, so it is a legitimate claim to test.
Write the gaps for HH, HT, TH, TT
Why: each expects a quarter of 100.
\[ O - E: \quad -5, \; 2, \; 5, \; -2 \]
Square and divide by 25
Why: every cell expects 25, so add first.
\[ \chi^2 = \frac{25 + 4 + 25 + 4}{25} = \frac{58}{25} = 2.32 \]
Count the degrees of freedom
Why: four cells now.
\[ df = 4 - 1 = 3 \]
Find the p-value
Why: right tail on three degrees of freedom.
\[ p = P(\chi^2_3 > 2.32) \approx 0.5087 \]
The four-cell test also asks whether HT and TH are equally likely, which the three-cell test cannot see, because it pools them. It is a stricter claim, and costs one more degree of freedom. Both tests agree here: nothing suggests unfair coins.
What you must not do is run both and report whichever looks better. Decide the cells from the question being asked, here the book's question about the number of heads, before computing anything.
The same rule applies to merging cells: merge because an expected count is below five, never because a different merge gives a smaller p-value. Choices made after seeing the data turn a five percent test into something much less trustworthy.
Check the totals and the gaps
Why: the four observed counts total 100 and the gaps total zero.
\[ 20 + 27 + 30 + 23 = 100, \quad -5 + 2 + 5 - 2 = 0 \quad \checkmark \]
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 573 — Example 11.4, the sample space HH, HT, TH, TT
Trap
After Example 11.4 a first attempt concludes:
\[ p = 0.3430 > 0.05 \]
so the test proves the coins are fair.
Wrong. Failing to reject is not evidence that the null is true.
The test only says that 100 flips cannot distinguish these coins from fair ones. A coin landing heads 55 percent of the time would often pass too.
\[ p = 0.343 \Rightarrow \text{ do not reject} \]
A goodness-of-fit test can reject a claimed distribution; it can never confirm one. Small samples make failure to reject cheap.
So the right report is about the evidence, and it says what the data could have seen.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 573 — Example 11.4's conclusion
Concept
Every test in this section ends with a sentence, and the sentence is where most marks are won or lost. The book's frame has four parts: the significance level, the source of the evidence, the strength of the evidence, and the claim, stated about the population in the words of the problem.
\[ \text{At the } \alpha \text{ level, from the sample data,} \]
\[ \text{there is (not) sufficient evidence} \]
\[ \text{to conclude that } H_a \]
When the test rejects, add what the table shows. Example 11.3's conclusion becomes far more useful once it says that far-western families are much less likely than the nation to have four or more services, the cell that supplied three quarters of the statistic.
When the test does not reject, keep the double negative. Example 11.2's sentence is that there is not sufficient evidence to conclude that the absent days do not occur with equal frequencies. It sounds clumsy, but every simpler version, such as absences are equal on all days, claims something the test cannot show.
Finally, name the population. The sixty managers or the hundred coin flips are the sample; the conclusion is about all employees, all far-western families, or these two coins in the long run. A conclusion about the sample alone is not a conclusion at all, because you already knew the sample's counts.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 569-573 — the conclusions of Examples 11.2, 11.3 and 11.4
Real world
Students hypothesise that every world region has an adult literacy rate of 82 percent, and the book asks for the test statistic and degrees of freedom from a table of ten regional rates. The arithmetic is easy. Whether it means anything is the real question.
| region | rate % | region | rate % |
|---|---|---|---|
| Developed Regions | 99.0 | Eastern Asia | 93.8 |
| Commonwealth of Ind. States | 99.5 | Southern Asia | 61.9 |
| Northern Africa | 67.3 | South-Eastern Asia | 91.9 |
| Sub-Saharan Africa | 62.5 | Western Asia | 84.5 |
| Latin America and Caribbean | 91.0 | Oceania | 66.4 |
\[ \chi^2 = \frac{(99.0 - 82)^2}{82} + \cdots + \frac{(66.4 - 82)^2}{82} = 26.38, \qquad df = 10 - 1 = 9 \]
Discussion prompt
The recipe gives 26.38 on nine degrees of freedom, a p-value of about 0.002. Name two reasons that this goodness-of-fit test is not valid, even though the arithmetic is right.
This is the most useful lesson the exercise offers. Before running any goodness-of-fit test, ask whether every cell holds a count of observations from one sample, and whether the counts add to the sample size. If not, the formula still produces a number, but that number has no chi-square distribution to be compared with.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 574 — Try It 11.4, Table 11.14
Concept
The statistic adds up gaps between counts, and counts grow with the sample size. Suppose the far-western percentages were each off from the national ones by only one percentage point: 11, 15, 54, 12 and 8 percent. With 600 families that is a trivial difference.
\[ n = 600: \quad \chi^2 = 1.63, \quad p = 0.80 \]
Keep exactly the same percentages and survey 8,000 families instead. Every gap in counts is now more than thirteen times larger, and its square is about a hundred and eighty times larger, while each expected count grows only thirteen-fold.
\[ n = 8000: \quad \chi^2 = 21.73, \quad p = 0.0002 \]
Figure (svg): A straight line rising from the origin showing the goodness-of-fit statistic against sample size, from 0 to 10,000 families, when every observed percentage is off by one point from the streaming-service claim. A dashed red horizontal line at 9.488 marks the 5 percent cutoff on 4 degrees of freedom; the line crosses it at about 3,500 families. Dots mark 600 families at 1.63 and 8,000 families at 21.73.
The statistic is proportional to the sample size whenever the percentages stay put, so the same one-point misfit crosses the 5 percent cutoff at about 3,500 families. With a large enough sample, every claimed distribution is rejected, because no real population matches a claim exactly.
So report the size of the misfit alongside the p-value: show the observed and expected percentages side by side, and name the cells that drive the statistic. A reader can then judge whether a significant difference matters.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 569-571 — Example 11.3's distribution, with hypothetical percentages
Real world
Goodness of fit is the standard check on anything that claims to be random: dice, lottery machines, a random-number generator, the order of songs on shuffle. Plan one such check yourself.
Discussion prompt
You plan to roll a die and test it for fairness at the 5 percent level. What is the smallest number of rolls that satisfies the condition on expected counts? How many degrees of freedom will the test have, and what statistic would you need to see before rejecting fairness?
This is the planning side of the condition. Because the expected counts depend only on the claim and the sample size, you can check them before rolling once, and choose a sample big enough both to satisfy the condition and to detect a bias you would care about.
Notice the degrees of freedom never depend on the number of rolls. Thirty rolls or three thousand, six faces give five degrees of freedom; only the statistic changes with the sample size.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, p. 565 — the condition on expected values
Picture it
Every test in this deck followed the same route. Here it is as a diagram, with the one loop that can send you back.
Figure (svg): A flow diagram. A box for the claimed distribution leads to a box for expected counts, n times each claimed proportion, which leads to a check box asking whether every expected count is at least 5. A red arrow labelled no runs down to a box saying combine neighbouring cells, and an arrow labelled recheck runs back up. A green arrow labelled yes leads right to the statistic, then down to degrees of freedom equal to cells minus one, then left to the right-tail p-value, and finally to a conclusion in context.
The loop is the condition on expected counts. If any expected count is below five, combine that cell with a sensible neighbour, recount the cells, and check again. Only when every expected count passes do you compute the statistic.
After the loop there is no choice of tail to make and no choice of curve beyond counting cells. The decisions that need judgement all come first: what the cells are, what the claim says about each, and whether the expected counts are big enough. That is where to spend your care.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565-573 — the steps of every example
Section
Part 6
Pattern
Every example in the section ran through the same steps. The arithmetic is mechanical; the decisions around it are what this pattern is for.
\[ \chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}, \qquad E_i = n p_i, \qquad df = k - 1 \]
Most wrong answers in this section are right arithmetic in the wrong place: percentages used as counts, degrees of freedom taken from the sample size or from a table that has since been merged, and a large p-value reported as proof. Each step above has a check aimed at one of them.
Read the pattern as a checklist when you check your own work. If the expected column does not add to n, or the gaps do not add to zero, or the statistic is wildly out of line with its degrees of freedom, stop and find the slip before writing any conclusion.
Check
Count what is free to vary in the table you actually test.
Check your understanding
A survey of 400 shoppers records their favourite of six store brands. Under the claimed distribution, one brand's expected count is 3, so it is combined with a neighbouring brand before the test. How many degrees of freedom does the test have?
Answer: A
Why: After merging, five cells remain. The five counts are tied to the total of 400, so four of them are free, and the degrees of freedom are five minus one, which is four.
Two separate corrections are needed, and each wrong option misses at least one. Subtract one for the fixed total, and recount after the merge.
Notice that the merge was decided by expected counts alone, before any shopper was asked. That is the right order: the condition, the cells and the degrees of freedom are all fixed by the claim and the sample size, and the data only supply the statistic.
In context: four free counts means the statistic is read from the chi-square curve with mean 4, so a statistic around 4 would be entirely ordinary for shoppers who matched the claimed preferences.
If you chose the sample-size option, revisit the trap slide on degrees of freedom; if you chose the option that ignores the merge, revisit the error-analysis slide in Part 4.
Check
Turn the claim into counts for this sample before anything else.
Check your understanding
A seed company claims its mix is 50 percent red, 30 percent yellow and 20 percent white. A packet of 240 seeds grows 132 red, 60 yellow and 48 white plants. What are the expected counts?
Answer: A
Why: Multiply each claimed proportion by the 240 seeds in this sample: 0.5 times 240 is 120, 0.3 times 240 is 72, and 0.2 times 240 is 48. They add to 240, matching the observed total.
Finishing the test: the gaps are 12, minus 12 and 0, so the statistic is 144 over 120 plus 144 over 72 plus 0, which is 1.2 plus 2, or 3.2, on two degrees of freedom.
If you picked the observed counts, you compared the data with themselves, which always gives a statistic of zero. If you picked the percentages, the expected column adds to 100, not 240, the alarm from the trap slide.
\[ \chi^2 = \frac{144}{120} + \frac{144}{72} + 0 = 3.2, \qquad p = e^{-1.6} \approx 0.20 \]
So at the 5 percent level there is not sufficient evidence that the packet departs from the company's claimed mix; a packet of 240 seeds can easily wobble this much.
Check
Choose the sentence a careful statistician would write.
Check your understanding
A goodness-of-fit test of whether customer arrivals are spread equally over four time slots gives a statistic of 1.9 on three degrees of freedom, with p-value 0.59. Which conclusion is correct at the 5 percent level?
Answer: A
Why: A p-value above alpha means the counts are consistent with equal slots, so the claim is not rejected. That is not a proof of equality, and the p-value is not the probability that the claim is true.
The quick check confirms the decision without a table: 1.9 is below 3, the mean of the chi-square curve with three degrees of freedom, so the p-value had to be above one half.
Each wrong option is a habit worth naming: proof of the null, the left tail read as evidence, and the p-value read as the probability of the claim.
The correct sentence would be stronger still with a word about power: with the sample at hand, only a fairly large imbalance between slots would have been detected.
Explain it to yourself
This is the one idea in the section that is not arithmetic. Put it in your own words before reading the model answer.
Discussion prompt
In two or three sentences, explain why a goodness-of-fit test uses only the right tail of the chi-square curve, even though the alternative hypothesis, the data do not fit, has no direction.
A strong answer names the squaring as the reason both directions of misfit land on the same side. A very strong one adds the caveat behind almost always: a statistic suspiciously close to zero can itself be a warning that data fit too well to be honest.
If your answer said the test is one-sided because the alternative says greater than, look again: the alternative here says nothing about direction. The tail is fixed by the statistic, not by the wording.
Exit ticket
A spinner is claimed to land on red, blue, green and yellow in the proportions 0.4, 0.3, 0.2 and 0.1. In 150 spins it lands 72 red, 39 blue, 27 green and 12 yellow. Test the claim at the 5 percent level.
Discussion prompt
Build the expected counts, check the condition, compute the statistic, the degrees of freedom and the p-value, and state the conclusion in context.
The checks to run on your own answer: the expected counts add to 150, the gaps add to zero, and a statistic of 4.1 is only a little above 3, the mean on three degrees of freedom, so a p-value of a quarter is about right.
If your degrees of freedom came out as 149, you counted spins instead of colours; if your statistic was huge, check that you multiplied the proportions by 150.
Recap
A goodness-of-fit test asks whether a whole set of observed counts is consistent with a claimed distribution. Expected counts come from the claim and the sample size; the statistic adds each cell's squared gap over its expected count; the degrees of freedom are the cells minus one; and the p-value is always the right tail.
| idea | formula or rule | read it as |
|---|---|---|
| hypotheses | H₀: data fit the claim; Hₐ: they do not | written in sentences |
| expected counts | E = n × p | they must add to n, like the observed |
| condition | every E ≥ 5 | otherwise combine a cell with a neighbour |
| statistic | χ² = Σ (O − E)²/E | one term per cell; never negative |
| degrees of freedom | df = cells − 1 | after any merge; never n − 1 |
| p-value | P(χ² > observed) | right tail; compare the statistic with df |
| Example 11.2 | χ² = 3, df 4, p = 0.5578 | no evidence absences are unequal |
| Example 11.3 | χ² = 29.65, df 4, p = 0.000006 | far West differs; the 4+ cell drives it |
| Example 11.4 | χ² = 2.14, df 2, p = 0.3430 | no evidence the coins are unfair |
The habits that matter are building expected counts as counts, checking them before computing, recounting the cells after every merge, naming the cell that drives a significant result, and never reporting a large p-value as proof that the data fit.
The Introductory Business Statistics text treats the same test in its own goodness-of-fit section, with business settings, if you want more practice. Section 11.3 turns to the test of independence, which uses the same statistic on a two-way table.
OpenStax Introductory Statistics 2e, §11.2 Goodness-of-Fit Test §11.2, pp. 565-574 — the whole section
OpenStax Introductory Business Statistics 2e, §11.3 Goodness-of-Fit Test §11.3 Goodness-of-Fit Test — the same test in business contexts
Want this taught 1-on-1? Alexander tutors Statistics — $55/session, free consultation.