Mathwords logoMathwords

Contingency Table — Definition, Formula & Examples

A contingency table is a grid that shows how many observations fall into each combination of two categorical variables. Each cell contains a count (or frequency), and the rows and columns represent the categories of each variable.

A contingency table (also called a two-way frequency table) is a rectangular array in which the entries represent the joint frequencies of two categorical variables, with row totals and column totals (marginal frequencies) summarizing the distribution of each variable individually.

How It Works

Place one categorical variable along the rows and the other along the columns. Each cell records the count of observations that belong to that particular row-and-column combination. Add a "Total" row at the bottom and a "Total" column on the right to show marginal frequencies. You can then compute joint, marginal, or conditional relative frequencies by dividing cell counts by the appropriate total. Comparing conditional relative frequencies across rows or columns helps you judge whether the two variables are associated.

Worked Example

Problem: A survey of 200 students asks whether they prefer cats or dogs and whether they are in 9th or 10th grade. Results: 9th graders — 50 prefer cats, 30 prefer dogs; 10th graders — 40 prefer cats, 80 prefer dogs. Organize this data in a contingency table and find the conditional relative frequency of preferring cats given that the student is in 10th grade.
Build the table: Rows = grade, Columns = pet preference. Fill in each cell and compute totals.
CatsDogsTotal9th50308010th4080120Total90110200\begin{array}{l|cc|c} & \text{Cats} & \text{Dogs} & \text{Total} \\ \hline \text{9th} & 50 & 30 & 80 \\ \text{10th} & 40 & 80 & 120 \\ \hline \text{Total} & 90 & 110 & 200 \end{array}
Find the conditional relative frequency: Divide the number of 10th graders who prefer cats by the total number of 10th graders.
P(Cats10th)=40120=130.333P(\text{Cats} \mid \text{10th}) = \frac{40}{120} = \frac{1}{3} \approx 0.333
Answer: About 33.3% of 10th graders prefer cats.

Why It Matters

Contingency tables are central to AP Statistics and introductory college courses whenever you analyze the relationship between two categorical variables. They form the basis for the chi-square test of independence, one of the most widely used hypothesis tests in fields from medicine to marketing.

Common Mistakes

Mistake: Confusing joint and conditional relative frequencies by dividing a cell count by the grand total when the question asks about a specific subgroup.
Correction: For a conditional relative frequency, divide the cell count by the row total or column total that matches the given condition, not the grand total.