197. Chi-Square Independence

Compares two observed categorical distributions.

Χ2=𝑖=1𝑘(𝑜𝑖𝑗𝑒𝑖𝑗)2𝑒𝑖𝑗𝐸𝑖𝑗=𝑅𝑖×𝐶𝑗𝑁df=(rows1)(cols1)
Example

You own a café, and you think you can make more money by getting people to buy larger drinks in the morning. You want to see if the time of day and coffee size are related, so you collect a simple random sample of last month’s orders. The observed data is below. At 𝛼=0.05 test if they are related.

ObservedSmallMediumLargeTotal
Morning7142950
Afternoon771529
Evening107421
Total242848100
expected=row total×col totaltable total
ExpectedSmallMediumLargeTotal
Morning5024100=125028100=145048100=2450
Afternoon2924100=6.962928100=8.122948100=13.9229
Evening2124100=5.042128100=5.882148100=10.0821
Total242848100
𝐻0:the two variables are independent𝐻𝑎:the 2 variables are related𝜒2=(712)212+(1414)214+(2924)224+(76.96)26.96+(78.12)28.12+(1513.92)213.92+(105.04)25.04+(75.88)25.88+(410.08)210.08=12.13

p-value < alpha

0.0164 < 0.05

Critical value < Chi^2 statistic

9.49 < 12.13

Example

Genre Preference by Age Group

ActionComedyDrama
Under 30605030140
Above 30204060120
809090260
ActionComedyDrama
Under 30140802601409026014090260140
Above 30120802601209026012090260120
809090260
ActionComedyDrama
Under 3043.0848.4648.46140
Above 3036.9241.5441.54120
809090260
ActionComedyDrama
Under 30(6043.08)243.08(5048.46)248.46(3048.46)248.46140
Above 30(2036.92)236.92(4041.54)241.54(6041.54)241.54120
809090260
ActionComedyDrama
Under 306.650.057.0313.73
Above 307.760.068.2116.02
14.400.1115.24𝟐𝟗.𝟕𝟓
Chi2=6.65+0.05+7.03+7.76+0.06+8.21=29.75

Since Χ2=29.75>Χ0.05,22=5.991, reject 𝐻0: genre preference depends on age group, driven almost entirely by action and drama (14.40 and 15.24) rather than comedy (0.11).