StatisticsChi-Square Tests for Categorical Data1 of 3
Chi-Square Tests for Categorical Data · 1

Chi-Square Test for Goodness of Fit

We know how to test a claim about a single proportion, and now we need a way to test whether the observed counts across all categories of one categorical variable fit a claimed model at once.

1

Measuring Mismatch with the Chi-Square Statistic

The Chi-Square statistic (χ2\observed{\chi^2}) is a single number that measures the total mismatch between the counts we observe in a sample and the counts we expect from a claimed model.

Suppose a video game claims its mystery loot boxes drop items across four rarity tiers according to this model: 50%\model{50\%} Common, 30%\model{30\%} Uncommon, 15%\model{15\%} Rare, and 5%\model{5\%} Legendary. To test that claim, you open 100100 boxes and observe 58\observed{58} Common, 24\observed{24} Uncommon, 15\observed{15} Rare, and 3\observed{3} Legendary.

Measuring Mismatch with the Chi-Square Statistic
Claim\htmlClass{lc-violet}{\text{Claim}}
CommonUncommonRareLegendary\htmlClass{lc-ink}{\def\arraystretch{1.3493}\begin{array}{l}\text{Common} \\ \text{Uncommon} \\ \text{Rare} \\ \text{Legendary}\end{array}}
50%30%15%5%\htmlClass{lc-violet}{\def\arraystretch{1.3493}\begin{array}{c}50\% \\ 30\% \\ 15\% \\ 5\%\end{array}}
100 boxes\htmlClass{lc-ink}{100 \text{ boxes}}

To combine all the category misses into one mismatch score without positive and negative gaps canceling out, and while keeping small and large categories in fair proportion, we compute the Chi-Square statistic:

χ2\displaystyle \observed{\chi^2} =∑(O⏟observed count−E⏟expected count)2E\displaystyle = \sum \frac{\gap{(\observed{\underbrace{O}_{\text{observed count}}} - \model{\underbrace{E}_{\text{expected count}}})^2}}{\model{E}}

The 22 in χ2\observed{\chi^2} is part of the statistic's name (because each gap is squared), so you never take a square root at the end.

Text solution
Subtract E\model{E} from O\observed{O} and square each category's gap Squaring each gap gets rid of the negative signs, so extra items in one category cannot cancel out shortages in another.
Common: (58−50)2=82=64Uncommon: (24−30)2=(−6)2=36Rare: (15−15)2=02=0Legendary: (3−5)2=(−2)2=4\displaystyle \begin{aligned} {\scriptstyle\text{Common: }} \gap{(\observed{58} - \model{50})^2} &= \gap{8^2} = \gap{64} \\ {\scriptstyle\text{Uncommon: }} \gap{(\observed{24} - \model{30})^2} &= \gap{(-6)^2} = \gap{36} \\ {\scriptstyle\text{Rare: }} \gap{(\observed{15} - \model{15})^2} &= \gap{0^2} = \gap{0} \\ {\scriptstyle\text{Legendary: }} \gap{(\observed{3} - \model{5})^2} &= \gap{(-2)^2} = \gap{4} \end{aligned}
Divide each squared gap by the expected count E\model{E} Dividing by E\model{E} compares each squared miss to the size of its category, so missing 2\gap{2} out of 5\model{5} expected Legendaries counts nearly as much as missing 8\gap{8} out of 50\model{50} expected Commons.
Common:6450=1.28Uncommon:3630=1.20Rare:015=0Legendary:45=0.80\displaystyle \begin{aligned} \text{Common:} \quad \frac{\gap{64}}{\model{50}} &= \gap{1.28} \\ \text{Uncommon:} \quad \frac{\gap{36}}{\model{30}} &= \gap{1.20} \\ \text{Rare:} \quad \frac{\gap{0}}{\model{15}} &= \gap{0} \\ \text{Legendary:} \quad \frac{\gap{4}}{\model{5}} &= \gap{0.80} \end{aligned}
Add the category contributions to get χ2\observed{\chi^2} Adding the pieces across all four tiers gives the overall mismatch score for the sample.
χ2\displaystyle \observed{\chi^2} =1.28+1.20+0+0.80\displaystyle = \gap{1.28} + \gap{1.20} + \gap{0} + \gap{0.80} =3.28\displaystyle = \observed{3.28}

Because the total is fixed at 100100 boxes, extra boxes in one rarity tier always come out of the other tiers so the signed gaps O−E\gap{\observed{O} - \model{E}} add up to zero. Shifting just a few boxes in a small category like Legendary (E=5\model{E} = \model{5}) makes χ2\observed{\chi^2} jump much more than shifting the same number of boxes in Common (E=50\model{E} = \model{50}).

With 100 loot boxes total, adding boxes to one category takes them from another so the raw gaps always cancel out, while moving the same number of boxes jumps chi-squared much more in a small expected category than in a big one.
2

Degrees of Freedom and Finding the P-Value

Now that we have a mismatch score of χ2=3.28\observed{\chi^2} = \observed{3.28}, we need to know whether 3.28\observed{3.28} is just ordinary random luck or strong evidence against the developer's model. To judge the score, we use the degrees of freedom (df\text{df}), which equals the average χ2\observed{\chi^2} score we expect from random chance when the model is true, and the p-value, which is the chance of getting a χ2\observed{\chi^2} score at least as large as ours by random luck alone.

Degrees of Freedom and Finding the P-Value
E\model{E}
O\observed{O}
(O−E)2E\dfrac{\gap{(}\observed{O}\gap{-}\model{E}\gap{)^2}}{\model{E}}
CommonUncommonRareLegendary\htmlClass{lc-ink}{\def\arraystretch{1.2931}\begin{array}{l}\text{Common} \\ \text{Uncommon} \\ \text{Rare} \\ \text{Legendary}\end{array}}
5030155\htmlClass{lc-violet}{\def\arraystretch{1.2931}\begin{array}{c}50 \\ 30 \\ 15 \\ 5\end{array}}
5824153\htmlClass{lc-blue}{\def\arraystretch{1.2931}\begin{array}{c}58 \\ 24 \\ 15 \\ 3\end{array}}
1.281.2000.80\htmlClass{lc-orange}{\def\arraystretch{1.2931}\begin{array}{c}1.28 \\ 1.20 \\ 0 \\ 0.80\end{array}}
χ2=3.28\htmlClass{lc-blue}{\chi^2 = 3.28}
0\htmlClass{lc-mute}{0}
5\htmlClass{lc-mute}{5}
10\htmlClass{lc-mute}{10}
15\htmlClass{lc-mute}{15}
χ2\htmlClass{lc-ink}{\chi^2}
3.28\htmlClass{lc-blue}{3.28}
p-value=?\htmlClass{lc-green}{\text{p-value} = {?}}

Once the sample total is fixed, knowing the counts in all but one category fixes the final category's count:

df\displaystyle \text{df} =Categories−1⏟average χ2 when H0 is true\displaystyle = \underbrace{\text{Categories} - 1}_{\text{average } \observed{\chi^2} \text{ when } H_0 \text{ is true}}

Because squared gaps can never be negative, the χ2\observed{\chi^2} distribution starts at 00 and is skewed to the right. Both higher-than-expected and lower-than-expected counts make (O−E)2\gap{(\observed{O} - \model{E})^2} larger, so any mismatch with the model pushes χ2\observed{\chi^2} to the right and the p-value is always the area in the right tail.

0\htmlClass{lc-mute}{0}
1\htmlClass{lc-mute}{1}
3\htmlClass{lc-violet}{3}
6\htmlClass{lc-mute}{6}
9\htmlClass{lc-mute}{9}
χ2\htmlClass{lc-ink}{\chi^2}
df=3\htmlClass{lc-ink}{\text{df} = 3}
χ2=3.28\htmlClass{lc-blue}{\chi^2 = 3.28}
p-value=0.35\htmlClass{lc-green}{\text{p-value} = 0.35}
Text solution
State the null and alternative hypotheses We test the claim that every category's true proportion matches the model against the alternative that the model is off in at least one category.
H0:The claimed rarity modelis correct (pCommon=0.50, pUncommon=0.30, pRare=0.15, pLegendary=0.05).Ha:The claimed model is notcorrect (at least onecategory’s true proportiondiffers from the claim).\displaystyle \begin{aligned} H_0&: \text{The claimed rarity model} \\ &\quad \text{is correct } (\model{p_{\text{Common}}} = \model{0.50},\ \\ &\quad \model{p_{\text{Uncommon}}} = \model{0.30},\ \\ &\quad \model{p_{\text{Rare}}} = \model{0.15},\ \\ &\quad \model{p_{\text{Legendary}}} = \model{0.05}). \\ H_a&: \text{The claimed model is not} \\ &\quad \text{correct (at least one} \\ &\quad \text{category's true proportion} \\ &\quad \text{differs from the claim).} \end{aligned}
Subtract 11 from the number of categories to find df\text{df} With 44 rarity categories and a fixed total of 100100 boxes, 33 categories are free to vary.
df\displaystyle \text{df} =4−1\displaystyle = 4 - 1 =3\displaystyle = 3
Find the right-tail p-value from the χ2\chi^2 table or calculator On the df=3\text{df} = 3 row of the χ2\chi^2 table, 3.28\observed{3.28} is smaller than the first cutoff on the left (4.114.11 for tail probability 0.25\share{0.25}), and χ2cdf\chi^2\text{cdf} gives the exact right-tail area.
Table: p-value>0.25Calculator: χ2cdf(lower=3.28, upper=1000, df=3)≈0.35\displaystyle \begin{aligned} &\text{Table: } \share{\text{p-value}} > \share{0.25} \\ &\text{Calculator: } \\ &\quad \chi^2\text{cdf}(\text{lower} = \observed{3.28},\ \\ &\qquad \text{upper} = 1000,\ \text{df} = 3) \\ &\quad \approx \share{0.35} \end{aligned}
Compare the p-value to α=0.05\alphalevel{\alpha} = \alphalevel{0.05} to conclude in context Because a mismatch score of 3.28\observed{3.28} or higher happens about 35%\share{35\%} of the time by random chance when the model is true, we fail to reject H0H_0 and do not have convincing evidence against the developer's claimed drop rates.
p-value\displaystyle \share{\text{p-value}} =0.35>0.05  ⟹  Fail to reject H0\displaystyle = \share{0.35} > \alphalevel{0.05} \implies \text{Fail to reject } H_0

As a larger mismatch pushes χ2\observed{\chi^2} further to the right along the df=3\text{df} = 3 curve, the shaded right-tail p-value shrinks past the cutoffs on the df=3\text{df} = 3 row of the χ2\chi^2 table (4.114.11 for 0.25\share{0.25}, 6.256.25 for 0.10\share{0.10}, 7.817.81 for 0.05\share{0.05}, and 11.3411.34 for 0.01\share{0.01}).

A bigger chi-square value moves you further right on the curve, leaving a smaller tail area and passing fixed cutoffs in the table.
3

Running a Goodness of Fit Test When nn Isn't 100100

In a sample of 100100 boxes, the expected counts matched the claimed percentages directly. For any other sample size nn, we find each category's expected count by multiplying nn by that category's claimed proportion pi\model{p_i}.

After a game update, players open n=150n = 150 loot boxes to test the same claimed model (50%\model{50\%} Common, 30%\model{30\%} Uncommon, 15%\model{15\%} Rare, 5%\model{5\%} Legendary) and observe 90\observed{90} Common, 45\observed{45} Uncommon, 12\observed{12} Rare, and 3\observed{3} Legendary.

Running a Goodness of Fit Test When n Isn't 100
Claim\htmlClass{lc-violet}{\text{Claim}}
E\model{E}
O\observed{O}
CommonUncommonRareLegendary\htmlClass{lc-ink}{\def\arraystretch{1.2369}\begin{array}{l}\text{Common} \\ \text{Uncommon} \\ \text{Rare} \\ \text{Legendary}\end{array}}
50%30%15%5%\htmlClass{lc-violet}{\def\arraystretch{1.2369}\begin{array}{c}50\% \\ 30\% \\ 15\% \\ 5\%\end{array}}
????\htmlClass{lc-violet}{\def\arraystretch{1.2369}\begin{array}{c}? \\ ? \\ ? \\ ?\end{array}}
9045123\htmlClass{lc-blue}{\def\arraystretch{1.2369}\begin{array}{c}90 \\ 45 \\ 12 \\ 3\end{array}}
n=150\htmlClass{lc-ink}{n = 150}

For each category, the expected count is the average count we would get in the long run across many samples of size nn:

E\displaystyle \model{E} =n⏟sample size⋅pi⏟claimed proportion\displaystyle = \underbrace{n}_{\text{sample size}} \cdot \model{\underbrace{p_i}_{\text{claimed proportion}}}
Text solution
Multiply n=150n = 150 by each claimed proportion pi\model{p_i} without rounding Keeping the decimals gives the exact expected counts so all four still add up to 150150.
Common: E=150×0.50=75Uncommon: E=150×0.30=45Rare: E=150×0.15=22.5Legendary: E=150×0.05=7.5\displaystyle \begin{aligned} {\scriptstyle\text{Common: }} \model{E} &= 150 \times \model{0.50} = \model{75} \\ {\scriptstyle\text{Uncommon: }} \model{E} &= 150 \times \model{0.30} = \model{45} \\ {\scriptstyle\text{Rare: }} \model{E} &= 150 \times \model{0.15} = \model{22.5} \\ {\scriptstyle\text{Legendary: }} \model{E} &= 150 \times \model{0.05} = \model{7.5} \end{aligned}
Compute each category's contribution (O−E)2E\frac{\gap{(\observed{O} - \model{E})^2}}{\model{E}} and add them to find χ2\observed{\chi^2} Writing out each category's piece shows that the shortage of Rare items (12\observed{12} observed vs. 22.5\model{22.5} expected) makes up 4.9\gap{4.9} of the 10.6\observed{10.6} total mismatch.
χ2=(90−75)275+(45−45)245+(12−22.5)222.5+(3−7.5)27.5=15275+0245+(−10.5)222.5+(−4.5)27.5=22575+0+110.2522.5+20.257.5=3.0+0+4.9+2.7=10.6\displaystyle \begin{aligned} \observed{\chi^2} &= \frac{\gap{(\observed{90} - \model{75})^2}}{\model{75}} + \frac{\gap{(\observed{45} - \model{45})^2}}{\model{45}} \\ &\quad + \frac{\gap{(\observed{12} - \model{22.5})^2}}{\model{22.5}} + \frac{\gap{(\observed{3} - \model{7.5})^2}}{\model{7.5}} \\ &= \frac{\gap{15^2}}{\model{75}} + \frac{\gap{0^2}}{\model{45}} \\ &\quad + \frac{\gap{(-10.5)^2}}{\model{22.5}} + \frac{\gap{(-4.5)^2}}{\model{7.5}} \\ &= \frac{\gap{225}}{\model{75}} + \gap{0} + \frac{\gap{110.25}}{\model{22.5}} + \frac{\gap{20.25}}{\model{7.5}} \\ &= \gap{3.0} + \gap{0} + \gap{4.9} + \gap{2.7} = \observed{10.6} \end{aligned}
Find the right-tail p-value for df=4−1=3\text{df} = 4 - 1 = 3 and compare to α=0.05\alphalevel{\alpha} = \alphalevel{0.05} On the df=3\text{df} = 3 row of the table, 10.6\observed{10.6} lands between 9.849.84 (p=0.02\share{p} = \share{0.02}, or 9.359.35 for p=0.025\share{p} = \share{0.025} if the table leaves out 0.02\share{0.02}) and 11.3411.34 (p=0.01\share{p} = \share{0.01}), giving convincing evidence that the drop rates after the update do not fit the developer's model.
Table: 0.01<p-value<0.02(or 0.01<p-value<0.025)Calculator: χ2cdf(lower=10.6, upper=1000, df=3)≈0.014<0.05  ⟹  Reject H0\displaystyle \begin{aligned} &\text{Table: } \share{0.01} < \share{\text{p-value}} < \share{0.02} \\ &\quad (\text{or } \share{0.01} < \share{\text{p-value}} < \share{0.025}) \\ &\text{Calculator: } \\ &\quad \chi^2\text{cdf}(\text{lower} = \observed{10.6},\ \\ &\qquad \text{upper} = 1000,\ \text{df} = 3) \\ &\quad \approx \share{0.014} < \alphalevel{0.05} \\ &\quad \implies \text{Reject } H_0 \end{aligned}

On a test, either the table interval or the calculator p-value gets full credit as long as you write down df=3\text{df} = 3 with your work.

4

Conditions for a Chi-Square Goodness of Fit Test

Before we can trust the smooth χ2\observed{\chi^2} curve to give an accurate p-value, we need to check that the data are raw counts from a random, independent sample and that every category's expected count is large enough for the curve to work well.

Conditions for a Chi-Square Goodness of Fit Test
χ2=∑(O−E)2E\observed{\chi^2} = \displaystyle\sum \dfrac{\gap{(}\observed{O}\gap{-}\model{E}\gap{)^2}}{\model{E}}
df=3\htmlClass{lc-ink}{\text{df} = 3}
1.\htmlClass{lc-ink}{1.}
2.\htmlClass{lc-ink}{2.}
3.\htmlClass{lc-ink}{3.}

Key concepts

Use a Chi-Square Goodness of Fit test when you have one categorical variable from a single sample and want to test whether the observed counts across all categories fit a claimed model of proportions (such as testing all 44 loot box rarity tiers at once). If a question only asks about a single category's proportion (such as testing only whether Legendary items drop 5%\model{5\%} of the time), use a one-sample zz-test for a proportion instead.

Before computing the statistic, check that the data are raw counts from a random, independent sample (n≤10%n \le 10\% of the population if sampled without replacement) and that every category's expected count is at least 55:

E=n⋅pi≥5(for n=150 and pLegendary=0.05, E=7.5≥5 passes even when O=3)\displaystyle \begin{gathered} \model{E} = n \cdot \model{p_i} \ge 5 \\ (\text{for } n = 150 \text{ and } \model{p_{\text{Legendary}}} = \model{0.05},\ \\ \model{E} = \model{7.5} \ge 5 \text{ passes even when } \observed{O} = \observed{3}) \end{gathered}

Keep expected counts unrounded, divide each category's squared gap by E\model{E}, and add the pieces across all categories:

χ2\displaystyle \observed{\chi^2} =∑(O−E)2E,df\displaystyle = \sum \frac{\gap{(\observed{O} - \model{E})^2}}{\model{E}}, \qquad \text{df} =Categories−1\displaystyle = \text{Categories} - 1

When H0H_0 is true, random variation produces an average score of χ2≈df\observed{\chi^2} \approx \text{df} (like χ2=3.28\observed{\chi^2} = \observed{3.28} with df=3\text{df} = 3, which gives p-value≈0.35>0.05\share{\text{p-value}} \approx \share{0.35} > \alphalevel{0.05} and fails to reject H0H_0). Only mismatches that push χ2\observed{\chi^2} far above df\text{df} into the right tail (like χ2=10.6\observed{\chi^2} = \observed{10.6} with df=3\text{df} = 3, where χ2cdf(10.6,1000,3)≈0.014<0.05\chi^2\text{cdf}(\observed{10.6}, 1000, 3) \approx \share{0.014} < \alphalevel{0.05}) give convincing evidence to reject H0H_0.

5

Practice

1

A candy company claims its bags contain 40%\model{40\%} red, 30%\model{30\%} blue, 20%\model{20\%} green, and 10%\model{10\%} yellow candies. From a random sample of n=85n = 85 candies, you observe 39\observed{39} red, 24\observed{24} blue, 17\observed{17} green, and 5\observed{5} yellow. Find the expected count for each color, then compare red and yellow: which color has the larger raw gap ∣O−E∣\gap{|\observed{O} - \model{E}|}, and which contributes more to the χ2\observed{\chi^2} statistic?

After finding E=85⋅pi\model{E} = 85 \cdot \model{p_i} for each color, compare what you divide each squared gap (O−E)2\gap{(\observed{O} - \model{E})^2} by.

Multiply n=85n = 85 by each claimed proportion to get the unrounded expected counts:
Red:E=85×0.40=34Blue:E=85×0.30=25.5Green:E=85×0.20=17Yellow:E=85×0.10=8.5\displaystyle \begin{aligned} \text{Red:} \quad \model{E} &= 85 \times \model{0.40} = \model{34} \\ \text{Blue:} \quad \model{E} &= 85 \times \model{0.30} = \model{25.5} \\ \text{Green:} \quad \model{E} &= 85 \times \model{0.20} = \model{17} \\ \text{Yellow:} \quad \model{E} &= 85 \times \model{0.10} = \model{8.5} \end{aligned}
(Watch out: rounding 25.5\model{25.5} to 2626 and 8.5\model{8.5} to 99 makes the expected counts add up to 8686 instead of 8585 and changes yellow's contribution to (−4)29≈1.78\tfrac{(-4)^2}{9} \approx 1.78.)
Compare the raw gaps and χ2\observed{\chi^2} contributions for red and yellow:
Red:O−E=39−34=+5  ⟹  5234=2534≈0.74Yellow:O−E=5−8.5=−3.5  ⟹  (−3.5)28.5=12.258.5≈1.44\displaystyle \begin{aligned} \text{Red:} \quad \gap{\observed{O} - \model{E}} &= \observed{39} - \model{34} = \gap{+5} \\ \implies \frac{\gap{5^2}}{\model{34}} &= \frac{\gap{25}}{\model{34}} \approx \gap{0.74} \\[4pt] \text{Yellow:} \quad \gap{\observed{O} - \model{E}} &= \observed{5} - \model{8.5} = \gap{-3.5} \\ \implies \frac{\gap{(-3.5)^2}}{\model{8.5}} &= \frac{\gap{12.25}}{\model{8.5}} \approx \gap{1.44} \end{aligned}
Red has the larger raw gap (5\gap{5} vs. 3.5\gap{3.5}), but yellow contributes nearly twice as much to χ2\observed{\chi^2} because its squared gap is divided by a much smaller expected count (8.5\model{8.5} vs. 34\model{34}): 0.74\gap{0.74} for red and 1.44\gap{1.44} for yellow.
2

A six-sided die is claimed to land on each face (11 through 66) with probability 16\model{\tfrac{1}{6}}. In 120120 rolls, the observed counts for faces 11 through 55 are 18\observed{18}, 23\observed{23}, 19\observed{19}, 21\observed{21}, and 16\observed{16}. Find the observed count for face 66, state the degrees of freedom, and explain how comparing the χ2\observed{\chi^2} statistic to the degrees of freedom tells you right away whether the die looks fair.

The 66 observed counts must add up to n=120n = 120. Once you compute χ2\observed{\chi^2}, what is the average χ2\observed{\chi^2} score for a fair die with df=6−1\text{df} = 6 - 1?

Subtract the first five faces from the total of 120120 rolls to find the remaining count for face 66:
Face 6 observed count\displaystyle \text{Face 6 observed count} =120−(18+23+19+21+16)\displaystyle = 120 - (\observed{18} + \observed{23} + \observed{19} + \observed{21} + \observed{16}) =120−97\displaystyle = 120 - \observed{97} =23\displaystyle = \observed{23}
Because only 55 of the 66 categories are free to vary once the total is fixed at 120120:
df\displaystyle \text{df} =6−1\displaystyle = 6 - 1 =5\displaystyle = 5
(Watch out: using the sample size to get df=120−1=119\text{df} = 120 - 1 = 119 confuses the Chi-Square test with a one-sample tt-test, and leaving Face 66 out of the sum gives χ2=3120=1.55\chi^2 = \tfrac{31}{20} = 1.55.)
Each face has expected count E=120×16=20\model{E} = 120 \times \model{\frac{1}{6}} = \model{20}:
χ2=(−2)220+3220+(−1)220+1220+(−4)220+3220=4+9+1+1+16+920=4020=2.00\displaystyle \begin{aligned} \observed{\chi^2} &= \frac{\gap{(-2)^2}}{\model{20}} + \frac{\gap{3^2}}{\model{20}} + \frac{\gap{(-1)^2}}{\model{20}} \\ &\quad + \frac{\gap{1^2}}{\model{20}} + \frac{\gap{(-4)^2}}{\model{20}} + \frac{\gap{3^2}}{\model{20}} \\ &= \frac{\gap{4} + \gap{9} + \gap{1} + \gap{1} + \gap{16} + \gap{9}}{\model{20}} \\ &= \frac{\gap{40}}{\model{20}} = \observed{2.00} \end{aligned}
When the fair-die model is true, random chance produces an average χ2\observed{\chi^2} equal to df=5\text{df} = 5, so a score of 2.00\observed{2.00} is completely ordinary and gives no evidence against the die being fair: χ2=2.00\observed{\chi^2} = \observed{2.00}.
3

A geneticist models pea plant offspring as 56.25%\model{56.25\%} purple-smooth, 18.75%\model{18.75\%} purple-wrinkled, 18.75%\model{18.75\%} white-smooth, and 6.25%\model{6.25\%} white-wrinkled. A random sample of 160160 plants gives 75\observed{75} purple-smooth, 39\observed{39} purple-wrinkled, 30\observed{30} white-smooth, and 16\observed{16} white-wrinkled. State the hypotheses, compute χ2\observed{\chi^2} and df\text{df}, find the p-value both as an interval from the df=3\text{df} = 3 row of the χ2\chi^2 table (cutoffs: 4.114.11 for 0.25\share{0.25}, 6.256.25 for 0.10\share{0.10}, 7.817.81 for 0.05\share{0.05}, 9.359.35 for 0.025\share{0.025}, 9.849.84 for 0.02\share{0.02}, 11.3411.34 for 0.01\share{0.01}) and using a calculator command, and state your conclusion at α=0.05\alphalevel{\alpha} = \alphalevel{0.05}.

Convert each percentage to a decimal before multiplying by n=160n = 160, then find where your χ2\observed{\chi^2} total sits along the df=3\text{df} = 3 cutoffs.

Hypotheses
H0:The offspring proportionsmatch the claimed model (56.25%, 18.75%, 18.75%, 6.25%).Ha:The claimed model is notcorrect (at least onecategory’s true proportiondiffers from the claim).\displaystyle \begin{aligned} H_0&: \text{The offspring proportions} \\ &\quad \text{match the claimed model } \\ &\quad (\model{56.25\%},\ \model{18.75\%},\ \\ &\quad \model{18.75\%},\ \model{6.25\%}). \\ H_a&: \text{The claimed model is not} \\ &\quad \text{correct (at least one} \\ &\quad \text{category's true proportion} \\ &\quad \text{differs from the claim).} \end{aligned}
Expected counts for n=160n = 160
EPS=160×0.5625=90,EPW=160×0.1875=30,EWS=160×0.1875=30,EWW=160×0.0625=10\displaystyle \begin{aligned} \model{E_{\text{PS}}} &= 160 \times \model{0.5625} = \model{90}, \\ \model{E_{\text{PW}}} &= 160 \times \model{0.1875} = \model{30}, \\ \model{E_{\text{WS}}} &= 160 \times \model{0.1875} = \model{30}, \\ \model{E_{\text{WW}}} &= 160 \times \model{0.0625} = \model{10} \end{aligned}
Test statistic χ2\observed{\chi^2} and degrees of freedom
χ2=(75−90)290+(39−30)230+(30−30)230+(16−10)210=2.50+2.70+0+3.60=8.80,df=4−1=3\displaystyle \begin{aligned} \observed{\chi^2} &= \frac{\gap{(\observed{75} - \model{90})^2}}{\model{90}} + \frac{\gap{(\observed{39} - \model{30})^2}}{\model{30}} \\ &\quad + \frac{\gap{(\observed{30} - \model{30})^2}}{\model{30}} + \frac{\gap{(\observed{16} - \model{10})^2}}{\model{10}} \\ &= \gap{2.50} + \gap{2.70} + \gap{0} + \gap{3.60} = \observed{8.80}, \\ \text{df} &= 4 - 1 = 3 \end{aligned}
(Watch out: dividing the squared gaps by the observed counts 75,39,30,16\observed{75, 39, 30, 16} instead of the expected counts 90,30,30,10\model{90, 30, 30, 10} gives χ2≈7.33\chi^2 \approx 7.33, which falls below the 7.817.81 cutoff and flips the conclusion.)
P-value and conclusion On the df=3\text{df} = 3 row, 8.80\observed{8.80} falls between 7.817.81 (p=0.05\share{p} = \share{0.05}) and 9.359.35 (p=0.025\share{p} = \share{0.025}):
Table: 0.025<p-value<0.05Calculator: χ2cdf(lower=8.80, upper=1000, df=3)≈0.032\displaystyle \begin{aligned} &\text{Table: } \share{0.025} < \share{\text{p-value}} < \share{0.05} \\ &\text{Calculator: } \\ &\quad \chi^2\text{cdf}(\text{lower} = \observed{8.80},\ \\ &\qquad \text{upper} = 1000,\ \text{df} = 3) \\ &\quad \approx \share{0.032} \end{aligned}
Because p-value≈0.032<0.05\share{\text{p-value}} \approx \share{0.032} < \alphalevel{0.05}, we reject H0H_0: there is convincing evidence that the pea plant offspring types do not fit the claimed model at p-value≈0.032\share{\text{p-value}} \approx \share{0.032}.
4

A transit agency claims that commuter arrivals across five station gates follow the model: Gate A 35%\model{35\%}, Gate B 25%\model{25\%}, Gate C 20%\model{20\%}, Gate D 12%\model{12\%}, and Gate E 8%\model{8\%}. An inspector takes a random sample of 5050 of the station's 12,00012{,}000 daily commuters and observes 19\observed{19} at Gate A, 14\observed{14} at Gate B, 11\observed{11} at Gate C, 4\observed{4} at Gate D, and 2\observed{2} at Gate E. The inspector says the Chi-Square Goodness of Fit test cannot be used because Gates D and E have observed counts under 55. Check all conditions for the test to see if the inspector is right.

Which column, Observed O\observed{O} or Expected E=50⋅pi\model{E} = 50 \cdot \model{p_i}, does the Large Counts condition actually check?

Random and Independent (10%10\% condition) The data are raw counts from a random sample of 5050 commuters, and 50≤10%50 \le 10\% of 12,00012{,}000 (1,2001{,}200), so both conditions pass.
Large Counts (E≥5\model{E} \ge 5) The inspector is checking the wrong column. Large Counts requires every Expected count, not every Observed count, to be at least 55. Multiplying n=50n = 50 by each claimed proportion gives:
EA=50×0.35=17.5,EB=50×0.25=12.5,EC=50×0.20=10,ED=50×0.12=6,EE=50×0.08=4\displaystyle \begin{aligned} \model{E_A} &= 50 \times \model{0.35} = \model{17.5}, \\ \model{E_B} &= 50 \times \model{0.25} = \model{12.5}, \\ \model{E_C} &= 50 \times \model{0.20} = \model{10}, \\ \model{E_D} &= 50 \times \model{0.12} = \model{6}, \\ \model{E_E} &= 50 \times \model{0.08} = \model{4} \end{aligned}
(Watch out: rejecting Gate D because OD=4<5\observed{O_D} = \observed{4} < 5 checks the wrong column, while stopping at ED=6≥5\model{E_D} = \model{6} \ge 5 misses that Gate E still fails.)
Gate D passes (ED=6≥5\model{E_D} = \model{6} \ge 5 even though OD=4\observed{O_D} = \observed{4}), but the test still cannot be run because Gate E has an expected count of EE=4<5\model{E_E} = \model{4} < 5.
5

A music app claims its shuffle plays 50%\model{50\%} songs from the 2010s, 30%\model{30\%} from the 2000s, and 20%\model{20\%} from the 1990s. A listener observes 55%\observed{55\%} from the 2010s, 27%\observed{27\%} from the 2000s, and 18%\observed{18\%} from the 1990s, and plugs those percentages directly into the formula: χ2=(55−50)250+(27−30)230+(18−20)220=1.00\chi^2 = \tfrac{(55 - 50)^2}{50} + \tfrac{(27 - 30)^2}{30} + \tfrac{(18 - 20)^2}{20} = 1.00. Explain what rule this breaks, compute the true χ2\observed{\chi^2} statistic if those percentages came from a random sample of n=200n = 200 songs versus n=1,000n = 1{,}000 songs, and explain why the conclusion changes.

Convert the percentages into actual counts of songs for n=200n = 200 and for n=1,000n = 1{,}000 before computing χ2\observed{\chi^2}.

Plugging percentages into the χ2\observed{\chi^2} formula breaks the raw counts condition by treating the sample as if n=100n = 100.
For n=200n = 200 songs (df=3−1=2\text{df} = 3 - 1 = 2) Observed counts are 110,54,36\observed{110, 54, 36} and expected counts are 100,60,40\model{100, 60, 40}:
χ2=(110−100)2100+(54−60)260+(36−40)240=102100+(−6)260+(−4)240=1.00+0.60+0.40=2.00\displaystyle \begin{aligned} \observed{\chi^2} &= \frac{\gap{(\observed{110} - \model{100})^2}}{\model{100}} + \frac{\gap{(\observed{54} - \model{60})^2}}{\model{60}} \\ &\quad + \frac{\gap{(\observed{36} - \model{40})^2}}{\model{40}} \\ &= \frac{\gap{10^2}}{\model{100}} + \frac{\gap{(-6)^2}}{\model{60}} + \frac{\gap{(-4)^2}}{\model{40}} \\ &= \gap{1.00} + \gap{0.60} + \gap{0.40} = \observed{2.00} \end{aligned}
(Watch out: converting observed percentages to counts 110,54,36\observed{110, 54, 36} while leaving expected values as percentages 50,30,2050, 30, 20 gives χ2=104.0\chi^2 = 104.0 instead of 2.00\observed{2.00}.) With df=2\text{df} = 2, χ2cdf(2.00,1000,2)≈0.37>0.05\chi^2\text{cdf}(\observed{2.00}, 1000, 2) \approx \share{0.37} > \alphalevel{0.05}, so we fail to reject H0H_0.
For n=1,000n = 1{,}000 songs (df=3−1=2\text{df} = 3 - 1 = 2) Observed counts are 550,270,180\observed{550, 270, 180} and expected counts are 500,300,200\model{500, 300, 200}:
χ2=(550−500)2500+(270−300)2300+(180−200)2200=502500+(−30)2300+(−20)2200=5.00+3.00+2.00=10.00\displaystyle \begin{aligned} \observed{\chi^2} &= \frac{\gap{(\observed{550} - \model{500})^2}}{\model{500}} + \frac{\gap{(\observed{270} - \model{300})^2}}{\model{300}} \\ &\quad + \frac{\gap{(\observed{180} - \model{200})^2}}{\model{200}} \\ &= \frac{\gap{50^2}}{\model{500}} + \frac{\gap{(-30)^2}}{\model{300}} + \frac{\gap{(-20)^2}}{\model{200}} \\ &= \gap{5.00} + \gap{3.00} + \gap{2.00} = \observed{10.00} \end{aligned}
With df=2\text{df} = 2, χ2cdf(10.00,1000,2)≈0.0067<0.05\chi^2\text{cdf}(\observed{10.00}, 1000, 2) \approx \share{0.0067} < \alphalevel{0.05}, so we reject H0H_0.
A 5%\gap{5\%} gap across 200200 songs is easily explained by random variation (χ2=2.00\observed{\chi^2} = \observed{2.00}, p-value≈0.37\share{\text{p-value}} \approx \share{0.37}), whereas the same percentage gap across 1,0001{,}000 songs gives convincing evidence against the claimed model (χ2=10.00\observed{\chi^2} = \observed{10.00}, p-value≈0.0067\share{\text{p-value}} \approx \share{0.0067}).