Skip to main content

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.

ByHoang TruongUpdated

FrameworkHypothesis testing

See it move

Loading infographic...

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.

Where it fits
SubjectData Analysis & StatisticsAdvancedTopicCommon Significance TestsAdvanced

The formula

LaTeX
χ2=(OE)2E\chi^2 = \sum \frac{(O - E)^2}{E}

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.

LaTeX
Expected count=Row total×Column totalGrand total\text{Expected count} = \frac{\text{Row total} \times \text{Column total}}{\text{Grand total}}

Calculate this for every cell before applying the χ² formula. Each expected count should generally be at least 5 for the test to be valid.

Chi-square test of independence — Edlintics Glossary