StatisticsChi-Square Tests for Categorical Data3 of 3
Chi-Square Tests for Categorical Data · 3
Chi-Square Test for Independence
When we measure two categorical variables on every individual in a single random sample, we need a way to test whether those two variables are associated in the population or just varying by random chance.
1
Independence vs. Homogeneity and Stating Hypotheses
Before we can test whether where a student sits in a large college lecture hall (Front Row, Middle Section, or Back Section) is associated with passing the class (Pass or Fail), we have to be sure which chi-square test our study calls for. A two-way table for a Chi-Square Test for Independence looks identical to one for a Chi-Square Test for Homogeneity. The difference is entirely in how the data was collected and which totals were fixed in advance.
In our study, a researcher takes one random sample of 300 lecture-hall students and records both seat location and course outcome for each person.
Independence vs. Homogeneity and Stating Hypotheses
Text solution
Identify the study design from the fixed totalsBecause we took one random sample of 300 students and measured two categorical variables on each person, neither the row totals (50,150,100) nor the column totals (180,120) were known beforehand. Only the grand total of 300 was fixed in advance, which calls for a Chi-Square Test for Independence.
State the hypotheses in terms of independence in the populationWe test whether knowing a student's seat location tells us anything about their chances of passing in the population of lecture-hall students.
H0Ha:Seat location and courseoutcome are independent(not associated) in thispopulation of students.:Seat location and courseoutcome are not independent(are associated) in thispopulation of students.
2
Conditions, Expected Counts, and the Chi-Square Statistic
Even if seat location and passing are completely independent in the population, a random sample of 300 students will not split into exact 60% pass and 40% fail proportions in every row. We want to find the χ2 statistic, which measures how far the counts across the whole table are from the expected counts, and its p-value, which measures how unlikely it would be to get differences as large as ours by random chance alone.
Once the counts are in the table, the math works the exact same way as in the Test for Homogeneity.
Conditions, Expected Counts, and the Chi-Square Statistic
Text solution
Check the conditions for a single random sampleThe data comes from one random sample of 300 students, that single sample is at most 10% of a population of at least 3,000 lecture-hall students, and every cell's expected count must be at least 5.
N=300≤10% of population⟹Population≥3,000,all E≥5
Apply the overall column proportions to each row totalMultiply each row total by the overall pass rate (300180=60%) and fail rate (300120=40%) to find the expected counts E under H0. The smallest expected count is 20≥5, so the Large Counts condition is met.
Compare each squared gap to its expected countSubtract O−E, square the difference so positive and negative gaps do not cancel, and divide by E so a gap of 6 students counts for more in a cell with a smaller expected count than in one with a larger expected count.
Sum the six components and find the tail areaAdd the components across all cells and compare the total against the χ2 distribution whose degrees of freedom are the number of cells we can freely fill before the row and column totals lock in the rest.
Because p=0.0007<α=0.05, we reject H0: there is convincing statistical evidence of an association between seat location and passing the class in this population of students.
3
Where Is the Association? Standardized Residuals
When a table is larger than 2×2, rejecting H0 only tells us that the variables are associated somewhere in the table. It does not tell us whether the Back Section is actually failing at an unusually high rate or whether a single row is causing the whole result. To see which cells differ from independence, we compute each cell's standardized residual (or Pearson residual), which acts roughly like a z-score, measuring how far the observed count sits above or below its expected count in units of E.
Let's see what happens when we turn our six cell components into standardized residuals.
Where Is the Association? Standardized Residuals
Text solution
Take the signed square root of each cell componentUndo the squaring in E(O−E)2 and put back the sign of O−E so the residual shows both how far the cell is from expectation and whether it is above (+) or below (−) expected.
standardized residualz=EO−E=±Component
Compare each cell's residual with the ±2 random-noise cutoffAt the 95% level, a z-score is significantly unusual when it goes past roughly ±2 (specifically ±1.96, which corresponds to a cell component greater than 22=4).
Only the Front Row crosses ±2, meaning the entire significant association comes from front-row students passing more (+2.19) and failing less (−2.68) than expected, while the Middle and Back sections lie well inside the −2 to +2 random-noise range. (Statistical software often prints an Adjusted Standardized Residual that divides by a smaller number to account for the row and column proportions, giving ±3.80 for Front, ±1.41 for Middle, and ±1.50 for Back. This points to the exact same cells, though by hand you compute EO−E.)
Notice how the same gap O−E gives a much larger standardized residual in the 50-seat Front Row than in the 150-seat Middle Section, because we divide by a smaller E.
A cell stands out from random noise only when its residual goes past two, and the same student gap creates a much bigger residual in a small section than in a large one.
4
Strength of Association: Cramér's V and Causation
Knowing that an association is statistically significant (p=0.0007) and where it is (the Front Row) still leaves one question open: how strong is the association overall? We cannot use χ2=14.5 to measure strength because, with the same proportion in every cell, χ2 grows proportionally with the sample size N. Instead, we compute Cramér's V, an effect size that divides out sample size and table dimensions to measure the strength of association on a scale from 0 (completely independent) to 1 (perfectly associated).
Let's calculate Cramér's V for our lecture hall and see what our study design allows us to conclude about cause and effect.
Strength of Association: Cramér's V and Causation
Text solution
Divide out the sample size N and the smaller table dimension minus 1Dividing χ2 by N=300 removes the effect of sample size, and dividing by min(R−1,C−1)=min(3−1,2−1)=1 scales the maximum possible value to 1.
N⋅min(R−1,C−1)χ2=300×114.5=0.0483
Take the square root to return to unsquared unitsTaking the square root undoes the squaring in χ2 and gives Cramér's V.
Crameˊr’s V (0 to 1 scale)V=N⋅min(R−1,C−1)χ2=0.0483≈0.22
When min(R−1,C−1)=1, benchmarks of 0.10 (small), 0.30 (medium), and 0.50 (large) tell us that V=0.22 is a small-to-moderate association. And because this was an observational study where students chose their own seats rather than being randomly assigned, the test shows an association in the population, not that moving to the front row causes higher grades.
Let's see what happens to χ2 and Cramér's V when we scale up the sample size N while keeping the proportion of students in every cell the same.
Copying the exact same lecture hall makes χ2 grow right along with sample size N, while Cramér's V stays at 0.22.
Key concepts
When you see a two-way table, start by checking how the data was collected before writing a single hypothesis. If the researcher took one random sample from a population and recorded two categorical variables on each individual, so only the grand total N was fixed in advance (like surveying 300 students on seat location and passing), use the Chi-Square Test for Independence to test whether the two variables are associated in the population (H0: independent vs. Ha: not independent / associated). Do not use the Test for Independence when a researcher samples separate groups with fixed group totals in advance (50 front, 150 middle, 100 back) or randomly assigns subjects to treatments; that design calls for the Chi-Square Test for Homogeneity.
Once the design is set, check that the data comes from one random sample of at most 10% of the population (N≤0.10×Population) and that all expected counts E=Grand TotalRow Total×Column Total are at least 5 (checking the smallest row and smallest column first, such as 30050×120=20≥5). Add the cell components χ2=∑E(O−E)2 and compare against df=(R−1)(C−1).
If p<α in a table larger than 2×2, follow up to find where and how strong the association is (if p≥α, stop, because there is no significant association to break down):
Where (Standardized Residuals)
z=EO−E=±Component turns each cell into a z-score. Only cells beyond ±2 (cell components above 4, like Front Pass z=+4.8=+2.19 and Front Fail z=−7.2=−2.68) differ significantly from independence at the 95% level; cells inside −2 to +2 (like Back Fail z=+0.9=+0.95) could easily be random sampling noise.
How Strong (Cramér's V) and Why
Because scaling a sample by k multiplies χ2 by k, divide out N and the smaller dimension minus 1:V=N⋅min(R−1,C−1)χ2 (for our 3×2 table, V=300×114.5≈0.22, a small-to-moderate association). And because a single-sample survey is observational, even a tiny p-value and a large V show association, never causation.
5
Practice
1
Two researchers each build a 3-by-2 table relating commute method (Walk, Bus, Drive) and arrival status (On Time, Late) for 400 workers. Researcher A takes one random sample of 400 workers at a downtown office complex and records both commute method and arrival status for each person. Researcher B takes separate random samples of 100 walkers, 150 bus riders, and 150 drivers and records whether each worker arrived on time or late. Which study calls for a Chi-Square Test for Independence, which totals in its table were fixed before data collection, and what are its null and alternative hypotheses?
A common mistake is to pick Researcher B or say the row totals of 100,150, and 150 are fixed in an independence test. Fixing group totals across separate samples is what makes Researcher B's study a Test for Homogeneity.
Ask which researcher knew the row totals (100,150,150) before surveying a single worker, and which researcher only knew the grand total (400).
Researcher A measured two categorical variables on one random sample of 400 workers, so Researcher A's study calls for a Chi-Square Test for Independence, with only the grand total of 400 fixed before data collection. (A common mistake is to pick Researcher B or say the row totals of 100,150, and 150 are fixed in an independence test. Fixing group totals across separate samples is what makes Researcher B's study a Test for Homogeneity.) For Researcher A:
H0: Commute method and arrival status are independent (not associated) in this population of office workers.
Ha: Commute method and arrival status are not independent (are associated) in this population of office workers.
(Watch out for stating the hypotheses as "the proportions of on-time arrivals are equal across groups". That phrasing belongs to Homogeneity rather than Independence.)
2
A hospital takes one random sample of 250 emergency-room patients and records arrival shift (Day, Evening, Overnight) and outcome (Admitted, Discharged). In the sample, 40 arrived during the Day, 110 in the Evening, and 100 Overnight; overall, 50 patients were Admitted and 200 were Discharged. Find the expected counts for the Day row, determine whether the Large Counts condition is met for the entire table, and find the minimum number of emergency-room patients in the hospital's population required to satisfy the 10% condition.
Find the overall percentage of patients who were Admitted and Discharged out of 250, apply those percentages to the 40 Day patients, and check why the Day and Admitted cell is the only one that could possibly fail the ≥5 check.
Overall, 25050=20% of patients were Admitted and 250200=80% were Discharged. Applying those proportions to the 40 Day patients:
Because Day is the smallest row (40) and Admitted is the smaller column (50), E=8 is the smallest expected count in the entire table (Evening expected counts are 22 and 88; Overnight expected counts are 20 and 80). Since all six expected counts are at least 5,the Large Counts condition is met. For the 10% condition, the single random sample of 250 must be at most 10% of the population (a common mistake is to multiply each row total by 10 separately and require 400 Day, 1,100 Evening, and 1,000 Overnight patients as if there were three separate samples, or to check observed counts instead of expected counts for the ≥5 rule):
A grocery store surveys one random sample of 200 shoppers and records payment method (Cash, Card, Mobile Pay) and coupon use (Used Coupon, No Coupon). Overall, 80 shoppers used a coupon (40%) and 120 did not (60%). The observed counts are: Cash (50 shoppers): 26 Used Coupon, 24 No Coupon; Card (100 shoppers): 28 Used Coupon, 72 No Coupon; Mobile Pay (50 shoppers): 26 Used Coupon, 24 No Coupon. Given expected counts of (20,30) for Cash, (40,60) for Card, and (20,30) for Mobile Pay, calculate all six cell components, the χ2 statistic, and the degrees of freedom, and state the conclusion at α=0.05 given p=0.0025.
After squaring each difference (O−E)2, be sure to divide each cell by its own expected count E before adding the six components, and use the number of rows and columns, not N−1, for the degrees of freedom.
First find the differences O−E:(+6,−6) for Cash, (−12,+12) for Card, and (+6,−6) for Mobile Pay. Dividing each squared difference (O−E)2 by its expected count E (be careful not to divide by the observed count O, which would give 2636+2436+⋯=12.91, or forget to divide by E altogether, which would give 36+36+144+144+36+36=432):
Summing the six components and finding the degrees of freedom (watch out for using df=R×C=6 or N−1=199 instead of (R−1)(C−1)):
χ2df=1.8+1.2+3.6+2.4+1.8+1.2=12.0,=(3−1)(2−1)=2
Since p=0.0025<α=0.05, we reject H0 and conclude there is convincing statistical evidence of an association between payment method and coupon use in this population of shoppers.
4
In a follow-up analysis to a significant Chi-Square Test for Independence, two cells in different rows both have an observed count that is 10 below expected (O−E=−10): Cell A has an expected count of E=100, and Cell B has an expected count of E=16. Find the standardized residual and the χ2 component for each cell, and explain which cell shows a statistically significant departure from independence at the 95% level.
Watch out for dividing O−E by E instead of E, which would give −0.10 and −0.625.
Divide O−E by E (keeping the negative sign) for the standardized residual, divide (O−E)2 by E for the component, and check which cell crosses the ±2 (or component >4) cutoff.
For Cell A (E=100) and Cell B (E=16) (watch out for dividing O−E by E instead of E, which would give −0.10 and −0.625, or dropping the minus sign when taking the square root of the component):
Only Cell B shows a statistically significant departure from independence at the 95% levelbecause its standardized residual of −2.50 goes beyond ±2 (specifically ±1.96, or a component above 4), whereas Cell A's residual of −1.00 lies well inside the −2 to +2 random sampling noise range.
5
A university surveys one random sample of N=500 students on class year (4 categories) and housing type (3 categories) and gets χ2=40.0 (p<0.0001). (a) Calculate Cramér's V for this 4-by-3 table. (b) If a second university had the exact same proportions in every cell of its 4-by-3 table across a sample of N=2,000 students (4 times as large), what would its χ2 statistic and Cramér's V be? (c) Does this result prove that a student's housing type causes changes in retention across class years?
The most common mistake here is assuming min(R−1,C−1) is always 1 as in a 3×2 table, which gives 50040≈0.283.Watch out for dividing by the full degrees of freedom df=3×2=6, which gives 3,00040≈0.115.
For (a), notice that the table is 4-by-3, so min(R−1,C−1) is not 1. For (b), trace what multiplying every count by 4 does to E(O−E)2 versus V.
(a)The smaller dimension minus 1 is min(4−1,3−1)=min(3,2)=2 (the most common mistake here is assuming min(R−1,C−1) is always 1 as in a 3×2 table, which gives 50040≈0.283, or dividing by the full degrees of freedom df=3×2=6, which gives 3,00040≈0.115):
V=500×240.0=1,00040.0=0.04=0.20
(b)Multiplying every observed and expected count by 4 multiplies (O−E)2 by 42=16 and E by 4 (avoid multiplying χ2 by 42=16 to get 640, or assuming χ2 stays at 40.0), so χ2 increases by a factor of 416=4 to χ2=160.0, while Cramér's V divides out the sample size and stays unchanged at V=0.20. (c)No; because the data comes from a single-sample observational survey where students were not randomly assigned to housing types, the test shows an association in the population, not causation.