Quiz 2

Categorical Data — Frequency Tables, Proportions, and Charts

3298 words
16 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Categorical Data — Frequency Tables, Proportions, and Charts ## 🎯 Learning Objectives After completing this topic, you will be able to: - Construct **frequency tables** and **relative frequency tables** from raw categorical data - Compute and interpret **proportions**, **percentages**, and **ratios** - Create and...

Categorical Data — Frequency Tables, Proportions, and Charts

🎯 Learning Objectives

After completing this topic, you will be able to:
  • Construct frequency tables and relative frequency tables from raw categorical data
  • Compute and interpret proportions, percentages, and ratios
  • Create and interpret bar charts, pie charts, and Pareto charts
  • Choose the appropriate chart type for a given dataset
  • Recognize common visualization pitfalls and misleading charts

📋 Prerequisites

  • Data Types & Scales (01-data-types-scales) — categorical data comes in nominal or ordinal scales
  • Intro to Statistics (00-intro-statistics) — understand population vs sample
  • Basic arithmetic: counting, division, percentages

📖 Core Content

3.1 Intuition: Making Sense of Categories

Imagine you have 100 responses to the question "What's your favorite ice cream flavor?" The raw data looks like:
Chocolate, Vanilla, Strawberry, Chocolate, Vanilla, Chocolate, Mint Chip, Vanilla, Chocolate, Strawberry, ... Reading this raw list tells you almost nothing useful. You need to organize it — count how many people chose each flavor. Once you do that, patterns emerge:
FlavorCount
Chocolate35
Vanilla28
Strawberry20
Mint Chip12
Other5
Suddenly, you can see: Chocolate is the most popular, followed by Vanilla. You can say "35% of people prefer chocolate." You can make a bar chart that shows this instantly. This is the essence of categorical data analysis: counting and comparing.
🔑 Key Insight: With categorical data, we can't compute means or standard deviations. Our main tool is counting — frequencies, proportions, and the comparisons between them.

3.2 Frequency Tables

A frequency table organizes categorical data by listing each category and counting how many observations fall into it.

3.2.1 Simple Frequency

Definition: A table showing each category and its frequency (count).
ComponentMeaningExample
CategoryEach distinct value of the variableChocolate, Vanilla, etc.
Frequency (f)Number of observations in that category35 people chose Chocolate
Total (n)Sum of all frequencies100 respondents

3.2.2 Relative Frequency

Definition: The proportion or percentage of observations in each category.
Relative Frequency=FrequencyTotal=fn\text{Relative Frequency} = \frac{\text{Frequency}}{\text{Total}} = \frac{f}{n} Percentage=Relative Frequency×100%\text{Percentage} = \text{Relative Frequency} \times 100\%
Extended frequency table:
FlavorFrequency (f)Relative FrequencyPercentage
Chocolate3535/100 = 0.3535%
Vanilla2828/100 = 0.2828%
Strawberry2020/100 = 0.2020%
Mint Chip1212/100 = 0.1212%
Other55/100 = 0.055%
Total1001.00100%
Check: Relative frequencies always sum to 1. Percentages always sum to 100% (barring rounding).

3.2.3 Cumulative Frequency (for Ordinal Data)

For ordinal categorical data, we can compute cumulative frequencies — running totals as we go through categories in order. Example: Education level of 200 respondents
Education LevelFrequencyCumulative FrequencyCumulative %
High School404020%
Bachelor's8040 + 80 = 12060%
Master's60120 + 60 = 18090%
PhD20180 + 20 = 200100%
Interpretation: "60% of respondents have at most a Bachelor's degree" (cumulative % when we reach Bachelor's).
🔑 Note: Cumulative frequency is only meaningful when categories have a natural order. For nominal data (like ice cream flavors), cumulative frequency doesn't make sense — what does "at most Chocolate" mean?

3.3 Bar Charts

A bar chart displays each category as a bar whose height (or length) represents the frequency or relative frequency.

Anatomy of a Bar Chart

(Diagram) Key rules for bar charts:
  1. Bars should have equal width — only height varies
  2. Bars should have gaps between them (unlike histograms for continuous data)
  3. Bars can be vertical (column chart) or horizontal (bar chart)
  4. Order bars by natural order (ordinal) or by frequency (nominal)

When to use a bar chart:

  • Comparing frequencies across categories
  • Showing the distribution of a categorical variable
  • Making quick visual comparisons

Example: Bar Chart of Ice Cream Preferences

Imagine plotting the data from our frequency table:
  • X-axis: Chocolate, Vanilla, Strawberry, Mint Chip, Other
  • Y-axis: Frequency (0 to 40)
  • Chocolate bar reaches 35, Vanilla reaches 28, etc. The viewer instantly sees: chocolate is most popular; Mint Chip and Other are less common.

3.4 Pie Charts

A pie chart shows each category as a slice of a circle, with the slice angle proportional to the relative frequency. Angle formula: Each slice's angle = Relative Frequency × 360°
FlavorPercentageAngle
Chocolate35%0.35 × 360° = 126°
Vanilla28%0.28 × 360° = 100.8°
Strawberry20%0.20 × 360° = 72°
Mint Chip12%0.12 × 360° = 43.2°
Other5%0.05 × 360° = 18°
When to use a pie chart:
  • Showing parts of a whole (all categories together form 100%)
  • When there are few categories (ideally 2-5)
  • When you want to emphasize relative proportions When NOT to use a pie chart:
  • With many categories (slices become too small)
  • When comparing small differences (humans are bad at comparing angles)
  • When precise values matter (bar charts show values more clearly)
Rule of thumb: If you have more than 5 categories, use a bar chart instead of a pie chart.

3.5 Pareto Charts

A Pareto chart is a bar chart where categories are ordered by frequency (highest to lowest), with a cumulative percentage line overlaid. Pareto principle (80/20 rule): Often, a small number of categories account for a large proportion of the total.

When to use a Pareto chart:

  • Identifying the "vital few" categories that dominate
  • Quality control and problem-solving (focus on the biggest issues)
  • Resource allocation (prioritize the most frequent problems)

Example: Customer Complaints at a Call Center

Complaint TypeCountCumulative %
Long wait time15037.5%
Unresolved issue9060.0%
Rude staff5573.7%
Billing error4585.0%
Wrong department4095.0%
Other20100.0%
A Pareto chart would show:
  • Bars (from tallest to shortest): Long wait, Unresolved, Rude staff, Billing, Wrong dept., Other
  • A line graph showing cumulative percentage Interpretation: The first two categories (Long wait + Unresolved) account for 60% of complaints. Fixing the top three could address nearly 75% of issues. This is the Pareto principle in action — focus on the few categories that give the most impact. (Diagram)

3.6 Comparing Distributions

Often, we want to compare two or more groups on the same categorical variable. Tools for this include:

Side-by-Side Bar Charts

Place bars for each group next to each other within each category. Example: Ice cream preferences by gender (Diagram)

Stacked Bar Charts

Stack categories within each group to show the composition. Use cases:
  • Comparing proportions across groups
  • Showing how the "mix" of categories changes

Grouped (Clustered) Bar Charts vs. Stacked Bar Charts

TypeBest ForLimitation
Side-by-sideComparing exact frequencies across groupsCan be cluttered with many categories
StackedComparing proportions/composition across groupsHard to compare individual categories

3.7 Worked Examples

Example 1: Building a Frequency Table (Easy)

Scenario: A survey asks 30 students their favorite subject: Math, Science, English, or History. Raw responses:
Math, Science, Math, English, Science, Math, History, Math, Science, English, Math, Math, Science, English, Math, Science, History, Math, Science, Math, English, Math, Science, Math, History, Math, Science, English, Math, Science Task: Create a frequency table with frequencies, relative frequencies, and percentages. Solution:
StepAction
1List distinct categories: Math, Science, English, History
2Count Math: M, M, M, M, M, M, M, M, M, M, M, M, M = 13
3Count Science: S, S, S, S, S, S, S, S, S = 9
4Count English: E, E, E, E, E = 5
5Count History: H, H, H = 3
6Verify total: 13 + 9 + 5 + 3 = 30 ✅
Final table:
SubjectFrequency (f)Relative FrequencyPercentage
Math1313/30 ≈ 0.43343.3%
Science99/30 = 0.30030.0%
English55/30 ≈ 0.16716.7%
History33/30 = 0.10010.0%
Total301.000100%
Interpretation: Math is the most popular subject (43.3% of students chose it). History is least popular (10%).

Example 2: Pie Chart Construction (Medium)

Scenario: Using the same data, calculate the angles for a pie chart. Solution:
SubjectPercentageAngle CalculationAngle
Math43.3%0.433 × 360°156°
Science30.0%0.300 × 360°108°
English16.7%0.167 × 360°60°
History10.0%0.100 × 360°36°
Total100%1.000 × 360°360° ✅
Check: The angles sum to 360° (within rounding error).

Example 3: Choosing the Right Chart (Harder)

Scenario: A company has data on customer age groups:
Age GroupNumber of Customers
18-25500
26-351200
36-45800
46-55300
56+200
Question: What chart type(s) would you recommend and why? Solution: Analysis of the data:
  • Age groups are ordinal (natural order)
  • 5 categories — manageable number
  • We want to show the distribution across groups Recommended charts:
ChartWhy It Works
Bar chart (ordered by age group)Shows the "peak" in 26-35 group clearly. The natural ordering preserves the age progression
Pareto chartIf we want to identify which age groups are most important (though here, the natural order is more informative than sorted-by-frequency)
Pie chartCould work, but 5 slices with very different sizes might be hard to read
Best choice: A bar chart with age groups in natural order on the X-axis. This clearly shows the distribution is skewed toward younger customers, peaking at 26-35 and tapering off.

3.8 Edge Cases & Gotchas

The "Other" Category

When a categorical variable has many possible values, we often group rare ones into "Other." Guidelines:
  • "Other" should not be the largest category
  • If "Other" becomes large, you need a better categorization scheme
  • Always define what "Other" includes

Misleading Pie Charts

Pie charts can be deceptive in several ways:
  1. 3D effects: Make slices look bigger than they are
  2. Exploded slices: Emphasize one slice disproportionately
  3. Too many slices: Creates a cluttered, unreadable chart
  4. Non-additive percentages: If percentages don't sum to 100%, the chart is wrong

Zero Frequencies

Sometimes a category exists but has zero observations. Should you include it?
  • Yes — if the category is logically part of the variable and might have observations in other contexts
  • No — if including it creates unnecessary visual clutter

3.9 Why This Matters

Categorical data is everywhere in real life:
  • Market research: What brand do customers prefer?
  • Medicine: What blood type is most common?
  • Quality control: What defect types occur most often?
  • Politics: How do different demographics vote? The tools in this topic — frequency tables, bar charts, pie charts, Pareto charts — are used daily by analysts worldwide. They form the foundation for:
  • Week 4 (Contingency Tables): Extending frequency analysis to two categorical variables
  • BSMA1004 (Stats 2): Chi-square tests for categorical data
  • BSMS2002 (Business Analytics): Customer segmentation and market analysis

📐 Key Formulas / Concepts

ConceptFormula / DescriptionWhen to Use
Frequency (f)Count of observations in a categoryAlways — the basic building block
Relative Frequencyf/nf / nComparing groups of different sizes
Percentage(f/n)×100%(f / n) \times 100\%More interpretable than raw proportions
Cumulative FrequencyRunning total of frequenciesOnly for ordinal data
Pie Chart AngleRelative Frequency×360°\text{Relative Frequency} \times 360°For showing parts of a whole (≤5 categories)
Bar ChartHeight = Frequency, gaps between barsFor comparing frequencies visually
Pareto ChartSorted bars + cumulative % lineFor identifying the "vital few" categories

⚠️ Common Pitfalls

Pitfall 1: Using a Pie Chart with Too Many Categories

The mistake: Creating a pie chart with 10+ slices, making it unreadable. Why it happens: Pie charts look "friendly" and intuitive. People default to them without considering the number of categories. How to catch it: Count the categories. If more than 5, use a bar chart instead. Correct approach: For many categories, a bar chart sorted by frequency gives a much clearer picture.

Pitfall 2: Misleading Y-Axis on Bar Charts

The mistake: Starting the Y-axis at a value other than zero to exaggerate differences. Why it happens: To make small differences look dramatic (common in news media). Example: A bar chart showing 52% vs 48% support starting the Y-axis at 45 makes a 4% gap look enormous. Correct approach: Always start bar chart axes at zero. If you must start elsewhere, clearly label the axis and consider using a different chart type.

Pitfall 3: Confusing Bar Charts with Histograms

The mistake: Creating a bar chart for continuous data or a histogram for categorical data. Why it happens: Both use bars, and the terms are sometimes used interchangeably. The difference:
FeatureBar ChartHistogram
Data typeCategoricalContinuous
Bar widthEqual (arbitrary)Proportional to bin width
Gaps between barsYesNo (bars touch)
OrderArbitrary or by frequencyNatural numeric order

Pitfall 4: Cumulative Frequency on Nominal Data

The mistake: Computing cumulative frequencies for nominal (unordered) categories. Why it happens: The student hears "cumulative frequency" and applies it without checking if order exists. Correct approach: Cumulative frequency only makes sense for ordinal data. For nominal data, stick to individual frequencies.

📝 Practice Questions

Q1: Frequency Table Construction
The following data shows the blood types of 40 patients:
A, B, O, A, AB, A, O, B, O, A, A, B, O, A, AB, O, A, O, B, A, O, A, B, O, A, AB, O, A, O, B, A, O, A, B, O, A, AB, O, A, B
Construct a frequency table with frequencies, relative frequencies, and percentages.
<details> <strong>Solution</strong>
Step 1: Count each blood type
Blood TypeTallyFrequency
AA, A, A, A, A, A, A, A, A, A, A, A, A, A, A15
BB, B, B, B, B, B, B, B8
ABAB, AB, AB, AB4
OO, O, O, O, O, O, O, O, O, O, O, O, O13
Step 2: Verify total: 15 + 8 + 4 + 13 = 40 ✅
Step 3: Compute relative frequencies and percentages
Blood TypefRelative FrequencyPercentage
A1515/40 = 0.37537.5%
B88/40 = 0.20020.0%
AB44/40 = 0.10010.0%
O1313/40 = 0.32532.5%
Total401.000100%
Interpretation: Blood type A is most common (37.5%), followed by O (32.5%). AB is rarest (10%).
</details> > **Q2: Pie Chart Angles** > > Using the blood type data from Q1, calculate the central angles for a pie chart. > > <details> <strong>Solution</strong> > >
Blood TypePercentageAngle CalculationAngle
A37.5%0.375 × 360°135°
B20.0%0.200 × 360°72°
AB10.0%0.100 × 360°36°
O32.5%0.325 × 360°117°
Total100%1.000 × 360°360° ✅
Check: 135 + 72 + 36 + 117 = 360° ✅
</details> > **Q3: Chart Selection** > > For each scenario, recommend the best chart type and explain why: > > a) Showing the market share of 5 smartphone brands b) Identifying the most common types of defects in a manufacturing process c) Comparing the education levels (HS, Bachelor's, Master's, PhD) across two companies > > <details> <strong>Solution</strong> > > **a) Market share of 5 brands:** **Pie chart** or **bar chart** > > - Pie chart works because there are few categories and we want to show "parts of a whole" (market share) > - Bar chart also works if we want precise comparisons between brands > > **b) Most common defects:** **Pareto chart** > > - The goal is to identify which defects occur most frequently > - Sorting by frequency and adding a cumulative % line shows where to focus quality improvement efforts > - The Pareto principle likely applies (a few defect types account for most problems) > > **c) Education levels across 2 companies:** **Side-by-side bar chart** or **stacked bar chart** > > - We need to compare distributions across groups > - Side-by-side bars for each education level allow direct comparison > - Stacked bars show the composition of each company's workforce </details> > **Q4: Cumulative Frequency** > > A survey asks 500 people their highest education level: > >
EducationFrequency
High School120
Bachelor's200
Master's130
PhD50
Compute the cumulative frequencies and cumulative percentages. What percentage have at most a Bachelor's degree?
<details> <strong>Solution</strong>
EducationFrequencyCumulative FreqCumulative %
High School120120120/500 = 24%
Bachelor's200120 + 200 = 320320/500 = 64%
Master's130320 + 130 = 450450/500 = 90%
PhD50450 + 50 = 500500/500 = 100%
Interpretation: 64% of respondents have at most a Bachelor's degree. In other words, 64% have a Bachelor's or less (HS + Bachelor's).
Alternative phrasing: 36% have a Master's or higher (100% - 64%).
</details> > **Q5: Pareto Analysis** > > A hospital tracks reasons for readmission within 30 days: > >
ReasonReadmissions
Infection85
Medication error42
Patient non-compliance38
Discharge planning failure25
Follow-up missed20
Other15
Create a Pareto analysis (sorted frequencies + cumulative percentages). Which reasons should be addressed first?
<details> <strong>Solution</strong>
Step 1: Sort by frequency (descending)
ReasonFrequencyCumulative %
Infection8585/225 = 37.8%
Medication error42127/225 = 56.4%
Patient non-compliance38165/225 = 73.3%
Discharge planning failure25190/225 = 84.4%
Follow-up missed20210/225 = 93.3%
Other15225/225 = 100%
Total readmissions: 85 + 42 + 38 + 25 + 20 + 15 = 225
Step 2: Identify the vital few
  • The top 2 reasons (Infection + Medication error) account for 56.4% of readmissions
  • The top 3 reasons account for 73.3%
  • The top 4 account for 84.4%
Recommendation: Focus on Infection and Medication error first — these two categories alone account for over half of all readmissions. Addressing the top 3 categories would address nearly 75% of the problem.
</details> > **Q6: True or False** > > For each statement, determine if it's true or false. If false, explain why. > > a) Bar charts should have gaps between bars. b) Pie charts are ideal for comparing small differences between categories. c) Cumulative frequency can be computed for nominal data. d) A Pareto chart combines bars and a line graph. > > <details> <strong>Solution</strong> > > a) **True** — Gaps distinguish bar charts (categorical data) from histograms (continuous data). > > b) **False** — Humans are bad at comparing angles and areas. Small differences are better shown with bar charts where height differences are easier to perceive. > > c) **False** — Cumulative frequency requires ordered categories. Nominal data has no order, so "cumulative" makes no sense. > > d) **True** — A Pareto chart has bars (sorted by frequency) AND a line showing cumulative percentage. </details> > **Q7: Chart Criticism** > > A magazine shows a pie chart with 12 categories, some with 3D effect, and the percentages sum to 97%. Critique this visualization. > > <details> <strong>Solution</strong> > > **Problems identified:** > > 1. **Too many categories (12):** Pie slices will be too thin to distinguish. Bar chart would be better. > > 2. **3D effect distorts perception:** The 3D perspective makes slices at the front look larger than they are. This is a well-known visual bias. > > 3. **Percentages don't sum to 100%:** They sum to 97%, which means 3% of the data is unaccounted for. Either there's a rounding error, or some data was omitted. > > 4. **Possible missing "Other" category:** If some categories were combined into "Other," it's not shown. > > > **Better approach:** A bar chart (or horizontal bar chart) with categories sorted by frequency, with a clear Y-axis starting at 0, and percentages that sum to 100%. </details> > **Q8: Application — Survey Analysis** > > You work for a streaming service. A survey of 1,000 users asks: "What's your primary reason for subscribing?" Results: > >
ReasonCount
Content library420
Price280
Original shows180
User interface70
Customer service50
a) Compute relative frequencies and percentages. b) What chart would you use to present this to management? c) Write a one-paragraph summary of the findings.
<details> <strong>Solution</strong>
a) Relative frequencies and percentages:
ReasonCountRelative FrequencyPercentage
Content library4200.42042.0%
Price2800.28028.0%
Original shows1800.18018.0%
User interface700.0707.0%
Customer service500.0505.0%
Total10001.000100%
b) Recommended chart: A Pareto chart would be excellent here because:
  • It shows the relative importance of each reason
  • The cumulative line demonstrates that Content library + Price account for 70% of reasons
  • Management can see where to focus retention efforts
Alternatively, a bar chart sorted by frequency works well.
c) Summary paragraph: "The primary driver of subscriptions is content — 42% of users subscribe for the content library. Price is the second most important factor (28%), followed by original shows (18%). User interface and customer service together account for only 12% of subscriptions. This suggests that investment in content acquisition should be the top priority for retention and growth, while pricing strategy and original content production are secondary levers."
</details> * * * ## 🔗 Cross-References - **Next topic:** [Central Tendency — Mean, Median, and Mode](/notes/01-foundation-bsma1002-stats-1-week03-03-central-tendency) — now that we can summarize categorical data, we move to numerical data - **Previous topic:** [Data Types & Scales](/notes/01-foundation-bsma1002-stats-1-week01-01-data-types-scales) — categorical data definitions - **Week 4 (Contingency Tables):** Extending frequency analysis to two categorical variables - **BSMA1004 (Stats 2):** Chi-square tests for categorical data - **BSMS2002 (Business Analytics):** Market segmentation using categorical analysis [Join Discord](https://discord.gg/gE2m4Qrdqv) [Previous**Sampling Methods**](/notes/01-foundation-bsma1002-stats-1-week01-00a-sampling-methods)[Next**Central Tendency**](/notes/01-foundation-bsma1002-stats-1-week03-03-central-tendency)
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.