Weeks
Statistics 1Week 2 · Frequency Tables, Charts, Mode and Median
Week 2 Notes

Statistics for
Data Science 1

Describing categorical data: frequency tables, charts, honest graphs, and the mode and median.

9 chapters32 worked examples~33 min read
Frequency tablesPie and bar chartsMisleading graphsMode and median

Chapters

  1. 01Frequency DistributionsLecture 2.1
  2. 02Relative FrequencyLecture 2.1
  3. 03Pie ChartsLecture 2.2
  4. 04Bar ChartsLecture 2.2
  5. 05Pareto Charts and Ordinal DataLecture 2.2
  6. 06Best Practices and Misleading GraphsLectures 2.3 and 2.4
  7. 07ModeLecture 2.5
  8. 08Median for Ordinal DataLecture 2.5
  9. 09Week 2 Summary SheetAll lectures

Based on lectures by Usha Mohan, IIT Madras

01
Lecture 2.1

Frequency Distributions

Week 2 is about describing one categorical variable. Everything starts with a frequency table: a list of the categories and how many times each one occurs.

DefinitionA frequency distribution of qualitative data is a listing of the distinct values and their frequencies. Each row of a frequency table lists a category along with the number of cases in that category.

1.1Where this fits

Lecture 2.1 starts with a review of Week 1. Frequency tables are the first tool for one categorical variable, so three ideas from Week 1 are the background.

What is statistics?
  • Descriptive and inferential statistics.
  • Sample versus population.
How data are collected
  • Variables and cases (observations) in a data set.
Kinds of data
  • Categorical (qualitative) or numerical (quantitative).
  • Cross-sectional versus time-series; measurement scales.

1.2Steps to build a frequency distribution

  1. List the distinct values. Write each different category once, in the first column.
  2. Tally every observation. Go through the data one value at a time and put a tally mark in that value's row.
  3. Count the tallies. Turn each row of tally marks into a number. This is the frequency.
Tally marksTally marks are written in bundles of five: four short strokes and a fifth stroke across them (here shown as ||||). The bundles make the count easy to read at the end of Step 3.

1.3Lecture examples: four data sets

The lecture builds a frequency table for four lists of categories. Read each list from left to right; every observation adds one tally to its row. After counting, the frequencies must add up to the number of observations.

Data set 1 (10 observations): A, A, B, C, A, D, A, B, D, C

CategoryTallyFrequency
A||||4
B||2
C||2
D||2
Total10

Check: 4+2+2+2=104 + 2 + 2 + 2 = 10, the number of observations.

All four data sets together

Data setnABCDSum
Data set 110422210
Data set 215633315
Data set 315363315
Data set 418634518
  • Data set 2: A, A, B, C, A, D, A, B, D, C, A, B, C, D, A
  • Data set 3: A, B, B, C, A, D, B, B, D, C, A, B, C, D, B
  • Data set 4: A, A, B, C, A, D, A, B, D, C, A, B, C, D, A, C, D, D
A discrepancy in the slidesIn the lecture's problem list, data set 3 is printed as A,A,B,C,A,A,B,B,D,C,A,B,C,D,B. The solution slides use A,B,B,C,A,D,B,B,D,C,A,B,C,D,B, and their frequencies (A = 3, B = 6, C = 3, D = 3) match only this second list. These notes use the second list.

1.4Frequency table in a Google Sheet

  1. Select (highlight) the cells that have the data you want to summarise.
  2. In the formatting bar click the Data option.
  3. Go to Pivot table and create it in a new sheet.
  4. In the Pivot table editor, first add Rows and then add Values.

1.5Going deeper: reading and checking a frequency table

  1. The total is your safety check. The frequencies must add up to the number of observations. If they do not, you skipped or double-counted something.
  2. Count from the list, not from the table. Cross out each observation as you tally it, so none is counted twice.
  3. Order of the rows does not matter for a nominal variable. Write the categories in any sensible order (here A to D).
  4. Frequency is a count, so it is a whole number: 0, 1, 2, ... It is never negative and never a fraction. Fractions come in the next topic.
Exam tips
  • Always write the total row and check it against the number of observations.
  • A table with the right shape but the wrong total means a counting slip: recount the largest category first.
Common mistakes
  • Listing a category twice in the first column.
  • Calling the tally marks the frequency. The frequency is the number you get by counting them.
  • Forgetting the total check.

Practice questions (graded-assignment style)

Q1Frequency of B

Multiple Choice Question (MCQ): choose the one correct option.

The observations are B, A, B, C, B, A, C, B, D, B. What is the frequency of B?

1
3
2
4
3
5
4
6
Solution
Idea

Count the B's while going through the list once.

  • B appears at positions 1, 3, 5, 8 and 10.
  • That is 5 tallies, so the frequency is 5.
  • Answer: option 3.
Q2The missing frequency

Numerical Answer Type (NAT).

A frequency table for 25 observations has A = 9, B = 6, C = 4, D = 3 and a fifth category E whose frequency is missing. Find the frequency of E.

Solution
Idea

The frequencies add up to the number of observations.

  • 9+6+4+3=229 + 6 + 4 + 3 = 22.
  • E=25−22=3E = 25 - 22 = 3.
  • Answer: 3
Q3Frequency tables: true or false

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
Each row of a frequency table lists one category and its count.
2
The frequencies add up to the number of observations.
3
In Step 2, each observation puts one tally in the row of its value.
4
A frequency can be a fraction between 0 and 1.
Solution
Idea

Frequency is a count; a fraction is a relative frequency.

  • Option 1 is correct: that is the definition.
  • Option 2 is correct: it is the check at the end.
  • Option 3 is correct: that is Step 2.
  • Option 4 is wrong: fractions between 0 and 1 are relative frequencies.
  • Answer: options 1, 2 and 3.
Q4Choose the right table

Multiple Choice Question (MCQ): choose the one correct option.

The colours of ten cars are R, G, B, R, G, R, R, B, G, R. Which frequency table is correct?

1
R = 5, G = 3, B = 2
2
R = 4, G = 4, B = 2
3
R = 5, G = 2, B = 3
4
R = 6, G = 3, B = 1
Solution
Idea

Count each colour and check the total is 10.

  • R is at positions 1, 4, 6, 7, 10: 5 times.
  • G is at positions 2, 5, 9: 3 times.
  • B is at positions 3, 8: 2 times. Total 5+3+2=105 + 3 + 2 = 10.
  • Answer: option 1.
Next · Lecture 2.1Relative Frequency
02
Lecture 2.1

Relative Frequency

Raw counts cannot compare two data sets of different sizes. Dividing each count by its own total gives a proportion, and proportions can be compared.

DefinitionThe ratio of the frequency to the total number of observations is called the relative frequency.
relative frequency=frequencytotal number of observations\text{relative frequency} = \frac{\text{frequency}}{\text{total number of observations}}

2.1Steps to construct it

  1. Obtain a frequency distribution of the data.
  2. Divide each frequency by the total number of observations.

A relative frequency is always between 0 and 1, and the relative frequencies of all categories add to 1.

2.2Why use relative frequency?

Reason 1: comparing two data sets
  • Two data sets can have different numbers of observations. Raw counts are not comparable, but proportions are.
Reason 2: a standard scale
  • Relative frequencies always fall between 0 and 1, so they give a standard for comparison.
024684A2B2C2DData set 1 (n = 10)Frequency024686A3B3C3DData set 2 (n = 15)Frequency
Figure 1. Different frequencies, because the sizes differ (10 and 15)
00.10.20.30.40.50.4A0.2B0.2C0.2DData set 1 (n = 10)Relative frequency00.10.20.30.40.50.4A0.2B0.2C0.2DData set 2 (n = 15)Relative frequency
Figure 2. Identical relative frequencies: 0.4, 0.2, 0.2, 0.2
Reading the figures

On the first figure the bars for data set 2 are taller because it has 15 observations instead of 10. On the second, both data sets give 0.4, 0.2, 0.2, 0.2: once each count is divided by its own total, the two data sets have exactly the same pattern.

2.3Lecture examples: relative frequencies

The lecture leaves the last column blank for data sets 3 and 4, so those values are worked out here from the frequencies.

Data setnABCD
1104 ÷ 10 = 0.42 ÷ 10 = 0.22 ÷ 10 = 0.22 ÷ 10 = 0.2
2156 ÷ 15 = 0.43 ÷ 15 = 0.23 ÷ 15 = 0.23 ÷ 15 = 0.2
3153 ÷ 15 = 0.26 ÷ 15 = 0.43 ÷ 15 = 0.23 ÷ 15 = 0.2
4186 ÷ 18 = 0.3333 ÷ 18 = 0.1674 ÷ 18 = 0.2225 ÷ 18 = 0.278
  • Data set 1: 0.4+0.2+0.2+0.2=10.4 + 0.2 + 0.2 + 0.2 = 1. Data set 2 gives the same relative frequencies although the counts differ.
  • Data set 3: 0.2+0.4+0.2+0.2=10.2 + 0.4 + 0.2 + 0.2 = 1. B is the largest share, 40 percent.
  • Data set 4: 0.333+0.167+0.222+0.278=1.0000.333 + 0.167 + 0.222 + 0.278 = 1.000. When a division does not end, the values are rounded to three decimals, so the rounded column can differ from 1 in the last digit (see Chapter 6, round-off errors).

2.4Going deeper: frequency versus relative frequency

  1. Use frequency when you want to know how many. Use relative frequency when you want to compare shares or compare two data sets.
  2. Percent is relative frequency times 100. A relative frequency of 0.4 is 40 percent.
  3. To go back, multiply by the total: frequency=relative frequency×n\text{frequency} = \text{relative frequency} \times n. For n=40n = 40 and relative frequency 0.25 the frequency is 10.
Exam tips
  • Obtain the frequency table first, then divide. Do not divide the raw list.
  • Add the column at the end: it should be 1 (or 1.000 after rounding).
Common mistakes
  • Dividing by the number of categories instead of the number of observations.
  • Concluding that two data sets differ because their counts differ. Compare relative frequencies.

Practice questions (graded-assignment style)

Q1One relative frequency

Numerical Answer Type (NAT).

A category has frequency 18 in a data set of 60 observations. Find its relative frequency.

Solution
Idea

Divide the frequency by the total.

  • 18÷60=0.318 \div 60 = 0.3.
  • Answer: 0.3
Q2Which data set has more A?

Multiple Choice Question (MCQ): choose the one correct option.

Data set X has 40 observations with 12 A's. Data set Y has 60 observations with 15 A's. Which statement is correct?

1
A has the larger relative frequency in X.
2
A has the larger relative frequency in Y.
3
A has the same relative frequency in both.
4
Y has more A's, so Y has the larger relative frequency.
Solution
Idea

Compare proportions, not counts.

  • X: 12÷40=0.3012 \div 40 = 0.30.
  • Y: 15÷60=0.2515 \div 60 = 0.25.
  • Y has more A's in count, but X has the larger proportion.
  • Answer: option 1.
Q3Properties of relative frequency

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
A relative frequency is always between 0 and 1.
2
The relative frequencies of all categories add to 1.
3
Two data sets of different sizes can have the same relative frequencies.
4
Relative frequency = frequency ×\times total.
Solution
Idea

Relative frequency is frequency divided by total.

  • Options 1 and 2 are the two standard properties.
  • Option 3 is correct: data sets 1 and 2 both give 0.4, 0.2, 0.2, 0.2.
  • Option 4 is wrong: it is frequency divided by total.
  • Answer: options 1, 2 and 3.
Q4Recover a frequency

Numerical Answer Type (NAT).

In a data set of 40 observations the relative frequencies are A = 0.35, B = 0.40 and C = 0.25. Find the frequency of C.

Solution
Idea

Multiply the relative frequency by the total.

  • 0.25×40=100.25 \times 40 = 10.
  • Check: A = 14, B = 16, C = 10 and 14+16+10=4014 + 16 + 10 = 40.
  • Answer: 10
Next · Lecture 2.2Pie Charts
03
Lecture 2.2

Pie Charts

The two most common displays of a categorical variable are a bar chart and a pie chart. Both describe the variable by displaying its frequency table.

DefinitionA pie chart is a circle divided into pieces proportional to the relative frequencies of the qualitative data.

3.1Steps to construct a pie chart

  1. Obtain a relative-frequency distribution of the data.
  2. Divide a circle into pieces proportional to the relative frequencies.
  3. Label the slices with the distinct values and their relative frequencies.

3.2Finding the angle of each slice

Use a protractor and the fact that a full circle has 360∘360^\circ. Each slice gets an angle equal to its relative frequency times 360∘360^\circ.

angle of a slice=relative frequency×360∘\text{angle of a slice} = \text{relative frequency} \times 360^\circ

For the first slice of the lecture example the relative frequency is 0.4, so the angle is 0.4×360∘=144∘0.4 \times 360^\circ = 144^\circ.

3.3Lecture examples: slice angles

Data set 1: A, A, B, C, A, D, A, B, D, C

CategoryFrequencyRelative freqDegrees
A40.4144°
B20.272°
C20.272°
D20.272°
Total101360°

Check: 144+72+72+72=360144 + 72 + 72 + 72 = 360, the full circle.

A40% · 144°B20% · 72°C20% · 72°D20% · 72°
Figure 3. Pie chart for data set 1: start at the top and go clockwise; the first slice is 144°

Data set 2: same slices

The frequencies are 6, 3, 3, 3 with total 15, so the relative frequencies are again 0.4, 0.2, 0.2, 0.2 and the angles are again 144∘,72∘,72∘,72∘144^\circ, 72^\circ, 72^\circ, 72^\circ. The pie chart looks identical: a pie chart depends only on the relative frequencies, not on the number of observations.

3.4Pie chart in a Google Sheet

  1. Select (highlight) the cells that have the data you want to visualise.
  2. Click the Insert chart option in the toolbar.
  3. Change the visualisation type in the Chart editor.
  4. Set the Chart type to Pie chart.

3.5Going deeper: when to use a pie chart

  1. A pie chart shows parts of a whole. It is a good way to show that one category makes up more than half of the total.
  2. Angles always add to 360°, and relative frequencies always add to 1. Use whichever sum is easier as a check.
  3. Too many thin slices are hard to read. Chapter 6 shows how to group small categories.
Exam tips
  • From a table: angle = relative frequency × 360. From a pie: relative frequency = angle ÷ 360.

Practice questions (graded-assignment style)

Q1A slice angle

Numerical Answer Type (NAT).

In a data set of 30 observations a category has frequency 9. What is the angle of its slice in a pie chart, in degrees?

Solution
Idea

Relative frequency first, then multiply by 360.

  • 9÷30=0.39 \div 30 = 0.3.
  • 0.3×360=1080.3 \times 360 = 108.
  • Answer: 108
Q2From relative frequency to angle

Numerical Answer Type (NAT).

A category has relative frequency 0.35. Find the angle of its slice, in degrees.

Solution
Idea

Angle = relative frequency × 360.

  • 0.35×360=1260.35 \times 360 = 126.
  • Answer: 126
Q3From angle to relative frequency

Multiple Choice Question (MCQ): choose the one correct option.

In a pie chart the slices for A, B, C and D have angles 144°, 72°, 72° and 72°. What is the relative frequency of A?

1
0.144
2
0.4
3
0.5
4
0.25
Solution
Idea

Relative frequency = angle ÷ 360.

  • 144÷360=0.4144 \div 360 = 0.4.
  • Check: 144+72+72+72=360144 + 72 + 72 + 72 = 360.
  • Answer: option 2.
Q4Pie chart facts

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
Slice angle = relative frequency ×360∘\times 360^\circ.
2
The slice angles add up to 360∘360^\circ.
3
Data sets 1 and 2 of this chapter give identical pie charts.
4
A pie chart changes shape when the number of observations doubles, even if all relative frequencies stay the same.
Solution
Idea

A pie chart depends only on relative frequencies.

  • Options 1 and 2 are the rules.
  • Option 3 is correct: both have relative frequencies 0.4, 0.2, 0.2, 0.2.
  • Option 4 is wrong: same relative frequencies mean the same pie.
  • Answer: options 1, 2 and 3.
Next · Lecture 2.2Bar Charts
04
Lecture 2.2

Bar Charts

DefinitionA bar chart displays the distinct values of the qualitative data on a horizontal axis and the relative frequencies (or frequencies or percents) on a vertical axis. Each distinct value gets a vertical bar whose height equals its frequency or relative frequency. The bars should be positioned so that they do not touch each other.

4.1Steps to construct a bar chart

  1. Obtain a frequency or relative-frequency distribution of the data.
  2. Draw a horizontal axis on which to place the bars and a vertical axis to display the frequencies or relative frequencies.
  3. For each distinct value, construct a vertical bar whose height equals the frequency or relative frequency of that value.
  4. Label the bars with the distinct values, the horizontal axis with the name of the variable, and the vertical axis with “Frequency” or “Relative frequency”.

4.2Anatomy of a bar chart

0123454A2B2C2DCategory (name of the variable)Frequency
Figure 4. Bar chart for data set 1 (A = 4, B = 2, C = 2, D = 2)
Reading the figure

The horizontal axis carries the categories and is named after the variable. The vertical axis carries the frequency, so the bar for A reaches 4 and the other three reach 2. The gaps between the bars remind us that the categories are separate groups, not one continuous scale.

4.3Lecture example: bar chart from a frequency table

  1. The frequency distribution of data set 1 is A=4,B=2,C=2,D=2A = 4, B = 2, C = 2, D = 2.
  2. Axes: categories A to D along the bottom, frequency from 0 to 5 up the side.
  3. Draw bars of height 4, 2, 2 and 2, separated by gaps.
  4. Label the bars A to D, the horizontal axis “Category” and the vertical axis “Frequency”.

Using the relative frequencies instead gives the same shape with the vertical axis running 0 to 0.4.

4.4Bar chart in a Google Sheet

  1. Select (highlight) the cells that have the data you want to visualise.
  2. Click the Insert chart option in the toolbar.
  3. Change the visualisation type in the Chart editor.
  4. Set the Chart type to Bar chart.

4.5Going deeper: what to remember about bar charts

  1. A bar chart shows the frequencies or relative frequencies of a categorical variable.
  2. If the variable is ordinal, the order of the categories is preserved. The bars are not re-sorted (Chapter 5).
  3. The bars can be vertical or horizontal. The rule that matters is that bar length is proportional to the value.
  4. Bars must not touch. That is what separates a bar chart (categories) from a histogram (numbers on a continuous scale, a later topic).
Common mistakes
  • Drawing the bars touching each other.
  • Leaving the axes unlabelled.
  • Starting the vertical axis above zero (Chapter 6).

Practice questions (graded-assignment style)

Q1Bars in a bar chart

Multiple Choice Question (MCQ): choose the one correct option.

In a bar chart of a categorical variable, the bars should

1
touch each other, like a histogram
2
be separated so that they do not touch
3
always be sorted by height
4
always be vertical
Solution
Idea

The gaps show the categories are separate groups.

  • Option 1 is wrong: touching bars belong to a histogram.
  • Option 3 is wrong: ordinal variables keep their natural order.
  • Option 4 is wrong: the lecture says bars can be horizontal or vertical.
  • Answer: option 2.
Q2A relative-frequency bar

Numerical Answer Type (NAT).

Data set 4 has 18 observations with frequencies A = 6, B = 3, C = 4, D = 5. In a bar chart of relative frequencies, what is the height of the bar for D? Give the answer to three decimal places.

Solution
Idea

Divide the frequency by the total.

  • 5÷18=0.2777…5 \div 18 = 0.2777\ldots
  • To three decimal places: 0.2780.278.
  • Answer: 0.278
Q3Bar chart facts

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
The vertical axis can show frequency or relative frequency.
2
The bars can be horizontal.
3
The bars of a bar chart should touch.
4
For an ordinal variable the order of the categories is preserved.
Solution
Idea

Recall the definition and the summary points.

  • Options 1, 2 and 4 are all stated in the lecture.
  • Option 3 is wrong: the bars should not touch.
  • Answer: options 1, 2 and 4.
Q4Frequency versus relative frequency chart

Multiple Choice Question (MCQ): choose the one correct option.

A bar chart of frequencies and a bar chart of relative frequencies are drawn for the same data. How do they compare?

1
They have the same shape but different vertical scales.
2
They have different shapes.
3
They have the same vertical scale but different shapes.
4
Only the frequency chart can be drawn.
Solution
Idea

Dividing every frequency by the same total keeps all the ratios between bars.

  • Every bar is divided by the same number, so the pattern does not change; only the axis labels do.
  • Answer: option 1.
Next · Lecture 2.2Pareto Charts and Ordinal Data
05
Lecture 2.2

Pareto Charts and Ordinal Data

DefinitionWhen the categories in a bar chart are sorted by frequency, the bar chart is sometimes called a Pareto chart. Pareto charts are popular in quality control to identify problems in a business process.
Ordinal variablesIf the categorical variable is ordinal, the bar chart must preserve the ordering. A bar chart of an ordinal variable is therefore not re-sorted into a Pareto chart.

5.1Lecture example: a Pareto chart

Data (15 observations): A, B, B, C, A, D, B, B, A, C, B, B, C, D, A.

CategoryFrequencyRelative freqAs printed on the slide
A44/15 = 0.2670.26
B66/15 = 0.4000.40
C33/15 = 0.2000.20
D22/15 = 0.1330.14
Total1511

The slide prints 0.26, 0.40, 0.20, 0.14 so that the column adds up to exactly 1. The exact values are 4/15=0.2674/15 = 0.267 and 2/15=0.1332/15 = 0.133 (rounded to three decimals), which is why the third column is shown with three decimals.

  1. Sort the categories by frequency: B (6), A (4), C (3), D (2).
  2. Draw the bars in that order, tallest first.
012345676B4A3C2DCategory (sorted by frequency)Frequency
Figure 5. Pareto chart: the categories are sorted from the highest frequency to the lowest

5.2Lecture example: ordinal data

The T-shirt sizes (Small S, Medium M, Large L) of twenty students are L, M, M, S, L, S, S, M, L, M, M, S, S, L, M, S, M, S, L, M. Make the frequency table and the bar chart.

SizeFrequencyRelative freq
Small77 ÷ 20 = 0.35
Medium88 ÷ 20 = 0.40
Large55 ÷ 20 = 0.25
Total201

Check: 7+8+5=207 + 8 + 5 = 20. Size is ordinal (Small < Medium < Large), so the bars keep this order and are not sorted by height.

02468107Small8Medium5LargeT-shirt size (ordinal: Small < Medium < Large)Frequency
Figure 6. Bar chart of an ordinal variable: the natural order is kept, even though Medium is the tallest bar

5.3Pareto or ordered bars?

Nominal categories
  • No natural order.
  • Sort by frequency to get a Pareto chart.
Ordinal categories
  • A natural order exists.
  • Keep that order along the horizontal axis.
Exam tips
  • Ask first: is the variable nominal or ordinal? That decides whether sorting is allowed.
  • In a Pareto chart the heights fall from left to right.
Common mistakes
  • Sorting the S, M, L bars by height. This destroys the order of the sizes.
  • Sorting from lowest to highest in a Pareto chart.

Practice questions (graded-assignment style)

Q1Sort or not?

Multiple Choice Question (MCQ): choose the one correct option.

A bar chart is drawn for the grades Poor, Fair, Good and Excellent (an ordinal variable). Should the bars be sorted by height?

1
Yes, always
2
No, the natural order of the grades must be kept
3
Yes, but only from lowest to highest
4
It does not matter
Solution
Idea

Ordinal categories keep their natural order.

  • Sorting by height would put the grades in a meaningless order.
  • Answer: option 2.
Q2The second bar

Multiple Choice Question (MCQ): choose the one correct option.

A nominal variable has frequencies A = 3, B = 7, C = 5, D = 2. In its Pareto chart, which category gets the second bar from the left?

1
A
2
B
3
C
4
D
Solution
Idea

Sort from the highest frequency to the lowest.

  • Sorted order: B (7), C (5), A (3), D (2).
  • The second bar is C.
  • Answer: option 3.
Q3Pareto facts

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
A Pareto chart is a bar chart sorted by frequency.
2
Pareto charts are popular in quality control.
3
An ordinal variable should be sorted by frequency.
4
In a Pareto chart the bar heights fall from left to right.
Solution
Idea

Recall the definition.

  • Options 1, 2 and 4 follow from the definition and the lecture.
  • Option 3 is wrong: ordinal bars keep their natural order.
  • Answer: options 1, 2 and 4.
Q4Height of a bar

Numerical Answer Type (NAT).

The frequencies of a nominal variable are A = 4, B = 6, C = 3, D = 2. In the Pareto chart, what is the height of the second bar from the left?

Solution
Idea

Sort first, then read the second value.

  • Sorted: 6 (B), 4 (A), 3 (C), 2 (D).
  • The second bar has height 4.
  • Answer: 4
Next · Lectures 2.3 and 2.4Best Practices and Misleading Graphs
06
Lectures 2.3 and 2.4

Best Practices and Misleading Graphs

6.1Know your purpose

Have a purpose for every table or graph you create, and choose the table or graph to serve that purpose.

Pie chart: parts of a whole
  • Best when you are trying to compare parts of a whole.
Bar chart: groups against each other
  • Used to compare things between different groups.

6.2Label your data

  • Label your chart to show the categories and indicate whether some have been combined or omitted.
  • Name the bars in a bar chart.
  • Name the slices in a pie chart.
  • If you have omitted some of the cases, make sure the label of the plot defines the collection that is summarised.

Example: the same grades, grade A = 7, B = 3, C = 7, D = 2 (19 students), drawn both ways with a title, named slices or bars, and labelled axes. The relative frequencies are 7/19=36.8%7/19 = 36.8\%, 3/19=15.8%3/19 = 15.8\%, 7/19=36.8%7/19 = 36.8\% and 2/19=10.5%2/19 = 10.5\%.

A36.8%B15.8%C36.8%D10.5%024687A3B7C2DGrade categoryCount
Figure 7. Distribution of grades: both charts have named slices or bars and labelled axes

6.3Many categories

A bar chart or pie chart with too many categories might conceal the more important categories. In some cases, grouping the other categories together helps.

Example: a variable has 26 categories A to Z with counts A = 11, B = 6, C = 9, D = 4 and one case in each of E to Z. The 22 single-case categories are drawn as 22 tiny bars that crowd the chart and hide the four categories that matter. Grouping E to Z gives 22×1=2222 \times 1 = 22 cases, so the new category Others has count 22 and the chart has five clear bars.

0481211A6B9C4D1E1F1G1H1I1J1K1L1M1N1O1P1Q1R1S1T1U1V1W1X1Y1ZCategoryCount
Figure 8. All 26 categories: the main categories are hard to see
051015202511A6B9C4D22OthersCategoryCount
Figure 9. After grouping E to Z as Others: A, B, C, D and Others

6.4The area principle and decorated graphs

The area principleDisplays of data must obey a fundamental rule called the area principle: the area occupied by a part of the graph should correspond to the amount of data it represents. Violations of the area principle are a common way to mislead with statistics.

Decorated graphics. Charts decorated to attract attention often violate the area principle. Example: total U.S. wine exports (millions of dollars): United Kingdom 150.3, Canada 146.8, Japan 82.8, Italy 42.5, Netherlands 34.4. A decorated graphic with bottles on top of boxes of various sizes and shapes and no baseline breaks the principle, because the size of a box does not correspond to its value.

04080120160150.3UK146.8Canada82.8Japan42.5Italy34.4Neth.CountryValue (millions of $)
Figure 10. The plain bar chart has a zero baseline and equal-width bars, so each height is proportional to the value: it obeys the area principle

6.5Truncated graphs

Another common violation is when the baseline of a bar chart is not at zero. Example: regionwise counts South 146, West 97, North 146, East 111. If the vertical axis starts at 75, the visible bar heights are 146−75=71146 - 75 = 71, 97−75=2297 - 75 = 22, 146−75=71146 - 75 = 71 and 111−75=36111 - 75 = 36. The South bar then looks about 71/22≈3.271/22 \approx 3.2 times the West bar, but the true ratio is only 146/97≈1.5146/97 \approx 1.5.

75100125150146S97W146N111ERegion (baseline at 75)Count050100150146S97W146N111ERegion (baseline at 0)Count
Figure 11. Same data: the left graph (baseline 75) exaggerates South and North; the right graph has the baseline at zero
Indicating a y-axis breakIf a truncated axis is unavoidable, use a special symbol (a zig-zag break mark) on the vertical axis to show that it has been modified, so the reader knows the scale starts at 75, not 0. In the lecture file this slide carries only the heading; the zig-zag in the left graph above is the usual break mark.

6.6Round-off errors

When table entries are percentages or proportions, the total may sum to a value slightly different from 100% or 1. This might result in a pie chart where the total does not add up. Example: Samsung 20%, Apple 15%, Nokia 14%, HTC 11%, RIM 10%, Others 31%. Then 20+15+14+11+10+31=10120 + 15 + 14 + 11 + 10 + 31 = 101, so the labels total 101% instead of 100%.

Samsung20%Apple15%Nokia14%HTC11%RIM10%Others31%
Figure 12. The rounded percentages add to 101%: always add up the labels before publishing a chart

Each share was rounded to a whole percent, so the total drifted from 100%.

6.7Going deeper: a checklist before you trust a graph

  1. Purpose: parts of a whole (pie) or groups against each other (bar)?
  2. Labels: title, named slices or bars, labelled axes, and a note on anything combined or omitted.
  3. Categories: too many? Group the small ones into Others.
  4. Area principle: no decoration that changes sizes, and the baseline at zero (or a break mark).
  5. Round-off: do the labels add to 100% (or 1)?
Common mistakes
  • Judging bar sizes by eye on a truncated axis.
  • Using a pie chart for many tiny categories.
  • Forgetting that rounded percentages may not add to exactly 100%.

Practice questions (graded-assignment style)

Q1The true ratio

Numerical Answer Type (NAT).

A bar chart has its vertical axis starting at 75 and shows counts 146 and 97 for two regions. What is the true ratio of the two counts, 146÷97146 \div 97, to one decimal place?

Solution
Idea

Use the real counts, not the visible heights.

  • 146÷97=1.505…146 \div 97 = 1.505\ldots
  • To one decimal place: 1.51.5. The truncated chart makes it look like 71÷22≈3.271 \div 22 \approx 3.2.
  • Answer: 1.5
Q2Do the labels add up?

Numerical Answer Type (NAT).

A pie chart has three slices each labelled 33%. What do the labels add up to, in percent?

Solution
Idea

Add the labels.

  • 33+33+33=9933 + 33 + 33 = 99.
  • Each slice is really 33.33…%33.33\ldots\%; rounding makes the total 99%, not 100%.
  • Answer: 99
Q3Misleading graphs

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
The area occupied by a part of a graph should correspond to the amount of data it represents.
2
A truncated vertical axis can exaggerate differences between bars.
3
Decorated graphics are always better because they attract attention.
4
Many tiny categories can be grouped together as Others.
Solution
Idea

Recall the area principle.

  • Options 1, 2 and 4 are stated in the lecture.
  • Option 3 is wrong: decorated graphics often violate the area principle.
  • Answer: options 1, 2 and 4.
Q4Group the small categories

Numerical Answer Type (NAT).

A variable has 11 categories with counts A = 14, B = 9, C = 6 and 8 further categories with one case each. If the 8 single-case categories are grouped as Others, what is the count of Others?

Solution
Idea

Add the single-case categories.

  • 8×1=88 \times 1 = 8.
  • The chart then has four bars: A, B, C and Others.
  • Answer: 8
Next · Lecture 2.5Mode
07
Lecture 2.5

Mode

Bar charts and pie charts are graphical summaries of categorical data. Sometimes we want a single label that sums up the data set. Numbers used to describe data sets are called descriptive measures; those that indicate where the center or most typical value lies are called measures of central tendency.

Definition: modeThe mode of a categorical variable is the most common category, the category with the highest frequency.

7.1Where the mode shows up in a chart

  • It labels the longest bar in a bar chart.
  • It labels the widest slice in a pie chart.
  • In a Pareto chart, the mode is the first category shown.
024686A3B4C2DCategoryCountA40%B20%C26.7%D13.3%
Figure 13. One data set, two charts, the same mode (A): the longest bar and the widest slice

7.2Lecture example: finding the mode

Find the mode of A, A, B, C, A, D, A, B, C, C, A, B, C, D, A.

  1. Count each category: A=6,B=3,C=4,D=2A = 6, B = 3, C = 4, D = 2 (total 6+3+4+2=156 + 3 + 4 + 2 = 15).
  2. The highest frequency is 6, for A.

The most common category is A, so the mode is A. This is the longest bar in the figure above.

7.3Bimodal and multimodal data

TiesIf two or more categories tie for the highest frequency, the data are said to be bimodal (two) or multimodal (more than two).

Example: A, A, B, C, A, C, A, B, C, C, A, C, C, D, A, A, C, D, B. The counts are A=7,B=3,C=7,D=2A = 7, B = 3, C = 7, D = 2 (total 7+3+7+2=197 + 3 + 7 + 2 = 19). The highest frequency, 7, is shared by A and C, so the data are bimodal.

03697A3B7C2DCategoryCount
Figure 14. Two bars of equal, greatest height: the data are bimodal

7.4Going deeper: what the mode can and cannot do

  1. The mode works for any categorical data, ordinal or not. It only needs counts.
  2. The mode is a category, not a number. The answer is “A”, not “6”. The 6 is the frequency of the mode.
  3. A data set can have more than one mode (bimodal or multimodal) when categories tie.
Exam tips
  • Write the category, then its frequency in brackets: “mode is A (6 times)”.
  • If the top two frequencies are equal, say bimodal and name both categories.
Common mistakes
  • Answering with the frequency (6) instead of the category (A).
  • Naming only one category when two tie.

Practice questions (graded-assignment style)

Q1Find the mode

Multiple Choice Question (MCQ): choose the one correct option.

The observations are R, G, B, G, G, R, B, G. What is the mode?

1
R
2
G
3
B
4
There is no mode
Solution
Idea

Count each category.

  • R = 2, G = 4, B = 2 (total 8).
  • G has the highest frequency, 4.
  • Answer: option 2.
Q2Bimodal or not?

Multiple Choice Question (MCQ): choose the one correct option.

The frequencies of four categories are A = 5, B = 7, C = 7, D = 3. The data are

1
unimodal with mode B
2
unimodal with mode C
3
bimodal with modes B and C
4
multimodal with modes A, B, C and D
Solution
Idea

Look for a tie at the top.

  • The highest frequency, 7, belongs to both B and C.
  • Answer: option 3.
Q3Mode facts

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
The mode is the most common category.
2
The mode works for ordinal and nominal variables.
3
In a Pareto chart the mode is the first category shown.
4
A data set can have only one mode.
Solution
Idea

Recall the definition and the chart links.

  • Options 1, 2 and 3 are correct.
  • Option 4 is wrong: ties give bimodal or multimodal data.
  • Answer: options 1, 2 and 3.
Q4How many modes?

Numerical Answer Type (NAT).

The frequencies are A = 8, B = 11, C = 11, D = 9. How many modes does the data set have?

Solution
Idea

Count the categories that share the highest frequency.

  • The highest frequency is 11, shared by B and C.
  • Answer: 2
Next · Lecture 2.5Median for Ordinal Data
08
Lecture 2.5

Median for Ordinal Data

Ordinal data offer another summary, the median, that is not available unless the data can be put into order.

Definition: medianThe median of an ordinal variable is the category of the middle observation of the sorted values. If there are an even number of observations, choose the category on either side of the middle of the sorted list as the median.

8.1Three steps to the median

  1. Put in order. Sort the observations by their natural order.
  2. Find the middle. Odd count: one middle value. Even count: two middle values.
  3. Read its category. The category there is the median. Either side is fine when the count is even.
position of the middle=n+12\text{position of the middle} = \frac{n + 1}{2}

For 15 observations the middle is the 8th. For 14 observations the two middle observations are the 7th and the 8th.

8.2Lecture examples

15 grades: the median is the 8th observation

Grades: A, B, B, C, A, D, B, B, A, C, B, B, C, D, A. In grade order A, B, C, D the sorted data are A,A,A,A,B,B,B,B,B,B,C,C,C,D,D.

A1A2A3A4B5B6B7B8B9B10C11C12C13D14D15
Figure 15. The middle of 15 values is the (15 + 1) / 2 = 8th: it is B, so the median grade is B

The most common grade is B (6 times), so the mode is also B. In this example the mode and the median are the same.

14 grades: two middle observations

Grades: A, B, B, C, A, D, B, B, A, C, B, B, C, D. Sorted: A,A,A,B,B,B,B,B,B,C,C,C,D,D. With 14 observations the two middle ones are the 7th and the 8th. Both are B, so the median grade is B.

A1A2A3B4B5B6B7B8B9C10C11C12D13D14
Figure 16. Even count: the 7th and the 8th are both B

15 grades where the mode and the median differ

Grades: A, B, B, C, A, D, A, B, A, C, B, A, C, D, A. Sorted: A,A,A,A,A,A,B,B,B,B,C,C,C,D,D. The first six are A and the next four are B, so the 8th observation is B and the median is B. The most common grade is A (6 times), so the mode is A.

A1A2A3A4A5A6B7B8B9B10C11C12C13D14D15
Figure 17. Mode (A) and median (B) can differ

8.3Going deeper: why only ordinal data?

  1. Sorting needs a natural order. Nominal categories (colours, cities) have none, so “the middle one” has no meaning.
  2. Always sort first. Reading the 8th item of the unsorted list is the commonest slip.
  3. Mode and median answer different questions. The mode is the most common category; the median is the category of the middle observation. They can be the same or different.
Exam tips
  • Write the sorted list as a run of letters and count to the middle position.
  • Check that your sorted list has the same number of letters as observations.
Common mistakes
  • Taking the middle of the unsorted list.
  • Sorting in the wrong order (the order must be the natural order of the grades).
  • Computing a median for a nominal variable.

Practice questions (graded-assignment style)

Q1Position of the median

Numerical Answer Type (NAT).

A sorted ordinal data set has 21 observations. At which position is the median observation?

Solution
Idea

Use (n+1)/2(n+1)/2.

  • (21+1)/2=11(21 + 1)/2 = 11.
  • Answer: 11
Q2Even number of observations

Multiple Choice Question (MCQ): choose the one correct option.

An ordinal data set has 14 observations. The median is the category at

1
the 7th position only
2
the 7th or the 8th position (either side of the middle)
3
the 14th position
4
the 2nd position
Solution
Idea

With an even count there are two middle observations.

  • The two middle observations are the 7th and the 8th; the lecture allows either side.
  • Answer: option 2.
Q3Median grade

Multiple Choice Question (MCQ): choose the one correct option.

Grades of 15 students, in the order A < B < C < D: there are 2 A's, 3 B's, 5 C's and 5 D's. What is the median grade?

1
A
2
B
3
C
4
D
Solution
Idea

Sort, then find the 8th observation.

  • Sorted: A at 1 to 2, B at 3 to 5, C at 6 to 10, D at 11 to 15.
  • The 8th observation falls in the C block (positions 6 to 10).
  • Answer: option 3.
Q4Median facts

Multiple Select Question (MSQ): select all that apply.

Choose the correct statements.

1
The median applies only when the categories can be put in order.
2
The data must be sorted by the natural order before finding the median.
3
With an even number of observations, the category on either side of the middle may be taken as the median.
4
The median can be computed for a nominal variable such as colour.
Solution
Idea

The median needs sorting.

  • Options 1, 2 and 3 are correct.
  • Option 4 is wrong: nominal categories have no natural order.
  • Answer: options 1, 2 and 3.
Next · All lecturesWeek 2 Summary Sheet
09
All lectures

Week 2 Summary Sheet

Everything in Week 2 on one sheet, topic by topic, for a last-minute revision.

What each tool is for

ToolWhat it showsWorks for
Frequency tableCounts of each categoryAny categorical variable
Relative frequency tableProportion of each category; compare data setsAny categorical variable
Pie chartParts of a whole; shows if one category is over halfAny categorical variable
Bar chartCompare groups; bars separated; either orientationAny; keep the order if ordinal
Pareto chartBar chart sorted by frequency (quality control)Nominal categories
ModeMost common categoryAny categorical variable
MedianCategory of the middle observation after sortingOrdinal only

Formulas and rules

Relative frequency
  • relative frequency = frequency ÷ total
  • All relative frequencies add to 1.
Pie slice angle
  • angle = relative frequency × 360°
  • All angles add to 360°.
Median position
  • Position = n+12\frac{n+1}{2}.
  • 15 observations: the 8th. 14 observations: the 7th or 8th.
Graph checks
  • Baseline at zero (or a break mark).
  • Labels add up (round-off).
  • Area matches the amount of data.

Topic by topic

Tabulate data
  • Frequency table: list, tally, count.
  • Relative frequency = frequency / total.
Charts of categorical data
  • Pie chart: slices from relative frequency.
  • Bar chart and Pareto chart (sorted).
  • Ordinal data keep their order.
Best practices
  • Know your purpose, label your data.
  • Group many small categories.
  • Area principle; avoid decorated and truncated graphs; check round-off.
Mode and median
  • Mode: most common category; bimodal or multimodal when tied.
  • Median: ordinal data only; middle observation of the sorted data.
Revision overview
Tabulate dataFrequency table: tally and count
Relative frequency = frequency / total
ChartsPie chart: slices from relative frequency
Bar chart and Pareto chart (sorted)
Ordinal data keep their order
Best practicesKnow your purpose, label your data
Group many small categories
Area principle
Describing categorical dataStatistics for Data Science 1
Misleading graphsDecorated graphics
Truncated axis (use a break mark)
Round-off errors
ModeMost common category
Bimodal or multimodal when tied
MedianOrdinal data only
Middle observation of the sorted data
Revision: the whole of Week 2 on one map
Back to top