Chi-square test of independence
The chi-square test of independence tests whether two categorical variables are associated by comparing observed frequencies in a contingency table with those expected if the variables were unrelated.
FrameworkHypothesis testing
See it move
Chi-square tests whether two categorical variables are related. The formula sums, across every cell of a contingency table, the squared gap between the observed count O and the expected count E, divided by E. Degrees of freedom equal (rows − 1) × (columns − 1). A large χ² means the observed counts differ from what independence predicts; each expected cell should be at least 5.
The formula
Variables
- Observed frequency in a cell of the contingency table
- Expected frequency in that cell under the assumption of independence
Degrees of freedom = (rows − 1) × (columns − 1). Large χ² indicates the observed frequencies deviate substantially from what independence predicts.
Calculate this for every cell before applying the χ² formula. Each expected count should generally be at least 5 for the test to be valid.