AP Statistics • Exploring Two-Variable Data

Statistics for Two Categorical Variables

Discover how two-way tables, conditional distributions, and association analysis reveal hidden relationships between categorical variables.

A scatter plot with data columns and a percentage symbol.
Inside this lesson 10 sections 5 questions 9 figures

SECTION 1

Historical Context & Motivation

The analysis of categorical data has deep roots in the history of statistics, arising from a fundamental need to understand relationships that cannot be captured by numerical measurements alone. When researchers want to know whether a new medical treatment is associated with patient recovery, or whether political preference varies by geographic region, they are working with categorical variables — variables whose values represent group memberships or qualitative labels rather than ordered numerical quantities. The development of rigorous methods for cross-classifying such variables and testing for association between them transformed fields ranging from epidemiology to social science, enabling researchers to move beyond anecdotal evidence toward data-driven conclusions.

1900 • Pearson's Chi-Square Test

Karl Pearson introduced the chi-square goodness-of-fit test, providing the first formal method for comparing observed categorical frequencies to theoretical expectations. This laid the groundwork for all modern two-way table analysis.

1922 • Fisher and Contingency Tables

Ronald A. Fisher developed the exact test for 2 × 2 contingency tables — now known as Fisher's exact test — which enabled hypothesis testing in small samples where Pearson's chi-square approximation was unreliable.

1950s • Simpson's Paradox Formalized

Edward Simpson formally described the paradox in which an association between two categorical variables reverses direction when a lurking variable is introduced, underscoring the critical importance of examining conditional distributions.

1977 • Exploratory Data Analysis Movement

John Tukey's emphasis on graphical exploration spurred the widespread adoption of mosaic plots and segmented bar charts for visualizing two-way tables, making patterns in categorical data more accessible to practitioners.

The central question that this topic addresses is deceptively simple: Is there a relationship between two categorical variables, or are they independent? Answering this question requires organizing data into a structured format, computing appropriate proportions, and interpreting patterns in a way that distinguishes genuine association from coincidence. These skills form a core component of the AP Statistics curriculum and appear repeatedly in both multiple-choice and free-response sections of the exam.

SECTION 2

Core Principles & Definitions

Before diving into computations, it is essential to establish a precise vocabulary. A two-way table (also called a contingency table) cross-classifies individuals according to two categorical variables simultaneously — one variable defines the rows and the other defines the columns. Each cell in the table contains a count (or frequency) of individuals who belong to the corresponding combination of categories. The row and column totals, often called marginal frequencies, summarize the overall distribution of each variable, while the individual cell counts are the joint frequencies.

1

Marginal Distribution

The distribution of one categorical variable alone, obtained by examining the row totals or column totals of a two-way table. It ignores the other variable entirely and answers questions like 'What proportion of all subjects preferred Brand A?'
2

Joint Distribution

The distribution of the combination of both categorical variables, computed by dividing each cell count by the grand total. It tells us the proportion of all individuals who fall into each specific row-column combination.
3

Conditional Distribution

The distribution of one variable given a fixed value of the other. For example, 'Among females only, what proportion preferred each brand?' These are the proportions within a single row or column, and they are the key to detecting association.
4

Association vs. Independence

Two categorical variables are associated if the conditional distributions of one variable differ across the categories of the other. They are independent if the conditional distributions are approximately equal — knowing one variable tells you nothing about the other.
✦

KEY TAKEAWAY

Think of a two-way table as a spreadsheet with a grid of mailboxes at a post office. Each mailbox (cell) collects letters addressed to a specific combination of street and zip code. The marginal distribution is the total mail for each street regardless of zip code. The conditional distribution asks: of all the letters sent to zip code 90210, what fraction went to each street? If that fraction looks the same no matter which zip code you pick, then street and zip are independent. If one zip code disproportionately serves one street, the variables are associated.

SECTION 3

Visual Explanation — Reading a Two-Way Table

The most natural visual representation of categorical cross-classification is the two-way table itself, augmented with marginal totals. The diagram below shows a survey of 400 college students classified by class year (Freshman, Sophomore, Junior, Senior) and preferred study location (Library, Dorm Room, Coffee Shop). Study the structure carefully: the joint frequencies fill the interior cells, the marginal frequencies appear along the right edge and bottom edge, and the grand total sits in the lower-right corner.

Two-Way Table: Class Year × Study Location (n = 400)Class YearLibraryDorm RoomCoffee ShopRow TotalFreshman305020100Sophomore354025100Junior453025100Senior502030100Column Total160140100400Joint frequencies (interior cells)Marginal frequencies (edges)Grand total
A complete two-way table for a sample of 400 students. Interior cell values are joint frequencies; the right column and bottom row contain marginal frequencies. The grand total (400) appears at the intersection of the two marginal rows.

Notice that each row total (100 for every class year in this balanced example) is obtained by summing across the three study-location cells in that row. Likewise, each column total (160 for Library, 140 for Dorm Room, 100 for Coffee Shop) is the sum of the four class-year cells in that column. The grand total, 400, can be computed either by summing the row totals or the column totals — a useful consistency check. When you convert joint frequencies to proportions by dividing each cell by 400, you obtain the joint relative frequency distribution; when you divide each cell by its row total, you obtain the conditional distribution of study location given class year. These conditional distributions are the primary tool for assessing association.

SECTION 4

Mathematical Framework

Three types of proportions arise from a two-way table, and distinguishing among them is essential for accurate interpretation. Let nij denote the count in row i and column j, let ni• denote the total for row i, let n•j denote the total for column j, and let n denote the grand total.

JOINT RELATIVE FREQUENCY

p^(rowiandcolumnj)=nij/np̂(row i and column j) = n_ij / n

Dividing a cell count by the grand total gives the proportion of all individuals who fall in that particular cell. The sum of all joint relative frequencies equals 1.

MARGINAL RELATIVE FREQUENCY

p^(rowi)=ni•/nandp^(columnj)=n•j/np̂(row i) = n_i• / n and p̂(column j) = n_•j / n

Dividing a row total or column total by the grand total gives the overall proportion of individuals in that category. These proportions describe each variable separately.

CONDITIONAL RELATIVE FREQUENCY

p^(columnj∣rowi)=nij/ni•p̂(column j | row i) = n_ij / n_i•

Dividing a cell count by its row total gives the proportion of individuals in row i who are in column j. Analogously, dividing by the column total yields p̂(row i | column j).

EXPECTED COUNT UNDER INDEPENDENCE

Eij=(ni•×n•j)/nE_ij = (n_i• × n_•j) / n

If two variables were truly independent, the expected count in cell (i, j) would equal the row total times the column total divided by the grand total. Comparing observed and expected counts is the basis of the chi-square test, which is studied in greater depth later in the course.

The distinction between joint, marginal, and conditional proportions is a frequent source of error on the AP exam. A common mistake is to compute a conditional proportion but divide by the grand total instead of the appropriate row or column total. Always ask yourself: what group am I conditioning on? The denominator of a conditional proportion is always the size of that conditioning group, not the size of the entire sample.

SECTION 5

Conditional Distributions & Segmented Bar Charts

The most powerful way to investigate whether two categorical variables are associated is to compare conditional distributions side by side. If the conditional distribution of the column variable looks roughly the same across every row, the variables appear independent. If the distributions differ noticeably, there is evidence of an association. A segmented (stacked) bar chart is the standard graphical tool for this comparison: each bar represents one category of the explanatory variable and is divided into colored segments whose lengths correspond to the conditional proportions of the response variable.

Segmented Bar Chart: Conditional Distribution of Study Location by Class YearProportionClass Year0.00.20.40.60.81.00.300.500.20Fresh.0.350.400.25Soph.0.450.300.25Junior0.500.200.30SeniorLibraryDorm RoomCoffee Shop
Each bar represents a class year and sums to 1.0. The varying segment heights across bars reveal that the conditional distribution of study location differs by class year — for instance, Library use (cyan) increases from 0.30 among Freshmen to 0.50 among Seniors, suggesting an association between class year and study location preference.

The chart above makes the association visually striking. If class year and study location were independent, every bar would have identical segment proportions — the cyan, violet, and pink bands would be at the same heights across all four bars. Instead, the Library segment grows steadily from Freshman (0.30) to Senior (0.50), while the Dorm Room segment shrinks from 0.50 to 0.20. The Coffee Shop segment fluctuates modestly. These differing conditional distributions provide strong descriptive evidence of association. On the AP exam, a segmented bar chart is the preferred graphic for displaying conditional distributions, and your written interpretation should always explicitly compare the conditional proportions across groups.

💡

AP EXAM TIP

When asked to describe association in a two-way table, always cite specific numerical proportions from the conditional distributions. A statement like 'the conditional distributions differ' is insufficient without supporting values. For example: 'Among Seniors, 50% prefer the Library compared to only 30% of Freshmen, suggesting that preference for the Library increases with class year.'

SECTION 6

Worked Example

A researcher surveyed 500 adults and classified each by exercise frequency (Regular or Irregular) and health self-rating (Excellent, Good, Fair). The two-way table is shown below. Determine the conditional distribution of health self-rating for each exercise group, and assess whether the data suggest an association between exercise frequency and health self-rating.

ExcellentGoodFairTotal
Regular9012040250
Irregular30100120250
Total120220160500

Exercise Frequency × Health Self-Rating (n = 500)

Computing & Comparing Conditional Distributions

  1. 1

    Step 1 — Identify the conditioning variable

    We want the conditional distribution of health self-rating given exercise frequency. This means we condition on the rows. Each row total (250 for Regular, 250 for Irregular) will serve as the denominator.
  2. 2

    Step 2 — Compute conditional proportions for Regular exercisers

    P̂(Excellent | Regular) = 90 / 250 = 0.36, P̂(Good | Regular) = 120 / 250 = 0.48, P̂(Fair | Regular) = 40 / 250 = 0.16. Note that these three proportions sum to 1.00.
    Regular: 0.36 Excellent, 0.48 Good, 0.16 Fair
  3. 3

    Step 3 — Compute conditional proportions for Irregular exercisers

    P̂(Excellent | Irregular) = 30 / 250 = 0.12, P̂(Good | Irregular) = 100 / 250 = 0.40, P̂(Fair | Irregular) = 120 / 250 = 0.48. Again, these sum to 1.00.
    Irregular: 0.12 Excellent, 0.40 Good, 0.48 Fair
  4. 4

    Step 4 — Compare and interpret

    The conditional distributions differ substantially. Among Regular exercisers, 36% rated their health as Excellent, compared to only 12% of Irregular exercisers. Conversely, only 16% of Regular exercisers rated their health as Fair, compared to 48% of Irregular exercisers. Because the conditional distributions of health self-rating differ markedly between the two exercise groups, the data suggest an association between exercise frequency and health self-rating. Regular exercisers tend to report higher health ratings.
    Conclusion: There is an association. However, because this is an observational study, we cannot conclude that exercise causes better health self-ratings.

SECTION 7

Strengths, Limitations & Common Pitfalls

AspectStrengthLimitation / Pitfall
SimplicityTwo-way tables are easy to construct and interpret, requiring no assumptions about distributions.They can become unwieldy when one or both variables have many categories, making patterns hard to spot.
Detecting AssociationComparing conditional distributions provides a clear, intuitive method for identifying association.Descriptive comparison alone cannot quantify the strength of association or determine statistical significance.
CausationThe table correctly displays the data, allowing the reader to see what the evidence shows.Association ≠ causation. Lurking or confounding variables may explain an apparent relationship.
Simpson's ParadoxAwareness of this paradox encourages analysts to stratify data by potential confounders.Aggregated data can reverse the direction of an association when a lurking variable is ignored.
Graphical DisplaySegmented bar charts and mosaic plots make conditional distributions visually comparable.Choosing the wrong denominator (joint instead of conditional) can produce misleading charts.

Strengths and limitations of two-way table analysis

⚠

SIMPSON'S PARADOX WARNING

Imagine two hospitals both treat heart patients. Hospital A has a higher overall survival rate than Hospital B. But when you separate patients by severity (mild vs. critical), Hospital B has a higher survival rate in both severity groups. This reversal — Simpson's Paradox — happens because Hospital B receives a disproportionate number of critical cases, pulling its overall rate down. The lesson: always consider whether a lurking variable should be used to stratify your two-way table before drawing conclusions.

SECTION 8

Connection to the Chi-Square Test & Beyond

The descriptive techniques covered in this lesson — constructing two-way tables, computing conditional distributions, and identifying association through graphical comparison — are foundational. Later in the AP Statistics course, you will formalize the assessment of association using the chi-square test for independence (or for homogeneity, depending on the study design). That inferential procedure uses the expected counts under independence (Eij = ni• × n•j / n) and compares them to the observed counts via a test statistic that follows an approximate chi-square distribution.

FeatureDescriptive Analysis (This Lesson)Chi-Square Inference (Later)
GoalDescribe and visualize patterns in the sample dataDetermine whether observed association is statistically significant
MethodConditional proportions, segmented bar chartsχ² test statistic, p-value, degrees of freedom
Conclusion typeAssociation appears to exist (or not) based on descriptive evidenceReject or fail to reject H₀ of independence at a specified significance level
PrerequisitesNone beyond data organizationRandom sampling/assignment, expected counts ≥ 5

Descriptive vs. inferential analysis of two categorical variables

The descriptive skills from this lesson are not rendered obsolete by inferential methods; rather, they remain an indispensable first step. On the AP exam, free-response questions about two categorical variables almost always require students to compute and compare conditional distributions before (or even instead of) performing a formal hypothesis test. A thorough descriptive analysis also helps you understand how the variables are associated — something a p-value alone cannot tell you.

SECTION 9

Practice Problems

Question 1: CONCEPTUAL

A researcher constructs a two-way table of gender (Male, Female) and pet preference (Dog, Cat, Fish). Which of the following best describes what it means for gender and pet preference to be independent?
  • A. The number of males who prefer dogs equals the number of females who prefer dogs.
  • B. The joint relative frequency of each cell equals zero.
  • C. The conditional distribution of pet preference is the same for males and females.
  • D. The marginal distribution of gender is the same as the marginal distribution of pet preference.
  • E. Each cell count is exactly equal to every other cell count.
Show answer (C)
C is correct. Independence between two categorical variables means that knowing the value of one variable provides no information about the distribution of the other. Formally, this is expressed as the conditional distribution of pet preference being identical across males and females. Choice A is incorrect because equal counts do not imply equal proportions when the row totals differ. Choice B is incorrect because joint relative frequencies of zero would mean no observations exist. Choice D is incorrect because marginal distributions of different variables need not be equal for independence to hold — independence is about conditional distributions, not marginal ones. Choice E is incorrect because uniform cell counts do not represent independence unless row and column totals happen to be equal.

Question 2: BASIC CALCULATION

In a survey of 600 people, 240 are Employed and 360 are Unemployed. Among Employed respondents, 180 support Policy X and 60 oppose it. Among Unemployed respondents, 120 support Policy X and 240 oppose it. What is the conditional proportion of support for Policy X among the Unemployed?
  • A. 0.20
  • B. 1/3 ≈ 0.333
  • C. 0.40
  • D. 0.50
  • E. 0.60
Show answer (B)
B is correct. The conditional proportion of support for Policy X among the Unemployed is calculated by dividing the number of Unemployed supporters by the total number of Unemployed respondents: 120 / 360 = 1/3 ≈ 0.333. Choice A (0.20) results from dividing 120 by 600, which gives the joint relative frequency, not the conditional proportion. Choice C (0.40) has no straightforward derivation from these data. Choice D (0.50) results from dividing 120 by 240, erroneously using the Employed total as the denominator. Choice E (0.60) confuses the Employed conditional proportion (180/240 = 0.75 is not 0.60 either) and does not correspond to any valid computation.

Question 3: INTERMEDIATE

A school district surveyed 800 students. The two-way table below shows transportation method by school level. Elementary: Bus 150, Car 90, Walk 60 (Total 300) Middle: Bus 100, Car 80, Walk 70 (Total 250) High: Bus 50, Car 120, Walk 80 (Total 250) Column totals: Bus 300, Car 290, Walk 210, Grand total 800 Which of the following statements is best supported by the data?
  • A. There is no association because bus is the most common transportation method at every school level.
  • B. There is an association because 50% of Elementary students ride the bus compared to only 20% of High school students.
  • C. The variables are independent because each school level has exactly three transportation options.
  • D. The marginal distribution shows that walking is equally popular at all levels.
  • E. There is an association because the grand total (800) is not evenly divisible by the number of cells (9).
Show answer (B)
B is correct. To assess association, we compare the conditional distributions of transportation method across school levels. For Elementary: Bus = 150/300 = 0.50, Car = 0.30, Walk = 0.20. For High school: Bus = 50/250 = 0.20, Car = 120/250 = 0.48, Walk = 80/250 = 0.32. The conditional distributions differ markedly — bus usage drops from 50% to 20% while car usage rises from 30% to 48% — establishing an association. Choice A is incorrect because association is determined by comparing proportions, not by identifying the most popular category; moreover, bus is not the most common at the High level (car is). Choice C is incorrect because having the same number of column categories has nothing to do with independence. Choice D is incorrect because the marginal distribution is a single set of totals; the conditional proportions for walking differ across levels (0.20, 0.28, 0.32). Choice E is incorrect because the divisibility of the grand total has no bearing on independence.

Question 4: APPLIED

4 pts
A pharmaceutical company tests two drug formulations (Standard and New) on 500 patients and records the outcome (Improved, No Change, Worsened). The data are: Standard (n = 250): Improved 100, No Change 110, Worsened 40 New (n = 250): Improved 140, No Change 85, Worsened 25 (a) Construct a table showing the conditional distribution of outcome for each formulation. (b) Create a complete comparison of the conditional distributions and determine whether the data suggest an association between formulation and outcome. (c) A skeptic argues that the patients receiving the New formulation were younger on average. Explain how this could affect your conclusion. (d) Describe the type of graphical display that would best communicate your findings and explain what to look for in it.
Show answer
Point 1 — Correct conditional distributions (1 point): Standard: Improved 100/250 = 0.40, No Change 110/250 = 0.44, Worsened 40/250 = 0.16. New: Improved 140/250 = 0.56, No Change 85/250 = 0.34, Worsened 25/250 = 0.10. Each row sums to 1.00. Point 2 — Comparison and association conclusion (1 point): The conditional distributions differ between the two formulations. The New formulation has a substantially higher proportion of patients who Improved (0.56 vs. 0.40) and a lower proportion who Worsened (0.10 vs. 0.16). The No Change proportion also decreased (0.34 vs. 0.44). Because the conditional distributions of outcome differ between the two formulations, there is evidence of an association between drug formulation and patient outcome. Point 3 — Confounding / lurking variable explanation (1 point): If patients receiving the New formulation were younger on average, then age is a lurking (potentially confounding) variable. Younger patients may naturally recover more quickly regardless of the drug formulation, so the apparent superiority of the New formulation could be partly or entirely due to the age difference rather than the formulation itself. This is a scenario where Simpson's Paradox could arise: stratifying the data by age group might reveal a weaker association, no association, or even a reversed association. Because this is an observational comparison without random assignment to treatment groups, a causal conclusion that the New formulation is superior is not justified. Point 4 — Appropriate graphical display (1 point): A segmented (stacked) bar chart with one bar per formulation, where each bar is divided into segments representing the proportion of patients in each outcome category, would best communicate the conditional distributions. To assess association, one should examine whether the segment proportions are roughly equal across the two bars (which would suggest independence) or noticeably different (which would suggest association). A side-by-side bar chart with grouped bars for each outcome category would also be acceptable. In this case, the Improved segment should be visibly larger for the New formulation bar, and the Worsened segment should be visibly smaller, reflecting the differences in conditional distributions identified in part (b).

Question 5: CRITICAL THINKING

4 pts
A university admissions office reports the following acceptance data: Overall: Program A accepted 50% of applicants; Program B accepted 42.5% of applicants. But when broken down by gender: • Male applicants: Program A accepted 60% (480 out of 800); Program B accepted 65% (65 out of 100). • Female applicants: Program A accepted 10% (20 out of 200); Program B accepted 40% (360 out of 900). (a) Verify the overall acceptance rates reported by the admissions office. (b) Explain in detail how Simpson's Paradox manifests in these data. Identify the lurking variable and explain its role. (c) Which set of rates — the overall rates or the gender-specific rates — provides a more accurate picture of the programs' acceptance practices? Justify your reasoning. (d) Propose a study design modification that would prevent this paradox from arising.
Show answer
Point 1 — Verification of overall rates (1 point): Program A total applicants: 800 + 200 = 1000; accepted: 480 + 20 = 500; overall rate: 500/1000 = 50%. Program B total applicants: 100 + 900 = 1000; accepted: 65 + 360 = 425; overall rate: 425/1000 = 42.5%. These match the reported overall rates: Program A accepted 50% and Program B accepted 42.5%. Students earn this point by computing correct overall rates from the given cell counts and confirming they match the reported values. Point 2 — Explanation of Simpson's Paradox (1 point): Simpson's Paradox occurs here because the overall rates suggest Program A is more selective (higher acceptance rate) than Program B, yet within each gender subgroup, Program B has a higher acceptance rate than Program A. For males: Program B accepts 65% vs. Program A's 60%. For females: Program B accepts 40% vs. Program A's 10%. The lurking variable is the gender composition of each program's applicant pool. Program A receives mostly male applicants (800 out of 1000), and males have a relatively high acceptance rate, which inflates Program A's overall rate. Program B receives mostly female applicants (900 out of 1000), and females have lower acceptance rates in both programs, which pulls Program B's overall rate down. The unequal distribution of the lurking variable (gender) across programs causes the aggregated rates to reverse the within-group pattern. Point 3 — Which rates are more informative (1 point): The gender-specific (conditional) rates provide a more accurate picture because they control for the confounding variable. Program B has a higher acceptance rate for both males (65% vs. 60%) and females (40% vs. 10%). The overall rates are misleading because they combine subgroups of vastly different sizes. Program A's overall rate is boosted by having most of its applicants from the higher-acceptance male subgroup, while Program B's overall rate is suppressed by drawing mostly from the lower-acceptance female subgroup. For any individual applicant, the relevant comparison is within their own gender group, making the conditional distributions more informative than the aggregated marginal rates. Point 4 — Study design modification (1 point): To prevent Simpson's Paradox from distorting comparisons, the university could ensure that the gender composition of applicant pools is balanced across programs — for instance, by using stratified analysis that reports acceptance rates separately for each gender group. Alternatively, the university could standardize the comparison by weighting each program's gender-specific rates by a common gender distribution (e.g., the overall proportion of male and female applicants across both programs combined). If a randomized experiment is feasible, random assignment of applicants to evaluation processes would tend to equalize confounding variables across groups. At minimum, always reporting stratified results by gender (and other relevant demographics) rather than only aggregated overall rates prevents the paradox from misleading decision-makers.

SUMMARY

Summary

Summary

Analyzing the relationship between two categorical variables begins with organizing data into a two-way table (contingency table) that displays joint frequencies in the interior cells and marginal frequencies along the edges. The marginal distribution of a single variable is obtained by dividing its marginal frequencies by the grand total, while the conditional distribution of one variable given a specific value of the other is obtained by dividing cell counts by the appropriate row or column total.

Two variables exhibit association when their conditional distributions differ across categories; they are independent when the conditional distributions are approximately equal. Segmented bar charts are the preferred graphical tool for comparing conditional distributions side by side. Always cite specific proportions when describing association, always use the correct denominator (the conditioning group's total), and always remain vigilant for Simpson's Paradox — a reversal of association that occurs when a lurking variable confounds the aggregated analysis. Association does not imply causation; causal conclusions require a well-designed randomized experiment.

Varsity Tutors • AP Statistics • Statistics for Two Categorical Variables