A contingency table is the basic tool for categorical data: it counts how many units fall into each combination of two (or more) categories. The row and column totals show how the data are distributed on each variable alone, while the inside counts show how the variables relate. Most categorical tests, from chi-square to Fisher's exact test, start from this table.
A reading plan, from raw counts to a cautious conclusion:
Anatomy of a 2 x 2 table. Two recipes are compared on $100$ wafers each, and every wafer either passes or fails:
| Recipe | Pass | Fail | Total | Fail rate |
|---|---|---|---|---|
| Old | $90$ | $10$ | $100$ | $10\%$ |
| New | $78$ | $22$ | $100$ | $22\%$ |
| Total | $168$ | $32$ | $200$ | $16\%$ |
Comparing rates within each row, rather than raw counts across rows, is what makes the table informative. With $a,b$ the old row's pass and fail counts and $c,d$ the new row's, three standard summaries describe the contrast:
Here $\mathrm{RD}=0.22-0.10=0.12$ (twelve percentage points more failures), $\mathrm{RR}=2.2$ (failures are 2.2 times as likely), and $\mathrm{OR}=(90\cdot22)/(10\cdot78)\approx2.54$. The odds ratio is not the risk ratio: they agree only when the outcome is rare, which is why reporting "2.5 times as likely" from an odds ratio overstates the risk here. Its standard confidence interval is computed on the log scale:
The standard error is $\sqrt{1/90+1/10+1/78+1/22}\approx0.412$, so the $95\%$ interval for the odds ratio is about $[1.13,\,5.69]$. It excludes $1$, so it agrees with the Pearson chi-square test, which gives $\chi^2=5.36$ on $1$ degree of freedom and $p=0.0206$. With counts this small in the fail column, Fisher's exact test gives a more cautious $p=0.0327$.
The trap: collapsing a table. A 2 x 2 table can hide a third variable. Suppose recipe A and recipe B are compared across two lot types, and the pass rates are:
Recipe A passes $18/20=90\%$ of easy lots against $85\%$ for B ($170/200$), and $100/200=50\%$ of hard lots against $30\%$ for B ($6/20$). A wins in both groups, yet pooled it loses, at $53.6\%$ against $80\%$. The reason is that A was given mostly hard lots and B mostly easy ones. This is Simpson's paradox: the pooled table mixes the effect of the recipe with the effect of lot difficulty. Stratify by every plausible hidden factor before accepting a pooled comparison, and use a stratified method such as the Cochran-Mantel-Haenszel test when you must combine strata.
Practical rules.
- Orient the table: put the explanatory variable (recipe, tool) in the rows and the outcome in the columns, so row percentages answer the question.
- Counts, not rates: keep raw counts. Percentages without their denominators cannot be tested or combined.
- Choose the test by size: chi-square needs expected counts of about $5$ or more in nearly every cell; otherwise use Fisher's exact test.
- Larger tables: an $r\times c$ table has $(r-1)(c-1)$ degrees of freedom; inspect Pearson residuals to see which cells drive a significant result.
- Association, not cause: a table of observational counts shows that variables move together, not why. Randomization or stratification is needed for a causal claim.
Read a contingency table as a map of who ended up where: compare within rows, report an effect size with its interval, and check for a hidden third variable before believing the pooled picture.