# Contingency tables
Contingency tables are a graphical method for displaying discrete data across several strata. In an study context, the convention is that the different values of the independent variable form the rows, while the values of the dependent variable form the columns.
For example, for a placebo-controlled vaccine trial for COVID-19, we might get the following $2\times2$ contingency table:
| | COVID-19 | No COVID-19 |
| ------- | -------- | ----------- |
| Vaccine | 52 | 150,183 |
| Placebo | 168 | 148,519 |
Another convention is to place the marginal totals of each row and column at the end:
| | COVID-19 | No COVID-19 | Row Total |
| ------------ | -------- | ----------- | --------- |
| Vaccine | 52 | 150,183 | 150,235 |
| Placebo | 168 | 148,519 | 148,687 |
| Column Total | 220 | 298692 | 298,912 |
The total in the bottom right corner indicates how many ([[Independent and Identically Distributed (IID) Assumption|iid]]) samples were collected and is considered to be fixed after an experiment is done.
From a statistical model, the counts of the individual cells are considered to be random. This can be modeled with a multinomial distribution. The probability that someone falls within cell $(i,j)$ is denoted as $\pi_{ij}$.
| | COVID-19 | No COVID-19 | Row Total |
| ------------ | ---------- | ----------- | ---------- |
| Vaccine | $\pi_{11}$ | $\pi_{12}$ | $\pi_{1.}$ |
| Placebo | $\pi_{21}$ | $\pi_{22}$ | $\pi_{2.}$ |
| Column Total | $\pi_{.1}$ | $\pi_{.2}$ | $\pi_{..}$ |
Contingency tables can easily be extended to have multiple rows and columns if the corresponding variables have multiple categories.
Contingency tables themselves are just a way to *organize* data; the corresponding hypothesis test for them is the [[Chi-squared test of independence|chi-squared test]]. If there is a lot of data, we may appeal to a Wald-type interval for the difference in group proportions.
For matched pair binary data, consult [[McNemar's Test]].
---
# References
- [[Categorical Data Analysis#Chapter 2 - Describing Contingency Tables]]