Neural Sync Active
Week 2: Categorical Data & Visual Summaries
Registry Synced
Week 2: Categorical Data & Visual Summaries
3107 words
16 min read
2026-09-12
Reading compass
Now · TL;DR
Statistics for Data Science I — Week 2: Categorical Data & Visual Summaries
IITM’s Week 2 moves into categororical data and its summaries/representations.
The syllabus line is broad, so the detailed treatment below is a standard expansion of that topic rather than extra IITM-specific claims.
TL;DR
For categorical data, the main job is not to calculate means.
It is to answer:
and:
The core tools are:
- frequency
- relative frequency
- percentage
- frequency tables
- bar charts
- pie charts
- comparing categorical distributions
- two-way/contingency tables for two categorical variables
1. Recap: categorical variable
A categorical variable records group membership or labels.
Examples:
- blood group
- city
- operating system
- favorite sport
- education level
- satisfaction category
Its values describe categories rather than measurements.
2. Nominal vs ordinal
Two major categorical types:
Nominal
Categories have no intrinsic order.
Example:
There is no natural:
Ordinal
Categories have meaningful order.
Example:
But spacing between categories is not necessarily equal.
3. Frequency
The frequency of a category is the number of observations belonging to it.
Suppose 20 students choose a preferred programming language:
| Language | Frequency |
|---|---|
| Python | 10 |
| Java | 5 |
| C | 3 |
| Other | 2 |
Total:
4. Frequency notation
If category i occurs:
times, then:
where:
is the total number of observations.
This is an important sanity check.
5. Relative frequency
Raw counts are often hard to compare across datasets of different sizes.
Relative frequency solves that.
For category i:
It lies between:
and:
6. Example
Using:
| Language | Frequency |
|---|---|
| Python | 10 |
| Java | 5 |
| C | 3 |
| Other | 2 |
with:
Python relative frequency:
Java:
C:
Other:
7. Relative frequencies must sum to 1
Because:
dividing everything by n gives:
Small deviations may occur because of rounding.
8. Percentage frequency
Percentage is simply:
For Python:
9. Frequency table
A useful categorical summary might include:
| Category | Frequency | Relative frequency | Percentage |
|---|---|---|---|
| Python | 10 | 0.50 | 50% |
| Java | 5 | 0.25 | 25% |
| C | 3 | 0.15 | 15% |
| Other | 2 | 0.10 | 10% |
| Total | 20 | 1.00 | 100% |
This converts raw categorical observations into a readable distribution.
10. Distribution of a categorical variable
The distribution tells us how observations are spread across categories.
For categorical data, this is essentially the collection of:
Example:
textPython → 50% Java → 25% C → 15% Other → 10%
11. Mode
For categorical data, the most natural measure of "center" is the mode.
The mode is the category with highest frequency.
In the previous example:
because it appears most often.
12. Why mean is usually meaningless for categories
Suppose:
Calculating:
has no meaningful interpretation.
The numbers are labels.
So for nominal categories:
frequencies, proportions and mode are meaningful; arithmetic means usually are not.
13. Bar chart
A bar chart represents each category using a bar whose height corresponds to:
- frequency
- relative frequency
- percentage
Conceptually:
textPython ██████████ Java █████ C ███ Other ██
The bars are separated because the categories are distinct.
14. Bar-chart axes
Typically:
- horizontal axis → categories
- vertical axis → frequency / proportion / percentage
Example:
15. Why bars are separated
Categorical values are distinct groups.
There is no continuous numerical interval between:
and:
So bars in an ordinary categorical bar chart are usually separated.
This becomes useful when comparing bar charts with histograms later.
16. Bar-chart ordering
For nominal categories, order may be chosen for clarity:
- alphabetical
- descending frequency
- logical grouping
For ordinal categories, preserve the meaningful natural order.
Example:
Reordering those randomly would destroy information.
17. Frequency vs proportion bar chart
Suppose two datasets have:
and:
Raw frequencies may be misleading when comparing them.
Proportions:
make comparisons easier.
18. Pie chart
A pie chart represents a whole as:
Each category gets an angle proportional to its relative frequency.
For category i:
19. Example
If Python represents:
of observations:
Java at:
gets:
20. Pie-chart sanity check
All slices must total:
and percentages must total approximately:
21. Bar chart vs pie chart
Both can summarize categorical distributions.
Bar chart
Better for:
- comparing categories precisely
- many categories
- similar-sized categories
- comparing multiple groups
Pie chart
Useful mainly for:
- simple part-to-whole representation
- small number of categories
Bar charts are generally easier for precise comparisons because humans compare lengths better than angles.
22. Pareto-style ordering
A bar chart can sometimes be sorted from largest frequency to smallest:
textA █████████ C ██████ B ███ D █
This quickly exposes dominant categories.
This sorting is useful for nominal categories, but not when the ordinal order itself carries meaning.
23. Two categorical variables
So far we considered one variable.
Now suppose each observation has:
- preferred OS
- device type
For example:
| Person | OS | Device |
|---|---|---|
| 1 | Android | Phone |
| 2 | iOS | Phone |
| 3 | Windows | Laptop |
| 4 | macOS | Laptop |
We may want to study whether the two variables are associated.
24. Two-way table
A two-way table, also called a contingency table, summarizes two categorical variables simultaneously.
Example:
| Phone | Laptop | Total | |
|---|---|---|---|
| Android | 40 | 5 | 45 |
| iOS | 35 | 2 | 37 |
| Windows | 2 | 30 | 32 |
| macOS | 1 | 25 | 26 |
| Total | 78 | 62 | 140 |
Each cell contains a joint frequency.
25. Joint frequency
A joint frequency counts observations satisfying both categories.
Example:
means:
40 observations are both Android users and Phone users.
26. Marginal frequencies
The totals along the margins are called marginal frequencies.
From the table:
Android total:
Phone total:
These summarize one variable without conditioning on the other.
27. Joint relative frequency
If total observations:
then the joint relative frequency of:
Android and Phone
is:
So about:
28. Conditional distribution
Suppose we want:
Among phone users, what fraction use Android?
Phone total:
Android-phone users:
Therefore:
This is conditional because we restrict attention to one subgroup first.
29. Conditional denominator rule
This is one of the biggest practical traps.
If the question says:
Among laptop users, what fraction use Windows?
Then denominator must be:
not total sample size.
Always ask:
What group am I conditioning on?
That group supplies the denominator.
30. Example
From:
| Phone | Laptop | Total | |
|---|---|---|---|
| Android | 40 | 5 | 45 |
| iOS | 35 | 2 | 37 |
| Windows | 2 | 30 | 32 |
| macOS | 1 | 25 | 26 |
| Total | 78 | 62 | 140 |
Among laptop users, proportion using Windows:
About:
31. Reverse conditional is different
Compare:
6230.Among laptop users, what percentage use Windows?
with:
3230.Among Windows users, what percentage use laptops?
These are completely different questions.
So:
in general.
Probability notation comes later, but the denominator intuition begins here.
32. Association between categorical variables
Two categorical variables are associated if the distribution of one changes across categories of the other.
Example:
Suppose:
Phone users
- Android: 51%
- iOS: 45%
- others: 4%
Laptop users
- Android: 8%
- iOS: 3%
- Windows: 48%
- macOS: 40%
The distributions are dramatically different.
That suggests an association between:
- device type
- operating system
33. No association intuition
If conditional distributions look almost identical across groups, that suggests little or no association.
For example:
| Group | Yes | No |
|---|---|---|
| A | 60% | 40% |
| B | 61% | 39% |
The distributions are very similar.
That does not prove independence formally yet, but it is the relevant descriptive idea.
34. Segmented / stacked bar charts
Two-way categorical data can be visualized with segmented bars.
Example conceptually:
textGroup A |████████████------| Group B |██████------------|
Each bar can represent:
with different segments representing category proportions.
This makes conditional distributions visually comparable.
35. Side-by-side bar charts
Another option:
textGroup A Group B Yes ██████ █████ No ███ ████
This is often easier for comparing individual categories between groups.
36. Counts vs percentages in two-way tables
Suppose:
Group A has:
people.
Group B has:
people.
Raw counts can obscure relative behavior.
If:
A-members choose Yes and:
B-members choose Yes,
raw counts say:
But percentages say:
vs:
So B actually has the higher Yes rate.
37. Simpson's-paradox intuition
A subtle issue can occur when aggregated proportions show one trend while subgroup proportions show another.
This is known as Simpson's paradox.
You do not need the full machinery yet, but retain this lesson:
Aggregation can hide important subgroup structure.
So always inspect whether another categorical variable is mixing together very different groups.
38. Missing category
Suppose a survey includes options:
- Yes
- No
- No response
Do not silently discard "No response" unless the analysis explicitly defines how missing data are treated.
Otherwise the denominator may change.
This can materially affect percentages.
39. Mutually exclusive categories
For a simple one-variable frequency table, categories should generally be mutually exclusive:
each observation belongs to exactly one category.
Bad categories:
- age <30
- age 20–40
Someone aged 25 belongs to both.
The categories overlap.
40. Exhaustive categories
Ideally, the categories should also cover every possible observation.
Example:
If asking transport mode:
- car
- bus
- bike
but someone walks, there is nowhere to classify them.
An "Other" category may make the scheme exhaustive.
41. Mutually exclusive + exhaustive
A clean categorical classification often aims for:
Meaning:
- no observation belongs to multiple categories
- every observation has somewhere to go
42. Frequency table from raw data
Suppose responses are:
textA, B, A, C, B, A, A, C, B, A
Count:
Total:
Relative frequencies:
43. Recovering frequency from percentage
Suppose:
and:
belong to category A.
Frequency:
So:
44. Recovering total from frequency and relative frequency
Suppose category A has:
and relative frequency:
Since:
we get:
45. Recovering missing frequency
Suppose:
| Category | Frequency |
|---|---|
| A | 15 |
| B | 20 |
| C | ? |
| D | 25 |
Total:
Then:
This kind of table arithmetic is straightforward but common.
46. Mode from a frequency table
If:
| Category | Frequency |
|---|---|
| A | 10 |
| B | 17 |
| C | 9 |
then:
because:
is the largest frequency.
47. Multiple modes
If two categories tie for highest frequency:
| Category | Frequency |
|---|---|
| A | 12 |
| B | 12 |
| C | 4 |
then both:
and:
are modal categories.
The distribution can be called bimodal in an appropriate descriptive sense.
Common mistake: frequency vs relative frequency
Frequency:
Relative frequency:
Percentage:
Don't mix units.
Common mistake: percentages exceeding 100%
For mutually exclusive exhaustive categories:
approximately.
If the sum is:
something is wrong unless multiple responses per observation are permitted.
50. Multiple-response questions
A survey may say:
Select all programming languages you use.
One person may select:
- Python
- JavaScript
- SQL
Then category counts can sum to more than:
And percentages may exceed:
when summed.
So always check whether the categories are mutually exclusive.
Common mistake: pie chart for overlapping categories
Pie charts assume parts form one whole.
If respondents can belong to multiple categories, ordinary pie-chart slices are misleading because percentages need not total:
Common mistake: treating ordinal values as nominal
For:
the order itself is information.
A graph should normally preserve:
Alphabetically rearranging them would obscure the structure.
Common mistake: comparing counts with unequal group sizes
Suppose:
Group A:
say Yes.
Group B:
say Yes.
Counts:
But rates:
For comparisons across differently sized groups, proportions are usually more informative.
Common mistake: wrong conditional denominator
Question:
Among students who passed, what percentage are in Group A?
Denominator:
not:
and not:
Read "among..." carefully.
Common mistake: association implies causation
Suppose device type and OS are associated.
That does not automatically mean one causes the other in the statistical causal sense.
Descriptive association tells us distributions differ.
Causal claims require additional assumptions/design.
56. Categorical-data workflow
For one categorical variable:
textRaw categories ↓ Count occurrences ↓ Frequency table ↓ Relative frequency / percentage ↓ Bar chart / simple visualization ↓ Identify dominant/rare categories
For two categorical variables:
textTwo variables ↓ Contingency table ↓ Joint + marginal frequencies ↓ Conditional percentages ↓ Compare distributions ↓ Assess descriptive association
57. Formula sheet
Relative frequency
ri=nfiPercentage
pi=nfi×100Frequency from percentage
fi=100pinPie-chart angle
θi=nfi×360∘Frequency total
i∑fi=nRelative-frequency total
i∑ri=158. Week 1 → Week 2 connection
Week 1 asked:
If the answer is:
Week 2 asks:
Then with two categorical variables:
That is the first step toward studying association.
59. What you should actually master
By the end of Stats 1 Week 2, you should be able to:
- Identify nominal and ordinal categorical variables.
- Build a frequency table from raw data.
- Calculate relative frequencies.
- Calculate percentages.
- Check that frequencies/proportions total correctly.
- Identify the modal category.
- Read and interpret bar charts.
- Understand pie-chart proportions.
- Choose proportions instead of raw counts when group sizes differ.
- Construct/read a two-way table.
- Identify joint and marginal frequencies.
- Calculate simple conditional proportions.
- Choose the correct denominator in "among..." questions.
- Compare categorical distributions across groups.
- Describe association without automatically claiming causation.
If those are comfortable, Stats 1 Week 2 is under control.
Quick Recall & Flashcards
Test your active recall before proceeding to practice problems. Format:
Question :: Answer.- Week 2 Diagnostic: In a dataset of 50 students, 20 prefer Python, 15 prefer Java, and 15 prefer C++. What is the relative frequency of students who prefer Python? :: Answer: 0.4 — Relative frequency = count / total = 20 / 50 = 0.4.
- Week 2 Diagnostic: Which measure of central tendency is valid for nominal categorical data? :: Answer: C — Nominal data has no ordering or numerical values, so only the most frequent category (Mode) is meaningful.
Practice & Self-Check
Attempt these diagnostic questions to verify your operational understanding.
1
Question 1
In a dataset of 50 students, 20 prefer Python, 15 prefer Java, and 15 prefer C++. What is the relative frequency of students who prefer Python?
NAT
3 Unit Assessment
2
Question 2
Which measure of central tendency is valid for nominal categorical data?
MCQ
3 Unit Assessment
A. Mean
B. Median
C. Mode
D. Variance