Historical Context & Motivation
Long before the formal machinery of statistical inference was developed, researchers recognized that understanding relationships between categorical attributes—such as occupation and literacy, or treatment type and patient outcome—required more than simple one-variable frequency counts. The challenge was clear: when two categorical variables each have multiple levels, summarizing every possible combination of categories demands a structured, tabular approach. The two-way table (also called a contingency table) emerged as the foundational tool for organizing such data, and its development parallels the rise of quantitative social science.
The central question this topic addresses is deceptively simple: Is there a relationship between two categorical variables, and how can we display and quantify that relationship? To answer it, we need tools that organize raw counts into meaningful summaries and graphical displays that make patterns—and their absence—visually apparent. This section of the AP Statistics curriculum equips you with exactly those tools.
Core Principles & Definitions
Before constructing any table or chart, it is essential to have a firm grasp of the key vocabulary. A categorical variable places each individual into one of several groups or categories; examples include political affiliation, blood type, or preferred mode of transportation. When we observe two categorical variables for each individual in a dataset, we can organize the counts into a two-way table (also called a contingency table), where rows represent the categories of one variable and columns represent the categories of the other.
Joint Frequency
Marginal Frequency
Conditional Distribution
Marginal Distribution
Association vs. Independence
Visual Explanation: The Two-Way Table
The diagram below presents a two-way table for a hypothetical survey of 400 college students cross-classified by class year (Freshman, Sophomore, Junior, Senior) and preferred study method (Alone, Group, Online). Joint frequencies appear in the interior cells; marginal frequencies are displayed along the right edge and bottom row. Observe how the marginal totals for each row sum to the row total, and the marginal totals for each column sum to the column total; both grand totals equal 400.
Notice the structural anatomy of the table. The intersection of the Freshman row and the Alone column yields the joint frequency 50, meaning 50 freshmen in the sample prefer studying alone. The row total for Freshmen (120) is the marginal frequency of the Freshman category, obtained by summing 50 + 30 + 40. Similarly, the column total for Alone (140) sums 50 + 35 + 30 + 25. The grand total of 400 in the bottom-right corner serves as a quick check: every row total and every column total must each sum to 400.
Mathematical Framework: Proportions & Distributions
Raw counts are informative, but proportions allow us to make meaningful comparisons—especially when row or column totals are unequal. There are three types of proportions commonly extracted from a two-way table: joint relative frequencies, marginal relative frequencies, and conditional relative frequencies. Each answers a fundamentally different question.
Graphical Displays: Segmented & Side-by-Side Bar Charts
While the two-way table is the computational backbone, graphical representations make associations (or their absence) immediately visible. The AP Statistics curriculum emphasizes two primary chart types for two categorical variables: segmented (stacked) bar charts and side-by-side bar charts. A segmented bar chart displays the conditional distribution of one variable within each category of the other by stacking colored segments to fill each bar to 100%. If the segment proportions are roughly the same across all bars, the variables appear independent; if the proportions shift noticeably, an association is suggested.
The chart makes the association visually apparent. The cyan segment (Alone) shrinks from 41.7% for Freshmen to 27.8% for Seniors, while the violet segment (Group) grows from 25.0% to 50.0%. If the two variables were independent—meaning class year had no relationship with study preference—all four bars would have essentially identical segment proportions. The visible differences suggest that as students advance through college, they increasingly prefer group study. A side-by-side bar chart would display the same information by placing separate bars for each study method next to one another within each class-year group, making it easier to compare absolute heights but harder to see proportional composition.
Worked Example
A health researcher surveys 500 adults about their exercise frequency (Regular, Occasional, None) and whether they report high stress levels (Yes, No). The data are shown in the table below. Determine whether there appears to be an association between exercise frequency and high stress.
| High Stress: Yes | High Stress: No | Total | |
|---|---|---|---|
| Regular | 40 | 160 | 200 |
| Occasional | 60 | 90 | 150 |
| None | 90 | 60 | 150 |
| Total | 190 | 310 | 500 |
Strengths & Limitations of Graphical Displays
Different graphical displays of two categorical variables emphasize different aspects of the data. Choosing the right display depends on whether your goal is to compare conditional proportions, compare counts, or show the overall composition. The table below summarizes the strengths and limitations of the most common options.
| Display Type | Best For | Limitations |
|---|---|---|
| Two-Way Table | Precise counts and proportions; computing conditional distributions; the essential starting point for any analysis | Not a visual display; patterns can be hard to spot in large tables with many categories |
| Segmented Bar Chart | Comparing conditional distributions across groups; detecting association at a glance | Difficult to compare middle segments accurately; does not show sample sizes unless annotated |
| Side-by-Side Bar Chart | Comparing absolute counts or proportions for specific categories; easy to read individual bar heights | Harder to see the full conditional distribution within each group; chart can become cluttered with many categories |
| Mosaic Plot | Showing both conditional proportions and relative group sizes in a single display | Less intuitive to read; not explicitly tested on the AP exam, but appears occasionally |
Connection to Inference: The Chi-Square Test
Everything covered so far—two-way tables, conditional distributions, and segmented bar charts—belongs to the exploratory data analysis (EDA) stage of statistics. We can describe patterns and note apparent associations, but we cannot yet determine whether those patterns are statistically significant or could have arisen by chance. That is the role of inferential statistics, specifically the chi-square test for independence, which you will encounter later in the AP Statistics curriculum.
| Feature | Descriptive (This Lesson) | Inferential (Chi-Square Test) |
|---|---|---|
| Goal | Summarize and display the relationship between two categorical variables in a sample | Determine whether a relationship observed in a sample provides convincing evidence of a relationship in the population |
| Tools | Two-way tables, segmented bar charts, conditional proportions | Expected counts, chi-square statistic (χ²), p-values, degrees of freedom |
| Output | "There appears to be an association..." | "There is statistically significant evidence of an association (p < 0.05)..." |
| Scope | Limited to the sample at hand | Generalizes from sample to population under stated conditions |
Mastering the descriptive skills in this lesson is essential groundwork for the chi-square test. The expected counts used in that test are derived from the marginal totals you already know how to compute, and the test statistic measures how far the observed joint frequencies deviate from what we would expect under independence. In other words, the chi-square test formalizes exactly the kind of comparison you perform when you eyeball a segmented bar chart and decide whether the segment proportions look "different enough" to matter.
Practice Problems
Summary & Review
Representing two categorical variables begins with the two-way table, which organizes raw counts into joint frequencies (interior cells) and marginal frequencies (row and column totals). From the table, we compute three types of proportions: joint relative frequencies (cell ÷ grand total), marginal relative frequencies (row or column total ÷ grand total), and conditional relative frequencies (cell ÷ row or column total). The conditional distributions are the key to detecting association.
Graphically, segmented bar charts and side-by-side bar charts are the primary tools for visualizing these relationships. Two 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. Always remember: association does not imply causation, and beware of Simpson's Paradox, in which a lurking variable can reverse an apparent trend when data are aggregated.