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.

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.

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.

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.

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.

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̂(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̂(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̂(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
E_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.

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.

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.'

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.

Exercise Frequency × Health Self-Rating (n = 500)
ExcellentGoodFairTotal
Regular9012040250
Irregular30100120250
Total120220160500
Computing & Comparing Conditional Distributions
1
Step 1 — Identify the conditioning variableWe 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
Step 2 — Compute conditional proportions for Regular exercisersP̂(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
Step 3 — Compute conditional proportions for Irregular exercisersP̂(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
Step 4 — Compare and interpretThe 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.

Strengths, Limitations & Common Pitfalls

Strengths and limitations of two-way table analysis
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.
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.

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.

Descriptive vs. inferential analysis of two categorical variables
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

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.

Practice Problems

1
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?
2
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?
3
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?
PROBLEM 4APPLIED
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.
PROBLEM 5CRITICAL THINKING
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.

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