StatisticsChi-Square Tests for Categorical Data2 of 3
Chi-Square Tests for Categorical Data · 2

Chi-Square Test for Homogeneity

A Goodness of Fit test compares a single sample to a claimed distribution, but often we have two or more separate groups and want to know whether they follow the same distribution of a categorical variable.

1

Hypotheses and Expected Counts for Homogeneity

A Chi-Square Test for Homogeneity tests whether the distribution of a categorical variable is the same across multiple populations or treatments. Suppose we take a random sample of 300300 Phone users and a separate random sample of 200200 Laptop users to see whether they choose Free, Basic, and Pro subscription plans at the same rates.

Hypotheses and Expected Counts for Homogeneity
Free\htmlClass{lc-ink}{\text{Free}}
Basic\htmlClass{lc-ink}{\text{Basic}}
Pro\htmlClass{lc-ink}{\text{Pro}}
Total\htmlClass{lc-ink}{\text{Total}}
Phone\htmlClass{lc-ink}{\text{Phone}}
Laptop\htmlClass{lc-ink}{\text{Laptop}}
Total\htmlClass{lc-ink}{\text{Total}}
165(?)\observed{165}\hspace{0.25em}\expected{(?)}
85(?)\observed{85}\hspace{0.25em}\expected{(?)}
250\htmlClass{lc-ink}{250}
81(?)\observed{81}\hspace{0.25em}\expected{(?)}
69(?)\observed{69}\hspace{0.25em}\expected{(?)}
150\htmlClass{lc-ink}{150}
54(?)\observed{54}\hspace{0.25em}\expected{(?)}
46(?)\observed{46}\hspace{0.25em}\expected{(?)}
100\htmlClass{lc-ink}{100}
300\htmlClass{lc-ink}{300}
200\htmlClass{lc-ink}{200}
500\htmlClass{lc-ink}{500}
Text solution
State the competing hypothesesUnder the null hypothesis, plan choice does not depend on which device a user signs up on, so both populations share a single distribution.
H0:The distribution ofsubscription plan choiceis the same for allPhone users and allLaptop users.Ha:The distribution ofsubscription plan choiceis not the samefor both groups.\displaystyle \begin{aligned} \expected{H_0}&: \text{The distribution of} \\ &\quad \text{subscription plan choice} \\ &\quad \text{is the same for all} \\ &\quad \text{Phone users and all} \\ &\quad \text{Laptop users.} \\ H_a&: \text{The distribution of} \\ &\quad \text{subscription plan choice} \\ &\quad \text{is not the same} \\ &\quad \text{for both groups.} \end{aligned}
Pool the groups to find the overall column proportionsIf H0\expected{H_0} is true and both groups choose plans at the same rates, we combine all 500500 users to estimate the shared split across the three plans.
Free=250500=50%,Basic=150500=30%,Pro=100500=20%\displaystyle \begin{aligned} \text{Free} &= \frac{250}{500} = \share{50\%}, \\ \text{Basic} &= \frac{150}{500} = \share{30\%}, \\ \text{Pro} &= \frac{100}{500} = \share{20\%} \end{aligned}
Scale the pooled column proportions to each row totalMultiply each group's sample size by the pooled column fraction to find the expected count for every cell.
Expected=Column TotalGrand Total⏟pooled column fraction×Row Total=Row Total×Column TotalGrand Total\displaystyle \begin{aligned} &\expected{\text{Expected}} \\ &= \share{\underbrace{\frac{\text{Column Total}}{\text{Grand Total}}}_{\text{pooled column fraction}}} \times \text{Row Total} \\ &= \frac{\text{Row Total} \times \text{Column Total}}{\text{Grand Total}} \end{aligned}
Phone (n=300):Free=300×250500=150,Basic=300×150500=90,Pro=300×100500=60Laptop (n=200):Free=200×250500=100,Basic=200×150500=60,Pro=200×100500=40\displaystyle \begin{aligned} &\text{Phone } (n = 300): \\ &\quad \begin{aligned} \text{Free} &= \frac{300 \times 250}{500} = \expected{150}, \\ \text{Basic} &= \frac{300 \times 150}{500} = \expected{90}, \\ \text{Pro} &= \frac{300 \times 100}{500} = \expected{60} \end{aligned} \\[1.2em] &\text{Laptop } (n = 200): \\ &\quad \begin{aligned} \text{Free} &= \frac{200 \times 250}{500} = \expected{100}, \\ \text{Basic} &= \frac{200 \times 150}{500} = \expected{60}, \\ \text{Pro} &= \frac{200 \times 100}{500} = \expected{40} \end{aligned} \end{aligned}

So under H0\expected{H_0}, we expect 150\expected{150} Free users in the Phone sample and 100\expected{100} Free users in the Laptop sample simply because we surveyed more Phone users, even when both groups choose the Free plan at the exact same 50%\share{50\%} rate.

Because both rows follow the same 50%\share{50\%} Free, 30%\share{30\%} Basic, and 20%\share{20\%} Pro split under H0\expected{H_0}, unequal sample sizes always give unequal expected counts in every column. The expected counts in the two rows only match when the two sample sizes are equal.

Under the null hypothesis, both groups share the same column percentages, so only the row totals change the expected counts.
2

Conditions and the Chi-Square Statistic

Now we want to measure how far all six observed counts sit from their expected counts using a single χ2\observed{\chi^2} test statistic, after checking that our samples meet the conditions for a Chi-Square distribution.

Conditions and the Chi-Square Statistic
Free\htmlClass{lc-ink}{\text{Free}}
Basic\htmlClass{lc-ink}{\text{Basic}}
Pro\htmlClass{lc-ink}{\text{Pro}}
Total\htmlClass{lc-ink}{\text{Total}}
Phone\htmlClass{lc-ink}{\text{Phone}}
Laptop\htmlClass{lc-ink}{\text{Laptop}}
Total\htmlClass{lc-ink}{\text{Total}}
165(150)\observed{165}\hspace{0.25em}\expected{(150)}
85(100)\observed{85}\hspace{0.25em}\expected{(100)}
250\htmlClass{lc-ink}{250}
81(90)\observed{81}\hspace{0.25em}\expected{(90)}
69(60)\observed{69}\hspace{0.25em}\expected{(60)}
150\htmlClass{lc-ink}{150}
54(60)\observed{54}\hspace{0.25em}\expected{(60)}
46(40)\observed{46}\hspace{0.25em}\expected{(40)}
100\htmlClass{lc-ink}{100}
300\htmlClass{lc-ink}{300}
200\htmlClass{lc-ink}{200}
500\htmlClass{lc-ink}{500}
χ2=?\observed{\chi^2} = {?}
Text solution
Check the conditions across all groupsEach group must come from an independent random sample under 10%10\% of its population, and every cell's expected count must be at least 55.
Random: separate randomsamples of 300 Phone usersand 200 Laptop users10% Condition: 300<10% of all Phone users,200<10% of all Laptop usersLarge Counts: smallest expected count=40≥5\displaystyle \begin{aligned} &\text{Random: separate random} \\ &\quad \text{samples of } 300 \text{ Phone users} \\ &\quad \text{and } 200 \text{ Laptop users} \\ &10\% \text{ Condition: } \\ &\quad 300 < 10\% \text{ of all Phone users}, \\ &\quad 200 < 10\% \text{ of all Laptop users} \\ &\text{Large Counts: } \\ &\quad \text{smallest expected count} \\ &\quad = \expected{40} \ge 5 \end{aligned}
Square each cell's gap and divide by its expected countBecause the fixed totals force the raw gaps (Observed−Expected\gap{\observed{\text{Observed}} - \expected{\text{Expected}}}) to add to 00 across every row and column, we square each gap and divide by that cell's expected count to compare the gap to the size of the cell.
Phone contributions:(165−150)2150=1.50,(81−90)290=0.90,(54−60)260=0.60Laptop contributions:(85−100)2100=2.25,(69−60)260=1.35,(46−40)240=0.90\displaystyle \begin{aligned} &\text{Phone contributions}: \\ &\quad \begin{aligned} \frac{\gap{(\observed{165} - \expected{150})^2}}{\expected{150}} &= \gap{1.50}, \\ \frac{\gap{(\observed{81} - \expected{90})^2}}{\expected{90}} &= \gap{0.90}, \\ \frac{\gap{(\observed{54} - \expected{60})^2}}{\expected{60}} &= \gap{0.60} \end{aligned} \\[1.2em] &\text{Laptop contributions}: \\ &\quad \begin{aligned} \frac{\gap{(\observed{85} - \expected{100})^2}}{\expected{100}} &= \gap{2.25}, \\ \frac{\gap{(\observed{69} - \expected{60})^2}}{\expected{60}} &= \gap{1.35}, \\ \frac{\gap{(\observed{46} - \expected{40})^2}}{\expected{40}} &= \gap{0.90} \end{aligned} \end{aligned}
Sum all six contributions to find χ2\observed{\chi^2}Adding the six scaled pieces combines the whole table's difference from expected into one number.
χ2=∑(Observed−Expected)2Expected=1.50+0.90+0.60+2.25+1.35+0.90=7.50\displaystyle \begin{aligned} \observed{\chi^2} &= \sum \frac{\gap{(\observed{\text{Observed}} - \expected{\text{Expected}})^2}}{\expected{\text{Expected}}} \\ &= \gap{1.50} + \gap{0.90} + \gap{0.60} \\ &\quad + \gap{2.25} + \gap{1.35} + \gap{0.90} \\ &= \observed{7.50} \end{aligned}

So the observed table has a total chi-square statistic of χ2=7.5\observed{\chi^2} = \observed{7.5}, with the smaller Laptop sample contributing more in every column even though the gaps in each column are the same size (2.25\gap{2.25} vs. 1.50\gap{1.50} in Free, where both cells are off by 15\gap{15} users).

Because the Free column is fixed at 250250 users, moving users between Phone and Laptop always creates equal and opposite raw gaps (+Δ\gap{+\Delta} and −Δ\gap{-\Delta}) that cancel to 00 and give the exact same squared gap (Δ2\gap{\Delta^2}). Even so, the smaller Laptop group always contributes more to χ2\observed{\chi^2} because Δ2\gap{\Delta^2} is divided by an expected count of 100\expected{100} instead of 150\expected{150}.

Shifting users between Phone and Laptop gives both rows the same squared gap, so the smaller Laptop group always adds more to chi-square.
3

Degrees of Freedom, P-Value, and Conclusion

To tell whether χ2=7.5\observed{\chi^2} = \observed{7.5} is large enough to reject H0\expected{H_0}, we need the table's degrees of freedom so we can find the right-tail p-value on the matching Chi-Square curve.

Degrees of Freedom, P-Value, and Conclusion
Free\htmlClass{lc-ink}{\text{Free}}
Basic\htmlClass{lc-ink}{\text{Basic}}
Pro\htmlClass{lc-ink}{\text{Pro}}
Total\htmlClass{lc-ink}{\text{Total}}
Phone\htmlClass{lc-ink}{\text{Phone}}
Laptop\htmlClass{lc-ink}{\text{Laptop}}
Total\htmlClass{lc-ink}{\text{Total}}
??
??
250\htmlClass{lc-ink}{250}
??
??
150\htmlClass{lc-ink}{150}
??
??
100\htmlClass{lc-ink}{100}
300\htmlClass{lc-ink}{300}
200\htmlClass{lc-ink}{200}
500\htmlClass{lc-ink}{500}
χ2=7.5\observed{\chi^2 = 7.5}
df=?\text{df} = {?}
Free\htmlClass{lc-ink}{\text{Free}}
Basic\htmlClass{lc-ink}{\text{Basic}}
Pro\htmlClass{lc-ink}{\text{Pro}}
Total\htmlClass{lc-ink}{\text{Total}}
Phone\htmlClass{lc-ink}{\text{Phone}}
Laptop\htmlClass{lc-ink}{\text{Laptop}}
Total\htmlClass{lc-ink}{\text{Total}}
300\htmlClass{lc-ink}{300}
200\htmlClass{lc-ink}{200}
250\htmlClass{lc-ink}{250}
150\htmlClass{lc-ink}{150}
100\htmlClass{lc-ink}{100}
500\htmlClass{lc-ink}{500}
165\htmlClass{lc-blue}{165}
81\htmlClass{lc-blue}{81}
85\htmlClass{lc-blue}{85}
250−165\htmlClass{lc-ink}{250 - 165}
69\htmlClass{lc-blue}{69}
150−81\htmlClass{lc-ink}{150 - 81}
54\htmlClass{lc-blue}{54}
300−246\htmlClass{lc-ink}{300 - 246}
46\htmlClass{lc-blue}{46}
100−54\htmlClass{lc-ink}{100 - 54}
0\htmlClass{lc-ink}{0}
2\htmlClass{lc-ink}{2}
4\htmlClass{lc-ink}{4}
6\htmlClass{lc-ink}{6}
10\htmlClass{lc-ink}{10}
χ2\htmlClass{lc-ink}{\chi^2}
df=2\htmlClass{lc-ink}{\text{df} = 2}
7.5\htmlClass{lc-blue}{7.5}
heights×10\htmlClass{lc-mute}{\text{heights} \times 10}
p≈0.024\htmlClass{lc-green}{p \approx 0.024}
Text solution
Count the free cells to get degrees of freedomBecause the last cell in every row and the last cell in every column are fixed by subtraction from the row and column totals, only the cells outside the last row and last column can vary freely.
df\displaystyle \text{df} =(Rows−1)(Columns−1)\displaystyle = (\text{Rows} - 1)(\text{Columns} - 1) =(2−1)(3−1)\displaystyle = (2 - 1)(3 - 1) =2\displaystyle = 2
Find the right-tail p-value and compare to α=0.05\alphalevel{\alpha} = \alphalevel{0.05}On the df=2\text{df} = 2 curve, the area to the right of χ2=7.5\observed{\chi^2} = \observed{7.5} measures how often random sampling alone would give a table at least this far from expected if H0\expected{H_0} were true.
p-value\displaystyle \share{p\text{-value}} =P(χ2≥7.5)≈0.024<α\displaystyle = P(\observed{\chi^2} \ge \observed{7.5}) \approx \share{0.024} < \alphalevel{\alpha} =0.05\displaystyle = \alphalevel{0.05}

So we reject H0\expected{H_0}: since p=0.024<0.05\share{p} = \share{0.024} < \alphalevel{0.05}, we have convincing evidence that the distribution of subscription plan choice is not the same for all Phone users and all Laptop users, with the biggest share of χ2\observed{\chi^2} coming from the two Free cells (1.50+2.25=3.75\gap{1.50} + \gap{2.25} = \gap{3.75}, half of the entire 7.5\observed{7.5} statistic).

With the row and column totals fixed, choosing the two free cells (Phone Free and Phone Basic) locks the other four cells into place by subtraction. Moving those two free counts from 165\observed{165} and 81\observed{81} out to 180\observed{180} and 72\observed{72} doubles the gap from expected in all six cells, so χ2\observed{\chi^2} grows from 7.5\observed{7.5} to 30\observed{30}, far out in the right tail, and the p-value gets much smaller.

With the row and column totals fixed, choosing the two free cells sets the other four by subtraction and places chi-square on the curve for two degrees of freedom.
4

Homogeneity in a Randomized Experiment

So far our groups came from separate random samples of existing populations, but we also use the Chi-Square Test for Homogeneity when we create the groups ourselves by randomly assigning treatments in an experiment. Suppose we take 300300 users with expiring trials and randomly assign 100100 users to each of three button wordings ("Keep My Perks", "Don't Lose Access", and "Subscribe Now") to test whether the wording changes what users do next (Subscribe, Pause, or Cancel).

Homogeneity in a Randomized Experiment
300 users\htmlClass{lc-ink}{300 \text{ users}}
Random assignment\htmlClass{lc-ink}{\text{Random assignment}}
100\htmlClass{lc-ink}{100}
100\htmlClass{lc-ink}{100}
100\htmlClass{lc-ink}{100}
Keep My Perks\htmlClass{lc-ink}{\text{Keep My Perks}}
Don’t Lose Access\htmlClass{lc-ink}{\text{Don’t Lose Access}}
Subscribe Now\htmlClass{lc-ink}{\text{Subscribe Now}}
Text solution
State the hypotheses across the three treatmentsIn HaH_a, state that the distribution is not the same for all three treatments rather than claiming all three differ from one another.
H0:The true distribution ofuser action (Subscribe,Pause, Cancel) is the samefor all three button wordings.Ha:The true distribution ofuser action is not the samefor all three button wordings.\displaystyle \begin{aligned} \expected{H_0}&: \text{The true distribution of} \\ &\quad \text{user action (Subscribe,} \\ &\quad \text{Pause, Cancel) is the same} \\ &\quad \text{for all three button wordings.} \\ H_a&: \text{The true distribution of} \\ &\quad \text{user action is not the same} \\ &\quad \text{for all three button wordings.} \end{aligned}
Check conditions for an experiment and find expected countsBecause the groups were formed by random assignment rather than sampling without replacement from a finite population, we do not check the 10%10\% condition, and the equal group sizes (n=100n = 100) give the same expected counts in every row.
Expected counts in each row(n=100):Subscribe=100×90300=30,Pause=100×60300=20,Cancel=100×150300=50(all ≥5)\displaystyle \begin{aligned} &\text{Expected counts in each row} \\ &(n = 100): \\ &\quad \begin{aligned} \text{Subscribe} &= \frac{100 \times 90}{300} = \expected{30}, \\ \text{Pause} &= \frac{100 \times 60}{300} = \expected{20}, \\ \text{Cancel} &= \frac{100 \times 150}{300} = \expected{50} \\ &\quad (\text{all } \ge 5) \end{aligned} \end{aligned}
Sum all nine cell contributions to χ2\observed{\chi^2}Compute (Observed−Expected)2Expected\frac{\gap{(\observed{\text{Observed}} - \expected{\text{Expected}})^2}}{\expected{\text{Expected}}} for every cell in the 3×33 \times 3 table and add them up.
χ2=(2.70+0+1.62)⏟Keep My Perks+(0+1.80+0.72)⏟Don’t Lose Access+(2.70+1.80+4.50)⏟Subscribe Now=15.84\displaystyle \begin{aligned} \observed{\chi^2} &= \underbrace{(\gap{2.70} + \gap{0} + \gap{1.62})}_{\text{Keep My Perks}} \\ &\quad + \underbrace{(\gap{0} + \gap{1.80} + \gap{0.72})}_{\text{Don't Lose Access}} \\ &\quad + \underbrace{(\gap{2.70} + \gap{1.80} + \gap{4.50})}_{\text{Subscribe Now}} \\ &= \observed{15.84} \end{aligned}
Find degrees of freedom and the right-tail p-valueFilling the top-left 2×22 \times 2 block locks the last row and last column, leaving 44 degrees of freedom.
df=(3−1)(3−1)=4,p-value=P(χ2≥15.84)≈0.0032<α=0.05\displaystyle \begin{aligned} \text{df} &= (3 - 1)(3 - 1) = 4, \\ \share{p\text{-value}} &= P(\observed{\chi^2} \ge \observed{15.84}) \\ &\approx \share{0.0032} < \alphalevel{\alpha} = \alphalevel{0.05} \end{aligned}

Because p=0.0032<0.05\share{p} = \share{0.0032} < \alphalevel{0.05} and users were randomly assigned to the buttons, we reject H0\expected{H_0} and conclude that button wording causes a difference in the distribution of user actions, with the "Subscribe Now" Cancel cell (Observed=65\observed{\text{Observed}} = \observed{65} vs. Expected=50\expected{\text{Expected}} = \expected{50}, contributing 4.50\gap{4.50}) making up the largest share of χ2\observed{\chi^2}.

Whenever you compare three or more groups, write HaH_a as "the distribution is not the same for all groups" (or "at least one group has a different distribution"), because if two button wordings have the same distribution and only the third differs, H0\expected{H_0} is already false.

Key concepts

Use a Chi-Square Test for Homogeneity to compare the distribution of a categorical variable across two or more separate groups, whether they come from independent random samples (300300 Phone users vs. 200200 Laptop users) or random assignment in an experiment (100100 users assigned to each of three button wordings). When you only have a single sample compared against one claimed set of percentages, use a Goodness of Fit test instead.

Because H0\expected{H_0} claims all groups follow the same distribution without giving the percentages, pool the groups together to find each column's overall fraction, then scale to each group's row total:

Expected\displaystyle \expected{\text{Expected}} =Row Total×Column TotalGrand Total\displaystyle = \frac{\text{Row Total} \times \text{Column Total}}{\text{Grand Total}}

Check for separate random samples or random assignment, check the 10%10\% condition only when sampling without replacement from finite populations (skip it in randomized experiments), and check Large Counts on the expected counts (every Expected≥5\text{every } \expected{\text{Expected}} \ge 5, even if an observed count is below 55). Then add up the scaled squared gaps across all cells and use (Rows−1)(Columns−1)(\text{Rows} - 1)(\text{Columns} - 1) degrees of freedom to find the right-tail p-value:

χ2=∑(Observed−Expected)2Expected,df=(Rows−1)(Columns−1)\displaystyle \begin{gathered} \observed{\chi^2} = \sum \frac{\gap{(\observed{\text{Observed}} - \expected{\text{Expected}})^2}}{\expected{\text{Expected}}}, \\ \text{df} = (\text{Rows} - 1)(\text{Columns} - 1) \end{gathered}
5

Practice

1

A streaming service takes separate random samples of 400400 Teen subscribers and 100100 Senior subscribers to compare which video quality setting they use: Standard, HD, or 4K. In the Teen sample, 150\observed{150} use Standard, 170\observed{170} use HD, and 80\observed{80} use 4K. In the Senior sample, 25\observed{25} use Standard, 55\observed{55} use HD, and 20\observed{20} use 4K. (Across all 500500 subscribers, 175175 use Standard, 225225 use HD, and 100100 use 4K.) (a) A marketer points to the 4K column (80\observed{80} Teens vs. 20\observed{20} Seniors) and claims Teens are much more likely to use 4K than Seniors. Explain why comparing 80\observed{80} to 20\observed{20} directly is misleading. (b) Find the expected counts for all six cells under the null hypothesis. What do the expected counts in the 4K column show about the marketer's claim?

Compare the two row totals (400400 vs. 100100) first, then pool all 500500 subscribers to find what percentage of the entire table chose each quality setting.

(a) Comparing 80\observed{80} directly to 20\observed{20} is unfair because the Teen sample (400400) is four times as large as the Senior sample (100100), so Teens will naturally have higher raw counts even if both groups choose settings at the same rates. (b) Pooling all 500500 subscribers gives column proportions of 175500=35%\frac{175}{500} = \share{35\%} Standard, 225500=45%\frac{225}{500} = \share{45\%} HD, and 100500=20%\frac{100}{500} = \share{20\%} 4K. (Be careful not to split each row equally into thirds like 4003=133.33\frac{400}{3} = 133.33 and 1003=33.33\frac{100}{3} = 33.33; H0\expected{H_0} says the two age groups share the same distribution, not that all three video settings are equally popular.) Multiplying each row total by the pooled percentages using Expected=Row Total×Column TotalGrand Total\expected{\text{Expected}} = \frac{\text{Row Total} \times \text{Column Total}}{\text{Grand Total}}:
Teen (n=400):Standard=400×175500=140,HD=400×225500=180,4K=400×100500=80Senior (n=100):Standard=100×175500=35,HD=100×225500=45,4K=100×100500=20\displaystyle \begin{aligned} &\text{Teen } (n = 400): \\ &\quad \begin{aligned} \text{Standard} &= \frac{400 \times 175}{500} = \expected{140}, \\ \text{HD} &= \frac{400 \times 225}{500} = \expected{180}, \\ \text{4K} &= \frac{400 \times 100}{500} = \expected{80} \end{aligned} \\[1.2em] &\text{Senior } (n = 100): \\ &\quad \begin{aligned} \text{Standard} &= \frac{100 \times 175}{500} = \expected{35}, \\ \text{HD} &= \frac{100 \times 225}{500} = \expected{45}, \\ \text{4K} &= \frac{100 \times 100}{500} = \expected{20} \end{aligned} \end{aligned}
In the 4K column, the observed counts (80\observed{80} and 20\observed{20}) equal the expected counts (80\expected{80} and 20\expected{20}), showing that both groups chose 4K at the exact same 20%\share{20\%} rate.
2

An online retailer tests whether three checkout page layouts (Single Page, Two-Step, Accordion) affect what shoppers do at checkout (Complete Purchase, Save for Later, Abandon Cart). They take 150150 shoppers entering checkout and randomly assign 5050 to each layout. Across all 150150 shoppers, 9090 Complete Purchase, 1818 Save for Later, and 4242 Abandon Cart. In the Save for Later column, the observed counts are 3\observed{3} for Single Page, 8\observed{8} for Two-Step, and 7\observed{7} for Accordion. (a) State the null and alternative hypotheses in context. (b) A colleague objects that we cannot run a Chi-Square Test for Homogeneity for two reasons: 150150 shoppers is more than 10%10\% of the shoppers on the site that hour, and the Single Page "Save for Later" cell has an observed count of 3\observed{3}, which is less than 55. Explain why both objections are incorrect.

Check how the three groups of 5050 shoppers were created (sampling from a population vs. random assignment), and check which counts, observed or expected, must be at least 55.

(a) H0\expected{H_0}: The true distribution of checkout action (Complete Purchase, Save for Later, Abandon Cart) is the same for all three checkout page layouts. HaH_a: The true distribution of checkout action is not the same for all three checkout page layouts (at least one layout has a different distribution). (Watch out for the mistake of writing that "all three layouts have different distributions", because if two layouts have the same distribution and only one differs, H0\expected{H_0} is already false.) (b) First, the 10%10\% condition is not checked because the groups were created by random assignment in an experiment rather than sampling without replacement from a finite population. Second, the Large Counts condition requires every expected count, not every observed count, to be at least 55 (checking the observed count of 3\observed{3} is a common mistake that leads to wrongly skipping the test). Since each layout has 5050 shoppers, the expected counts in every row are:
Complete Purchase=50×90150=30,Save for Later=50×18150=6,Abandon Cart=50×42150=14\displaystyle \begin{aligned} \text{Complete Purchase} &= \frac{50 \times 90}{150} = \expected{30}, \\ \text{Save for Later} &= \frac{50 \times 18}{150} = \expected{6}, \\ \text{Abandon Cart} &= \frac{50 \times 42}{150} = \expected{14} \end{aligned}
Every expected count is at least 55 (the smallest is 6\expected{6}), so the conditions are met.
3

A transportation study takes separate random samples of 120120 Downtown employees and 8080 Suburban employees (200200 employees total) and records each person's main commute mode: Drive, Transit, or Walk/Bike. Across all 200200 employees, 100100 Drive, 6060 take Transit, and 4040 Walk/Bike. Four cell counts were accidentally erased from the table, leaving only two observed counts: Downtown Drive =48= \observed{48} and Downtown Transit =42= \observed{42}. (a) How many degrees of freedom does this table have, and what are the four missing observed counts? (b) Find the six expected counts and calculate the χ2\observed{\chi^2} statistic. Why does the Suburban Drive cell contribute more to χ2\observed{\chi^2} than the Downtown Drive cell even though both cells are off from their expected counts by 12\gap{12} employees?

Use the fixed column totals (100,60100, 60) and row totals (120,80120, 80) to fill in the locked cells by subtraction, then scale the pooled column percentages (50%,30%,20%\share{50\%}, \share{30\%}, \share{20\%}) to each row total.

(a) The degrees of freedom are:
df\displaystyle \text{df} =(Rows−1)(Columns−1)\displaystyle = (\text{Rows} - 1)(\text{Columns} - 1) =(2−1)(3−1)\displaystyle = (2 - 1)(3 - 1) =2\displaystyle = 2
(Do not take total cells minus one to get 6−1=56 - 1 = 5; the row and column totals lock four of the six cells.) Using the fixed row and column totals to fill in the locked cells by subtraction:
Suburban Drive=100−48=52,Suburban Transit=60−42=18Downtown Walk/Bike=120−(48+42)=30,Suburban Walk/Bike=40−30=10\displaystyle \begin{aligned} &\text{Suburban Drive} \\ &\quad = 100 - \observed{48} = \observed{52}, \\ &\text{Suburban Transit} \\ &\quad = 60 - \observed{42} = \observed{18} \\ &\text{Downtown Walk/Bike} \\ &\quad = 120 - (\observed{48} + \observed{42}) = \observed{30}, \\ &\text{Suburban Walk/Bike} \\ &\quad = 40 - \observed{30} = \observed{10} \end{aligned}
(b) The pooled split across all 200200 employees is 50%\share{50\%} Drive, 30%\share{30\%} Transit, and 20%\share{20\%} Walk/Bike. Scaling to each row total gives the expected counts:
Downtown (n=120):Drive=60,Transit=36,Walk/Bike=24Suburban (n=80):Drive=40,Transit=24,Walk/Bike=16\displaystyle \begin{aligned} \text{Downtown } (n = 120): \quad \text{Drive} &= \expected{60}, \\ \text{Transit} &= \expected{36}, \\ \text{Walk/Bike} &= \expected{24} \\ \text{Suburban } (n = 80): \quad \text{Drive} &= \expected{40}, \\ \text{Transit} &= \expected{24}, \\ \text{Walk/Bike} &= \expected{16} \end{aligned}
Computing (Observed−Expected)2Expected\frac{\gap{(\observed{\text{Observed}} - \expected{\text{Expected}})^2}}{\expected{\text{Expected}}} for each cell (be careful to divide by the expected count rather than the observed count, which would wrongly give 13.4313.43):
Downtown:(−12)260=2.40,6236=1.00,6224=1.50Suburban:12240=3.60,(−6)224=1.50,(−6)216=2.25\displaystyle \begin{aligned} \text{Downtown}: \quad \frac{\gap{(-12)^2}}{\expected{60}} &= \gap{2.40}, \\ \frac{\gap{6^2}}{\expected{36}} &= \gap{1.00}, \\ \frac{\gap{6^2}}{\expected{24}} &= \gap{1.50} \\ \text{Suburban}: \quad \frac{\gap{12^2}}{\expected{40}} &= \gap{3.60}, \\ \frac{\gap{(-6)^2}}{\expected{24}} &= \gap{1.50}, \\ \frac{\gap{(-6)^2}}{\expected{16}} &= \gap{2.25} \end{aligned}
χ2\displaystyle \observed{\chi^2} =2.40+1.00+1.50+3.60+1.50+2.25\displaystyle = \gap{2.40} + \gap{1.00} + \gap{1.50} + \gap{3.60} + \gap{1.50} + \gap{2.25} =12.25\displaystyle = \observed{12.25}
Suburban Drive contributes more (3.60\gap{3.60} vs. 2.40\gap{2.40}) because the same squared gap of 144\gap{144} is divided by a smaller expected count of 40\expected{40} instead of 60\expected{60}.
4

A company takes 300300 customers who contacted support and randomly assigns 100100 customers to each of three follow-up methods (Phone Call, Live Chat, Automated Email), then records whether each customer rates the experience as Satisfied, Neutral, or Unsatisfied. Observed counts: Phone Call has 55\observed{55} Satisfied, 30\observed{30} Neutral, 15\observed{15} Unsatisfied (total 100100); Live Chat has 55\observed{55} Satisfied, 33\observed{33} Neutral, 12\observed{12} Unsatisfied (total 100100); Automated Email has 40\observed{40} Satisfied, 27\observed{27} Neutral, 33\observed{33} Unsatisfied (total 100100). Column totals are 150150 Satisfied, 9090 Neutral, and 6060 Unsatisfied (grand total 300300). (a) Find the expected counts, the χ2\observed{\chi^2} test statistic, and the degrees of freedom. (b) For this test statistic and degrees of freedom, the p-value is 0.0024\share{0.0024}. Interpret this p-value in context. (c) At α=0.05\alphalevel{\alpha} = \alphalevel{0.05}, state your conclusion, explain whether you can conclude that the follow-up method causes a difference in ratings, and identify which single cell contributes the most to χ2\observed{\chi^2}.

Since all three treatment rows have 100100 customers, find the expected counts once from the column totals (150,90,60150, 90, 60 out of 300300), and check how the groups were formed before deciding whether the conclusion is causal.

(a) The pooled column proportions are 150300=50%\frac{150}{300} = \share{50\%} Satisfied, 90300=30%\frac{90}{300} = \share{30\%} Neutral, and 60300=20%\frac{60}{300} = \share{20\%} Unsatisfied. Since each row has 100100 customers, the expected counts in every row are 50\expected{50} Satisfied, 30\expected{30} Neutral, and 20\expected{20} Unsatisfied. Computing (Observed−Expected)2Expected\frac{\gap{(\observed{\text{Observed}} - \expected{\text{Expected}})^2}}{\expected{\text{Expected}}} for all nine cells:
Phone Call:5250+0230+(−5)220=0.50+0+1.25=1.75Live Chat:5250+3230+(−8)220=0.50+0.30+3.20=4.00Automated Email:(−10)250+(−3)230+13220=2.00+0.30+8.45=10.75\displaystyle \begin{aligned} &\text{Phone Call}: \\ &\quad \frac{\gap{5^2}}{\expected{50}} + \frac{\gap{0^2}}{\expected{30}} + \frac{\gap{(-5)^2}}{\expected{20}} \\ &\qquad = \gap{0.50} + \gap{0} + \gap{1.25} = \gap{1.75} \\[0.8em] &\text{Live Chat}: \\ &\quad \frac{\gap{5^2}}{\expected{50}} + \frac{\gap{3^2}}{\expected{30}} + \frac{\gap{(-8)^2}}{\expected{20}} \\ &\qquad = \gap{0.50} + \gap{0.30} + \gap{3.20} = \gap{4.00} \\[0.8em] &\text{Automated Email}: \\ &\quad \frac{\gap{(-10)^2}}{\expected{50}} + \frac{\gap{(-3)^2}}{\expected{30}} + \frac{\gap{13^2}}{\expected{20}} \\ &\qquad = \gap{2.00} + \gap{0.30} + \gap{8.45} = \gap{10.75} \end{aligned}
Summing all nine contributions gives χ2=16.50\observed{\chi^2} = \observed{16.50}. For a 3×33 \times 3 table, the degrees of freedom are df=(3−1)(3−1)=4\text{df} = (3 - 1)(3 - 1) = 4 (watch out for the mistake of using Columns−1=2\text{Columns} - 1 = 2 as in Goodness of Fit, or 9−1=89 - 1 = 8). (b) If the true distribution of customer ratings were the same for all three follow-up methods, there is about a 0.24%\share{0.24\%} chance that random assignment alone would give a table with a χ2\observed{\chi^2} statistic of 16.50\observed{16.50} or larger (do not interpret 0.0024\share{0.0024} as the probability that H0\expected{H_0} is true). (c) Because p=0.0024<α=0.05\share{p} = \share{0.0024} < \alphalevel{\alpha} = \alphalevel{0.05}, we reject H0\expected{H_0}. Since customers were randomly assigned to the treatments (rather than choosing for themselves or being sampled from existing groups), we have convincing evidence that the follow-up method causes a difference in the distribution of customer ratings. The Automated Email, Unsatisfied cell (Observed=33\observed{\text{Observed}} = \observed{33} vs. Expected=20\expected{\text{Expected}} = \expected{20}) contributes the most to χ2\observed{\chi^2} at 8.45\gap{8.45}.