Contingency Tables and Tests of Independence
A grid that cross-tabulates two categorical variables, and the chi-squared test that checks whether the two are statistically independent or actually related.
Suppose you want to know whether an analyst's buy/hold/sell rating actually relates to whether the stock beat the market over the following quarter, or whether the two are unrelated. A contingency table just counts, for every combination of the two categories, how many observations fell into that cell — rating on one axis, outcome on the other — turning two categorical variables into a single grid of counts.
| Beat market | Underperformed | |
|---|---|---|
| Buy rating | 62 | 38 |
| Sell rating | 20 | 30 |
The chi-squared test of independence asks whether the pattern of counts you actually see is different enough from what you'd expect if the two variables had no relationship at all to conclude they're actually associated. The expected count under independence for each cell is , and the test statistic sums the squared, scaled gap between observed and expected counts across all cells:
In plain English: cells where the actual count is far from what independence would predict contribute more to the statistic, and a large enough (compared against a chi-squared distribution with degrees of freedom) means the deviation is unlikely to be due to chance alone, so independence is rejected — here, a buy rating and beating the market appear genuinely associated rather than coincidental.
A contingency table cross-tabulates two categorical variables into counts, and the chi-squared test of independence measures how far those counts sit from what pure chance (no relationship) would predict — a large statistic means the two variables are likely genuinely associated.
Practice in interviews
Further reading
- Wasserman, All of Statistics, ch. 14