Topic contents

Lesson 1

How do we describe categorical data?

From “how many people” to “what share”: explore categorical variables using counts, proportions, and charts.

Start with the survey counts: how many people are in each category?

A categorical variable records categories, such as the way students most often travel to school. Below, each person can choose only one main category.

Adjust category counts

Adjust category counts

Whenever you change a category count, the frequency table and chart update together.

Total number of people n = 140 | Count fᵢ = number of individuals in a category

Categorical frequency table

CategoryCountProportion
Walking4028.6%
Bicycle2517.9%
Bus6042.9%
Other1510.7%
Total140100.0%
0204060Walking · Count: 40WalkingBicycle · Count: 25BicycleBus · Count: 60BusOther · Count: 15Other
Horizontal bar chart of categorical counts
Class observation: Category names themselves cannot be added or subtracted. First count the observations in each category, then compare these counts.

Counts and proportions answer different questions

A count is the actual number of people; relative frequency is the category's share of all observations. Multiply the relative frequency by 100% to obtain the percentage.

Adjust the survey counts yourself

Adjust category counts

Relative frequency rᵢ = fᵢ / n; percentage = rᵢ × 100%
Total number of people: 140
Sum of category relative frequencies: 1.000
Sum of category percentages: 100%

Displayed values are rounded individually, so their sum may differ from 100.0% by 0.1 percentage points. Calculations still use unrounded values.

Percentage bar chart

0%20%40%60%80%100%Walking · Percentage: 29%WalkingBicycle · Percentage: 18%BicycleBus · Percentage: 43%BusOther · Percentage: 11%Other
Bar chart of category percentages

Largest share: Bus, 42.9%

When sample sizes change, “more people” and “a larger proportion” must be compared separately.

ri=fin,Percentage=ri×100%r_i=\frac{f_i}{n},\quad \text{Percentage}=r_i\times100\%

What do bar charts and pie charts each show best?

Bar charts are useful for comparing category sizes; pie charts show the shares of nonoverlapping categories that together form a whole. Compare the two displays using the same data here.

Bar chart: compare sizes directly

0%20%40%60%80%100%Walking · Percentage: 29%WalkingBicycle · Percentage: 18%BicycleBus · Percentage: 43%BusOther · Percentage: 11%Other
Bar chart of category proportions

Pie chart: examine the composition of a whole

Walking28.6%Bicycle17.9%Bus42.9%Other10.7%
  • Walking
  • Bicycle
  • Bus
  • Other
Pie chart of category proportions
Class exercise: in which situation should you avoid directly making a pie chart whose shares add up to 100%?

Choose an option.

Comparing two groups: why look at within-group percentages first?

Suppose we survey students in different years about whether they use AI tools. If the groups differ in size, comparing user counts directly can be misleading. First calculate the usage proportion within each group.

Survey data for two groups

Survey data for two groups

Group usage proportion = number of users in the group ÷ total number in the group

The usage proportion is 70.0% for first-year students and 70.0% for second-year students. The difference between the two sample proportions, in percentage points, is 0.0.

This only describes the observed difference in proportions between groups. It does not by itself establish a statistically significant difference between population proportions or establish causation.

Within-group percentages (100% stacked bar chart)

0%20%40%60%80%100%First year · Use AI: 70%First year · Do not use AI: 30%First yearSecond year · Use AI: 70%Second year · Do not use AI: 30%Second year
  • Use AI
  • Do not use AI
100% stacked bar chart of within-year proportions for two years of study

Corresponding 2×2 frequency table

GroupUse AIDo not use AITotal
First year7030100
Second year421860
Total11248160
Coming next: The next lesson focuses on contingency tables and conditional percentages. We then discuss using a χ² test to assess whether two categorical variables are independent.
Group usage proportion=number of users in the grouptotal number in the group\text{Group usage proportion}=\frac{\text{number of users in the group}}{\text{total number in the group}}