Bivariate Categorical Data
Bivariate categorical data records two categorical variables for each individual, organized in a two-way (contingency) table. The key tools are joint, marginal, and conditional relative frequencies, which reveal whether the two variables are associated or independent. Used in surveys, medicine, market research, and the social sciences whenever two qualities (not numbers) are compared.
A single categorical variable tells you how a group is distributed. Two categorical variables let you ask the far richer question: does knowing one variable change the distribution of the other? If the conditional distributions of variable B are the same across every category of A, the variables are independent — A tells you nothing about B. If those distributions differ, the variables are associated. Everything in this topic is machinery for measuring and detecting that difference.
Formal Statement
A categorical variable assigns each individual to exactly one of a finite set of categories (levels). Categories may be:
- Nominal — unordered labels (e.g. blood type: A, B, AB, O).
- Ordinal — labels with a natural order (e.g. rating: poor, fair, good).
A bivariate categorical dataset records two such variables, and , for each of individuals.
Let have categories (the rows) and have categories (the columns). The cell count is the number of individuals with and . The table of all is the two-way table. Define the marginal totals and grand total:
Derivation hint: sums a row across all columns, sums a column across all rows; summing either set of margins recovers the grand total .
From the counts we form three families of proportions.
Joint relative frequency — fraction of all individuals in cell :
Derivation hint: divide each cell by the grand total; all joint frequencies sum to 1.
Marginal relative frequency — fraction in a single row or column overall:
Derivation hint: divide a marginal total by ; equivalently , summing a row of joint frequencies.
Conditional relative frequency — fraction within a fixed row (or column):
Derivation hint: restrict attention to the subgroup (its total is ), then take the share in column ; this rescales one row so it sums to 1.
Two categorical variables and are independent when every conditional distribution equals the corresponding marginal distribution. Equivalently, the joint frequency factors:
In count form, the expected count under independence is:
Derivation hint: substitute , , into [5] and solve for the expected count.
Why It Holds / Derivation
We show that [5] forces [6]. 1. Start from the factorization. Independence means — the probability of landing in cell is the product of being in row and being in column . 2. Convert proportions to counts. Multiply both sides by :
The left side is the cell count we would expect, call it . 3. Substitute the marginals. Using and :
4. Interpret. is the count we'd see if the row and column variables carried no information about each other. Comparing the observed to measures association: large gaps signal a relationship.
∎Karl Pearson, the founder of modern mathematical statistics, introduced the chi-squared test in 1900 precisely to compare observed counts in a contingency table to the expected counts of [6]. He also coined the term "contingency" for these tables (1904) and built much of the vocabulary — correlation, standard deviation, histogram — that students still use. His student-rival G. Udny Yule developed measures of association for tables in the same era.
Building Intuition
Picture a class of 100 students sorted into a grid: rows for wears glasses / doesn't, columns for plays a sport / doesn't. The joint frequencies are the four cell shares — the bird's-eye view. The marginals are the edge totals — what you'd know if you only asked one question. The conditional frequencies are what you get by walking into just the "glasses" row and asking of these people, what fraction play a sport? Association is simply this: if the glasses-wearers play sports at a different rate than the non-glasses-wearers, the two variables are linked. Independence is the boring case where every row looks like a shrunken copy of the overall column distribution. The whole subject is the discipline of conditioning — narrowing to a subgroup — and then comparing.
```svg
```
Worked Examples
Given. 200 people are asked whether they prefer coffee or tea, cross-classified by age group.
| Coffee | Tea | Row total | |
|---|---|---|---|
| Under 30 | 50 | 30 | 80 |
| 30 or over | 60 | 60 | 120 |
| Col total | 110 | 90 | 200 |
Question. Are age and beverage preference associated?
Steps. 1. Conditional distribution for Under 30: coffee , tea . 2. Conditional distribution for 30 or over: coffee , tea . 3. Compare: under-30s prefer coffee 62.5% of the time, older group only 50%. The conditional distributions differ. 4. Check against marginal coffee rate: . Neither row matches it.
Answer.
Given. The same table. Compute the expected count of Under 30 & Coffee under independence, then the contribution to the chi-squared statistic.
Steps. 1. Marginals: (Under 30), (Coffee), . 2. Expected count from [6]:
3. Observed was , so the deviation is . 4. Chi-squared contribution of this cell,
Answer.
The observed count exceeds the independence prediction, consistent with the association found in Example 1.
Common Misconceptions
Conditional ≠ joint ≠ marginal — and the denominator is everything.
- A joint frequency divides by the grand total .
- A conditional frequency divides by a single row or column total.
- Saying "40% of glasses-wearers play sport" (conditional, ) is utterly different from "12% of all students wear glasses and play sport" (joint, ).
Also: (column given row ) and (row given column ) are not interchangeable. The fraction of doctors who are women is not the fraction of women who are doctors. Confusing these two directions is one of the most common — and consequential — statistical errors.
Association can reverse when groups are combined. Consider two hospitals' survival rates: Severe patients: Hospital A saves 30/100 = 30%, Hospital B saves 10/50 = 20%. A is better. Mild patients: Hospital A saves 100/100 = 100%(say 90/100=90%), Hospital B saves 180/200 = 90%. Tie or A leads. Yet combined, Hospital B can show a higher overall survival rate, because B treats mostly mild patients while A treats mostly severe ones. A is superior within each category but inferior in the lumped totals. This proves that a marginal (overall) comparison can flatly contradict every conditional comparison — a vivid warning against ignoring a third variable. See Simpson's Paradox.
Connections
Bivariate categorical data sits at a crossroads of statistics:
- It extends Univariate Categorical Data (one variable, a single bar chart) into a relational setting.
- The independence check of [6] is the engine of the Chi-Squared Test of Independence, which turns the cell deviations into a single test statistic and p-value.
- The conditional frequencies of [4] are the empirical face of Conditional Probability; equation [5] is exactly the multiplication rule for independent events.
- For two numerical variables, the analogous study is Scatterplots and Correlation — association measured by direction and strength rather than by table comparison.
- Measures like the odds ratio and relative risk quantify association, linking to Risk and Odds.
Real-World Applications
Historical Development
Subtleties & Limits
Detecting association is easy; explaining it is hard. A two-way table can show a strong, statistically significant association that is entirely due to a hidden confounding variable — Simpson's Paradox is the dramatic case, but subtler confounding pervades observational data. There is no purely mathematical rule that tells you which variables to condition on; that requires causal reasoning beyond the table itself. Modern causal inference (Pearl's directed graphs, potential-outcomes frameworks) attempts to formalize when conditioning reveals versus distorts a true relationship, but choosing the right adjustment set in real studies remains a deep, partly unsolved problem. Likewise, chi-squared tests assume adequate expected counts and independent sampling — conditions easily violated in practice.
See Also
Univariate Categorical Data · Conditional Probability · Chi-Squared Test of Independence · Simpson's Paradox · Scatterplots and Correlation · Risk and Odds