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.

Bivariate categorical data consists of paired observations of two categorical (qualitative) variables — variables whose values are labels or categories rather than measurements, such as eye colour and handedness, or treatment group and survival. The data are summarized in a two-way table of counts, from which we compute proportions to compare groups. This matters because much real-world data — survey responses, medical outcomes, voting patterns — is categorical, and the central scientific question is almost always "are these two things related?" A surprising fact: two variables can appear positively associated within every subgroup yet reversed in the combined data, a phenomenon called Simpson's Paradox.

The Core Insight

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

Categorical Variable

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.

Two-Way (Contingency) Table

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:

1
⟳ sums a row across all columns, sums a column across all rows; summing either set of margins recovers the grand total .

Joint, Marginal, and Conditional Relative Frequencies

From the counts we form three families of proportions.

Joint relative frequency — fraction of all individuals in cell :
2
⟳divide each cell by the grand total; all joint frequencies sum to 1.
Marginal relative frequency — fraction in a single row or column overall:
3
⟳divide a marginal total by ; equivalently , summing a row of joint frequencies.
Conditional relative frequency — fraction within a fixed row (or column):
4
⟳restrict attention to the subgroup (its total is ), then take the share in column ; this rescales one row so it sums to 1.

Independence Condition

Two categorical variables and are independent when every conditional distribution equals the corresponding marginal distribution. Equivalently, the joint frequency factors:

5

In count form, the expected count under independence is:

6
⟳substitute , , into [5] and solve for the expected count.

Why It Holds / Derivation

From Independence to Expected Counts

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 .
  1. Convert proportions to counts. Multiply both sides by :
The left side is the cell count we would expect, call it .
  1. Substitute the marginals. Using and :
  1. 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 | 1857–1936

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.

A two-way table with marginals; conditioning means reading along one row.

<svg viewBox="0 0 460 320" xmlns="http://www.w3.org/2000/svg">
<rect width="460" height="320" fill="#0a0e17"/>
<text x="230" y="28" fill="#e2e8f0" font-size="16" text-anchor="middle" font-family="sans-serif">Glasses × Sport (n = 100)</text>

<!-- grid -->
<line x1="80" y1="60" x2="380" y2="60" stroke="#94a3b8" stroke-width="1.5"/>
<line x1="80" y1="120" x2="380" y2="120" stroke="#94a3b8" stroke-width="1.5"/>
<line x1="80" y1="180" x2="380" y2="180" stroke="#94a3b8" stroke-width="1.5"/>
<line x1="80" y1="60" x2="80" y2="180" stroke="#94a3b8" stroke-width="1.5"/>
<line x1="200" y1="60" x2="200" y2="180" stroke="#94a3b8" stroke-width="1.5"/>
<line x1="320" y1="60" x2="320" y2="180" stroke="#94a3b8" stroke-width="1.5"/>

<!-- column headers -->
<text x="140" y="52" fill="#e2e8f0" font-size="13" text-anchor="middle" font-family="sans-serif">Sport</text>
<text x="260" y="52" fill="#e2e8f0" font-size="13" text-anchor="middle" font-family="sans-serif">No Sport</text>
<text x="350" y="52" fill="#94a3b8" font-size="13" text-anchor="middle" font-family="sans-serif">Total</text>

<!-- row headers -->
<text x="40" y="94" fill="#e2e8f0" font-size="13" text-anchor="middle" font-family="sans-serif">Glasses</text>
<text x="40" y="154" fill="#e2e8f0" font-size="13" text-anchor="middle" font-family="sans-serif">None</text>

<!-- highlighted conditioning row -->
<rect x="80" y="60" width="240" height="60" fill="#d4a853" opacity="0.15"/>

<!-- cell counts -->
<text x="140" y="94" fill="#d4a853" font-size="15" text-anchor="middle" font-family="sans-serif">12</text>
<text x="260" y="94" fill="#d4a853" font-size="15" text-anchor="middle" font-family="sans-serif">18</text>
<text x="140" y="154" fill="#e2e8f0" font-size="15" text-anchor="middle" font-family="sans-serif">28</text>
<text x="260" y="154" fill="#e2e8f0" font-size="15" text-anchor="middle" font-family="sans-serif">42</text>

<!-- margins -->
<text x="350" y="94" fill="#94a3b8" font-size="14" text-anchor="middle" font-family="sans-serif">30</text>
<text x="350" y="154" fill="#94a3b8" font-size="14" text-anchor="middle" font-family="sans-serif">70</text>
<text x="140" y="205" fill="#94a3b8" font-size="14" text-anchor="middle" font-family="sans-serif">40</text>
<text x="260" y="205" fill="#94a3b8" font-size="14" text-anchor="middle" font-family="sans-serif">60</text>
<text x="350" y="205" fill="#94a3b8" font-size="14" text-anchor="middle" font-family="sans-serif">100</text>

<text x="230" y="250" fill="#d4a853" font-size="13" text-anchor="middle" font-family="sans-serif">Condition on "Glasses": 12/30 = 40% play sport</text>
<text x="230" y="275" fill="#94a3b8" font-size="13" text-anchor="middle" font-family="sans-serif">Marginal: 40/100 = 40% play sport overall</text>
<text x="230" y="298" fill="#e2e8f0" font-size="12" text-anchor="middle" font-family="sans-serif">Equal rates here ⇒ no association in this row</text>
</svg>

Worked Examples

Association in a Survey

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.

Testing Independence via Expected Counts

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]:
  1. Observed was , so the deviation is .
  2. 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.

Simpson's Paradox

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

  1. Clinical trials. Treatment (drug/placebo) × outcome (recovered/not) in a table; the odds ratio measures efficacy.
  2. Epidemiology. Smoking status × lung cancer — Doll & Hill's 1950 study was built on exactly such tables.
  3. Market research. Customer segment × product preference, to target advertising.
  4. A/B testing in tech. Website version (A/B) × conversion (bought/didn't), evaluated with a chi-squared test.
  5. Election polling. Region or age bracket × candidate choice, to detect demographic voting blocs.
  6. Quality control. Production line × defect type, to localize manufacturing faults.
  7. Genetics. Mendelian crosses tabulate genotype × phenotype, the original use of Pearson's goodness-of-fit reasoning.

Historical Development

  • 1865 — Gregor Mendel publishes pea-plant ratios, implicitly cross-classifying traits in tables.
  • 1888 — Francis Galton formalizes "co-relation," priming the idea of measuring association.
  • 1900 — Karl Pearson introduces the chi-squared test, comparing observed to expected cell counts.
  • 1904 — Pearson coins the term contingency table and proposes the contingency coefficient.
  • 1900s–1910s — G. Udny Yule develops the odds ratio and coefficient for tables.
  • 1922 — R. A. Fisher corrects the degrees of freedom for contingency tables, refining Pearson's test.
  • 1934 — Fisher devises the exact test for small tables (the famous "lady tasting tea").
  • 1951 — E. H. Simpson formally describes the reversal paradox now bearing his name.
  • 1970s onward — Log-linear models (Bishop, Fienberg, Holland) generalize two-way tables to high-dimensional categorical analysis.

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

Before this

Where this leads