Weeks
Statistics 1Week 3 · Describing Numerical Data: Mean, Median, Spread and Percentiles
Week 3 Notes

Statistics for
Data Science 1

Describing numerical data: frequency tables, histograms, mean, median, mode, spread and percentiles.

11 chapters~35 min read
HistogramsMean, median, modeVariance and SDPercentiles and IQR

Chapters

  1. 01Frequency Tables for Numerical DataLecture 3.1
  2. 02HistogramsLecture 3.1
  3. 03Stem-and-Leaf DiagramsLecture 3.1
  4. 04MeanLecture 3.2
  5. 05MedianLecture 3.3
  6. 06ModeLecture 3.3
  7. 07Measures of Dispersion and RangeLecture 3.4
  8. 08Variance and Standard DeviationLecture 3.4
  9. 09PercentilesLecture 3.5
  10. 10Quartiles, Five-Number Summary and IQRLecture 3.5
  11. 11Week 3 Summary SheetAll lectures

Based on lectures by Usha Mohan, IIT Madras

01
Lecture 3.1

Frequency Tables for Numerical Data

To describe numerical data we first group the observations into classes (also called categories or bins) and then treat the classes as the distinct values of qualitative data. Once the data are grouped, the frequency and relative-frequency tables are built exactly as in Week 2.

DefinitionA numerical variable is discrete if it usually involves a count of something, and continuous if it usually involves a measurement of something. The type decides how the data are organised: single values for discrete data, class intervals for continuous data.

1.1Where Week 3 starts

The lecture begins with a review of Weeks 1 and 2, and then splits variables by type. Weeks 1 and 2 dealt with categorical variables; this week is about numerical ones.

VariableCategoricalWeeks 1 and 2Numericalthis weekDiscreteusually a countContinuoususually a measurement
Figure 1. Types of variables: numerical variables are discrete or continuous
Review: Weeks 1 and 2
  • Descriptive and inferential statistics; sample and population.
  • Variables and cases; categorical or numerical; cross-sectional or time-series.
  • Measurement scales: nominal, ordinal, interval, ratio.
  • Frequency tables, relative frequency, pie and bar charts, mode and median.
This week: Week 3
  • Frequency tables and graphical summaries (histograms, stem-and-leaf).
  • Numerical summaries: mean, median, mode.
  • Dispersion: range, variance, standard deviation.
  • Percentiles and the interquartile range.

1.2Organising numerical data

Raw numbers are hard to read. We group them into classes, and then every class plays the role that a category played in Week 2.

NumericaldatarawobservationsGroup intoclassesalso calledcategories or binsTreat classesas valueslikequalitative dataFrequencytableand relativefrequency
Figure 2. Grouping turns numerical data into something a frequency table can handle

1.3Discrete data: single-value classes

If the data set contains only a relatively small number of distinct values, it is convenient to represent it in a frequency table. Each class represents a distinct value (a single value) along with its frequency of occurrence.

Lecture example: number of people in a household

The responses of 15 individuals to the number of people in their household: 2, 1, 3, 4, 5, 2, 3, 3, 3, 4, 4, 1, 2, 3, 4

  1. List the distinct values: 1, 2, 3, 4 and 5.
  2. Tally each response in the row of its value.
  3. Count the tallies and divide each frequency by the total, 15.
ValueTallyFrequencyRelative frequency
1||22 ÷ 15 = 0.133
2|||33 ÷ 15 = 0.2
3||||55 ÷ 15 = 0.333
4||||44 ÷ 15 = 0.267
5|11 ÷ 15 = 0.067
Total151

Check: 2+3+5+4+1=152 + 3 + 5 + 4 + 1 = 15 and the relative frequencies add to 1 (to three decimals: 0.133+0.2+0.333+0.267+0.067=10.133 + 0.2 + 0.333 + 0.267 + 0.067 = 1).

01234562132534415Number of people in the householdFrequency
Figure 3. Frequencies of household sizes
Reading the figure

The lecture shows an empty grid for this table; the graph of the frequencies is a bar graph over the five values. The tallest bar is at 3, so a household of three people is the most common answer.

1.4Continuous data: class intervals

For continuous data (or discrete data with many distinct values) the values are organised into class intervals, so that the table becomes understandable. A few guidelines have to be followed.

Lower class limit
  • The smallest value that could go in a class.
Upper class limit
  • The largest value that could go in a class.
Class width
  • The difference between the lower limit of a class and the lower limit of the next-higher class.
Class mark
  • The average of the two class limits of a class (its mid point).
Boundary ruleA class interval contains its left-end but not its right-end boundary point. So a mark of exactly 60 belongs to the class 60-70, not to 50-60.
40506070class 50-60Lower limit = 50filled: 50 is inUpper limit = 60open: 60 is not inClass mark = (50 + 60) / 2 = 55, class width = 60 - 50 = 10
Figure 4. The class 50-60: its limits, class mark and class width
Reading the diagram

The filled dot at 50 means 50 is included; the open dot at 60 means 60 is not. The lower limit is 50, the next class starts at 60, so the width is 10, and the class mark is the midpoint, 55. With the left-end rule, 60 itself belongs to the next class, so the class holds values from 50 up to just below 60.

Guidelines for forming classes

  1. Number of classes. The appropriate number is a subjective choice; the rule of thumb is to have between 5 and 20 classes.
  2. No overlaps, no gaps. Each observation should belong to some class and no observation should belong to more than one class.
  3. Equal lengths. It is common, although not essential, to choose class intervals of equal length.

1.5Lecture example: marks of 50 students

The marks of 50 students in a course are listed below. Group them into class intervals of width 10 and build the frequency and relative-frequency table.

68, 79, 38, 68, 35, 70, 61, 47, 58, 66, 60, 45, 61, 60, 59, 45,
39, 80, 59, 62, 49, 76, 54, 60, 53, 55, 62, 58, 67, 55, 86, 56,
63, 64, 67, 50, 51, 78, 56, 62, 57, 69, 58, 52, 42, 66, 42, 56, 58

  1. The smallest mark is 35 and the largest 86, so the classes 30-40, 40-50, 50-60, 60-70, 70-80, 80-90 (six classes, width 10) cover everything. The left-end rule decides the boundary values.
  2. Put each mark in its class and tally.
  3. Count and divide by 50.
Class intervalFrequencyRelative frequency
30-4033 ÷ 50 = 0.06
40-5066 ÷ 50 = 0.12
50-601818 ÷ 50 = 0.36
60-701717 ÷ 50 = 0.34
70-8044 ÷ 50 = 0.08
80-9022 ÷ 50 = 0.04
Total501

Check: 3+6+18+17+4+2=503 + 6 + 18 + 17 + 4 + 2 = 50 and 0.06+0.12+0.36+0.34+0.08+0.04=10.06 + 0.12 + 0.36 + 0.34 + 0.08 + 0.04 = 1.

A discrepancy in the slideThe printed list has only 49 marks. Counting those 49 gives 17 marks in 50-60 (not 18), so one mark between 50 and 59 is missing from the printed list. The slide's table (total 50, with 18 in 50-60) is used here and in the later histogram and mean calculations, because the mean 58.8 in Lecture 3.2 is computed from this table.

1.6Going deeper: choosing the classes

  1. Start from the extremes. Find the smallest and largest value; the classes must cover both. Here 35 and 86 sit inside 30-90.
  2. A handy width. A common way to pick the width is (largest - smallest) ÷ (number of classes wanted), rounded up to a convenient number like 5 or 10. Here (86 - 35) ÷ 6 = 8.5, rounded up to 10. This is a practical tip, not a rule from the lecture.
  3. Why the left-end rule matters. Without it a mark such as 60 could be counted twice (in 50-60 and in 60-70). The rule gives every mark exactly one class.
  4. Grouping loses detail. Once marks are put in a class we only know the class, not the exact mark. That is why the mean from a grouped table (Chapter 4) is only approximate.
Exam tips
  • Decide first: discrete (count, few values) or continuous (measurement, class intervals).
  • Always write the total row and check it equals the number of observations (and the relative frequencies add to 1).
  • For a boundary value, the class that starts at it wins: 60 goes to 60-70.
Common mistakes
  • Putting 60 in the class 50-60.
  • Using classes that overlap or leave gaps.
  • Calling a count a continuous variable (number of siblings is discrete).
  • Forgetting that class mark = (lower + upper) ÷ 2.
Next · Lecture 3.1Histograms
02
Lecture 3.1

Histograms

A histogram is the graph of a frequency (or relative-frequency) table of grouped numerical data: one vertical bar per class, with the classes placed on a number line.

2.1Steps to construct a histogram

  1. Frequency distribution. Obtain a frequency (relative-frequency) distribution of the data.
  2. Axes. Draw a horizontal axis on which to place the classes and a vertical axis on which to display the frequencies (relative frequencies).
  3. Bars. For each class, construct a vertical bar whose height equals the frequency (relative frequency) of that class.
  4. Labels. Label the bars with the classes, the horizontal axis with the name of the variable, and the vertical axis with “Frequency” (“Relative frequency”).

2.2Lecture example: histogram of the 50 marks

Use the frequency table from Chapter 1.

Class intervalFrequency
30-403
40-506
50-6018
60-7017
70-804
80-902

The lecture gives axes with the horizontal scale 30 to 100 and the vertical scale 1 to 18, ready for the bars. Draw a bar over each class with height 3, 6, 18, 17, 4, 2.

024681012141618203618174230405060708090Marks (class intervals)Frequency
Figure 5. Histogram of the marks of 50 students
Reading the figure

Each bar sits over its class on the number line, so neighbouring bars meet at the class boundaries (40, 50, 60, ...). The tallest bars are over 50-60 and 60-70, so most marks are in the fifties and sixties; very few marks are above 70.

2.3Histogram versus bar chart

Bar chart (Week 2)Histogram (Week 3)
DataCategoricalNumerical, grouped into classes
Horizontal axisSeparate categoriesA number line with class intervals
BarsSeparated by gapsTouch at the class boundaries
Bar heightFrequency (or relative frequency)Frequency (or relative frequency)

2.4Going deeper: relative-frequency histogram and shape

If the bar heights are the relative frequencies instead of the frequencies, the shape is exactly the same, only the vertical scale changes. This is the same idea as in Week 2: relative frequencies let us compare data sets of different sizes.

00.10.20.30.40.060.120.360.340.080.0430405060708090Marks (class intervals)Relative frequency
Figure 6. Same histogram with relative frequencies: the shape does not change
  1. Where is the peak? The tallest bars show where most observations lie. Here, between 50 and 70.
  2. How spread out? The bars run from 30 to 90, so the marks are spread over about 60 points.
  3. Different class widths change the picture. Very narrow classes give a jagged histogram; very wide classes hide the pattern. That is why the 5 to 20 classes rule of thumb exists.
Exam tips
  • Label both axes: the variable under the bars, “Frequency” or “Relative frequency” on the vertical axis.
  • To read the number of observations in several classes, add the bar heights.
  • If the bars are relative frequencies, multiply by n to get back the frequency.
Common mistakes
  • Leaving gaps between the bars of a histogram (that is a bar chart).
  • Using a different width for one class without noticing.
  • Putting counts on the vertical axis but labelling it “Relative frequency”.
Next · Lecture 3.1Stem-and-Leaf Diagrams
03
Lecture 3.1

Stem-and-Leaf Diagrams

DefinitionIn a stem-and-leaf diagram (or stemplot), each observation is separated into two parts: a stem, consisting of all but the rightmost digit, and a leaf, the rightmost digit.

For example, if the data are all two-digit numbers, we can let the stem of a value be the tens digit and the leaf be the ones digit.

One value: 75
  • Stem 7, leaf 5.
  • 7 | 5 means 75
Two values: 75 and 78
  • Same stem, so the leaves share a row.
  • 7 | 5 8 means 75 and 78

3.1Steps to construct a stemplot

  1. Split. Think of each observation as a stem (all but the rightmost digit) and a leaf (the rightmost digit).
  2. Stems. Write the stems from smallest to largest in a vertical column to the left of a vertical rule.
  3. Leaves. Write each leaf to the right of the vertical rule in the row that contains the appropriate stem.
  4. Sort. Arrange the leaves in each row in ascending order.

3.2Lecture example: ages of 11 patients

The ages, to the nearest year, of 11 patients admitted in a hospital are given. Draw a stem-and-leaf plot for this data set. 15, 22, 29, 36, 31, 23, 45, 10, 25, 28, 48

  1. Split each age: 15 = stem 1, leaf 5; 22 = stem 2, leaf 2; 29 = stem 2, leaf 9; and so on.
  2. The stems run from 1 (ages 10 to 19) to 4 (ages 40 to 49): 1, 2, 3, 4.
  3. Write the leaves in the order the data are given.
  4. Arrange the leaves in each row in ascending order.

Step 3: leaves in data order

StemLeaf
15  0
22  9  3  5  8
36  1
45  8

2 | 2 means 22

Step 4: leaves sorted

StemLeaf
10  5
22  3  5  8  9
31  6
45  8

2 | 2 means 22; 4 | 8 means 48

Check: the number of leaves is 2+5+2+2=112 + 5 + 2 + 2 = 11, the number of patients.

A note on the slideThe lecture slide poses this question but does not show the finished plot; the plot above is worked out from the steps on the slide.
Reading the plot

Each row is an age decade. Row 2 has five leaves, so five of the eleven patients are in their twenties. Rotated sideways, the rows look like the bars of a histogram, but every individual value is still readable.

3.3Going deeper: stemplot versus histogram

  • Keeps the data. A histogram shows only how many values fall in a class; a stemplot also keeps every value. From the plot above you can still read the oldest patient (48) and the youngest (10).
  • Sorted for free. With the leaves in order, the data are already sorted, which makes the median (Chapter 5) and percentiles (Chapter 9) easy to find.
  • Always give the key. Write “2 | 2 means 22” so the reader knows what the stem and leaf stand for.
  • Three-digit data. For 135, the stem is 13 (all but the rightmost digit) and the leaf is 5.
Exam tips
  • Count the leaves at the end: the total must equal the number of observations.
  • Include stems that have no leaves if they fall inside the range (they show a gap in the data).
Common mistakes
  • Leaving the leaves unsorted (Step 4).
  • Writing the leaf as a two-digit number; a leaf is a single digit.
  • Forgetting the key.
Next · Lecture 3.2Mean
04
Lecture 3.2

Mean

Central tendency
  • Where is the centre?
  • Measures that indicate the most typical value or centre of a data set: mean, median, mode.
Dispersion
  • How spread out?
  • Measures that indicate the variability or spread of a data set: range, variance, standard deviation, interquartile range.

The objective is to develop descriptive measures: quantities whose values are determined by the data, used to summarise a data set. We start with the most common one, the mean.

Definition: meanThe mean of a data set is the sum of the observations divided by the number of observations. It is usually referred to as the average (the arithmetic average).
Sample mean (n observations)
xˉ=x1+x2+⋯+xnn\bar{x} = \frac{x_1 + x_2 + \cdots + x_n}{n}
Population mean (N observations)
μ=x1+x2+⋯+xNN\mu = \frac{x_1 + x_2 + \cdots + x_N}{N}

4.1Lecture examples: the mean of small data sets

Example 1. Find the mean of 2, 12, 5, 7, 6, 7, 3.

xˉ=2+12+5+7+6+7+37=427=6\bar{x} = \frac{2 + 12 + 5 + 7 + 6 + 7 + 3}{7} = \frac{42}{7} = 6

Example 2: one large value changes the mean. Find the mean of (a) 2, 105, 5, 7, 6, 7, 3 and (b) 2, 105, 5, 7, 6, 3.

(a) xˉ=2+105+5+7+6+7+37=1357=19.286(b) xˉ=2+105+5+7+6+36=1286=21.33\text{(a)}\ \bar{x} = \frac{2 + 105 + 5 + 7 + 6 + 7 + 3}{7} = \frac{135}{7} = 19.286 \qquad \text{(b)}\ \bar{x} = \frac{2 + 105 + 5 + 7 + 6 + 3}{6} = \frac{128}{6} = 21.33
0102030405060708090100110Data 1mean 6Data 2mean 19.29Data 3mean 21.33
Figure 7. The same small values with a very large one: the mean (triangle) is pulled far to the right
A rounding noteThe slide prints 19.285 for (a); the exact value is 19.2857, which rounds to 19.286.
Reading the diagram

Data 1 has its mean at 6, in the middle of the dots. Replacing 12 by 105 pulls the mean to 19.29, a place where no observation lies. Dropping a 7 as well (Data 3) moves it to 21.33. The mean uses every value, so one extreme value moves it a lot.

Example 3: marks of ten students. Find the sample mean of 68, 79, 38, 68, 35, 70, 61, 47, 58, 66

xˉ=68+79+38+68+35+70+61+47+58+6610=59010=59\bar{x} = \frac{68 + 79 + 38 + 68 + 35 + 70 + 61 + 47 + 58 + 66}{10} = \frac{590}{10} = 59

4.2Mean for grouped data

Discrete single-value data. If the value xix_i occurs fif_i times, the sum of the data is f1x1+f2x2+⋯+fnxnf_1x_1 + f_2x_2 + \cdots + f_nx_n, so

xˉ=f1x1+f2x2+⋯+fnxnn=∑fixin\bar{x} = \frac{f_1x_1 + f_2x_2 + \cdots + f_nx_n}{n} = \frac{\sum f_i x_i}{n}

Example 4: household sizes. Find the mean number of people in a household for the 15 responses from Chapter 1.

Value xFrequency ff × x
122
236
3515
4416
515
Total1544
xˉ=4415=2.93\bar{x} = \frac{44}{15} = 2.93

Continuous data. Every observation in a class is replaced by the mid point mim_i of the class, so

xˉ=f1m1+f2m2+⋯+fnmnn=∑fimin\bar{x} = \frac{f_1m_1 + f_2m_2 + \cdots + f_nm_n}{n} = \frac{\sum f_i m_i}{n}

Example 5: marks of 50 students (grouped continuous data). Find the mean using the grouped table of Chapter 1.

Class intervalFrequency fMid point mf × m
30-40335105
40-50645270
50-601855990
60-7017651105
70-80475300
80-90285170
Total502940
xˉ=294050=58.8\bar{x} = \frac{2940}{50} = 58.8
024681012141618203m = 356m = 4518m = 5517m = 654m = 752m = 8530405060708090Marks (class intervals)Frequency
Figure 8. The dot in each bar is the class mid point used in the calculation
Approximate, not exact58.8 is an approximate value of the mean, not the exact one, because each observation was replaced by its class mid point.

4.3Manipulating the data

Adding a constant
yi=xi+c  ⇒  yˉ=xˉ+cy_i = x_i + c \;\Rightarrow\; \bar{y} = \bar{x} + c
Multiplying by a constant
yi=c xi  ⇒  yˉ=c xˉy_i = c\,x_i \;\Rightarrow\; \bar{y} = c\,\bar{x}

Example 6: adding 5 marks. The ten marks above have mean 59. The teacher adds 5 marks to every student. New data: 73, 84, 43, 73, 40, 75, 66, 52, 63, 71.

yˉ=64010=64=59+5\bar{y} = \frac{640}{10} = 64 = 59 + 5

The mean moves up by exactly 5.

Example 7: scaling down by 40%. The teacher instead multiplies each mark by 0.4. New data: 27.2, 31.6, 15.2, 27.2, 14, 28, 24.4, 18.8, 23.2, 26.4.

yˉ=23610=23.6=59×0.4\bar{y} = \frac{236}{10} = 23.6 = 59 \times 0.4

The mean is multiplied by 0.4.

0102030405060708090Marksmean 59Marks + 5mean 64Marks × 0.4mean 23.6
Figure 9. Adding 5 slides all the dots to the right; multiplying by 0.4 squeezes them toward 0. The mean (triangle) goes with them

4.4Going deeper

  1. The mean is the balance point. Imagine the dots as equal weights on a ruler: the mean is where the ruler balances. That is why one far-away value drags it.
  2. Deviations add to zero. The deviations xi−xˉx_i - \bar{x} always add to 0 (you will see this in Chapter 8 for the ten marks).
  3. The mean need not be a data value. The mean household size is 2.93 people, and no household has 2.93 people.
  4. Both rules together. If every value becomes c xi+dc\,x_i + d, the mean becomes c xˉ+dc\,\bar{x} + d. Apply the multiplication and the addition one after the other.
  5. Grouped mean is only approximate. The exact mean needs the original marks; the grouped table only knows the class of each mark.
Exam tips
  • Total first, then divide: write the sum and the count separately.
  • For grouped data build the extra column (f × x or f × m) and add it up.
  • The divisor in the grouped formulas is the total frequency n, not the number of rows.
Common mistakes
  • Dividing by the number of classes instead of the total frequency.
  • Using the class limits instead of the mid points.
  • Forgetting that the mean is pulled by outliers.
Next · Lecture 3.3Median
05
Lecture 3.3

Median

Definition: medianThe median of a data set is the middle value in its ordered list. Essentially, it is the number that divides the bottom 50% of the data from the top 50%.

5.1Steps to obtain the median

Arrange the data in increasing order. Let nn be the total number of observations.

n odd: one middle value

The median is the observation exactly in the middle of the ordered list:

(n+12)-th observation\left(\frac{n+1}{2}\right)\text{-th observation}
n even: two middle values

The median is the mean of the two middle observations:

mean of the n2-th and (n2+1)-th\text{mean of the }\tfrac{n}{2}\text{-th and }\left(\tfrac{n}{2}+1\right)\text{-th}
213253647576127n = 7 (odd): the middle is the (7 + 1) / 2 = 4th observation = 621325364751056n = 6 (even): average the 3rd and 4th observations = (5 + 6) / 2 = 5.5
Figure 10. Odd and even number of observations

5.2Lecture examples

Example 1: odd number of observations. Find the median of 2, 12, 5, 7, 6, 7, 3.

  • Arrange in increasing order: 2, 3, 5, 6, 7, 7, 12.
  • n=7n = 7 is odd, so the median is the 7+12=4\frac{7+1}{2} = 4th observation, which is 6.

Example 2: odd n with a large value. Find the median of 2, 105, 5, 7, 6, 7, 3.

  • Ordered: 2, 3, 5, 6, 7, 7, 105.
  • n=7n = 7 is odd, the 4th observation is 6, the same as before even though 12 became 105.

Example 3: even number of observations. Find the median of 2, 105, 5, 7, 6, 3.

  • Ordered: 2, 3, 5, 6, 7, 105.
  • n=6n = 6 is even, so take the average of the 3rd and 4th observations: 5+62=\frac{5 + 6}{2} = 5.5.

5.3Mean versus median: outliers

Example 4: sensitivity to outliers. Compare the mean and median of (1) 2, 12, 5, 7, 6, 7, 3 and (2) 2, 117, 5, 7, 6, 7, 3.

(1) mean=2+3+5+6+7+7+127=6, median 6(2) mean=2+3+5+6+7+7+1177=21, median 6\text{(1) mean} = \frac{2+3+5+6+7+7+12}{7} = 6,\ \text{median } 6 \qquad \text{(2) mean} = \frac{2+3+5+6+7+7+117}{7} = 21,\ \text{median } 6
0102030405060708090100110120Data 1mean = median = 6Data 2mean 21median 6
Figure 11. The outlier 117 moves the mean to 21 but leaves the median at 6
Key factThe sample mean is sensitive to outliers, whereas the sample median is not.

5.4Manipulating the data

Adding a constant
new median=old median+c\text{new median} = \text{old median} + c
Multiplying by a constant
new median=old median×c\text{new median} = \text{old median} \times c

Example 5: adding 5 marks. Marks: 68, 79, 38, 68, 35, 70, 61, 47, 58, 66. Find the median, then the median after adding 5 to each mark.

  • Ascending: 35, 38, 47, 58, 61, 66, 68, 68, 70, 79. n=10n = 10 is even, so the median is the average of the 5th and 6th: 61+662=\frac{61+66}{2} = 63.5.
  • After adding 5, ascending: 40, 43, 52, 63, 66, 71, 73, 73, 75, 84. Median 66+712=\frac{66+71}{2} = 68.5 =63.5+5= 63.5 + 5.

Example 6: scaling down by 40%. The marks are multiplied by 0.4. Find the new median.

  • New data ascending: 14, 15.2, 18.8, 23.2, 24.4, 26.4, 27.2, 27.2, 28, 31.6.
  • The 5th and 6th values are 24.4 and 26.4, so the median is 24.4+26.42=\frac{24.4 + 26.4}{2} = 25.4 =0.4×63.5= 0.4 \times 63.5.
A discrepancy in the slideThe slide lists the ascending order with only one 27.2 (nine values); the data have two 27.2s (68 appears twice). The median 25.4 is the same either way.
0102030405060708090Marksmedian 63.5Marks + 5median 68.5Marks × 0.4median 25.4
Figure 12. The median (triangle) moves with the data: +5 shifts it by 5, × 0.4 scales it by 0.4

5.5Going deeper

  1. Sort first. The median only makes sense on the ordered list. If the data are in a stem-and-leaf plot with sorted leaves, they are already sorted.
  2. Positions, not values. n+12\frac{n+1}{2} is a position. For n=7n = 7 it is 4, so look at the 4th value. For n=10n = 10 it is 5.5, meaning halfway between the 5th and 6th values.
  3. When to prefer the median. When a few extreme values would drag the mean (incomes, house prices), the median describes the typical case better.
  4. The median is the 50th percentile. Chapter 9 puts this in a bigger picture.
  5. Both rules together. If every value becomes c xi+dc\,x_i + d, the median becomes c⋅median+dc\cdot\text{median} + d.
Exam tips
  • Write the ordered list out before picking the middle.
  • Check nn odd or even before choosing the rule.
  • With ties (like 7, 7) keep both in the list.
Common mistakes
  • Taking the middle of the unsorted list.
  • For even n, taking only one of the middle values.
  • Dropping repeated values when sorting.
Next · Lecture 3.3Mode
06
Lecture 3.3

Mode

Definition: modeThe mode of a data set is its most frequently occurring value.

6.1Steps to obtain the mode

  1. If no value occurs more than once, then the data set has no mode.
  2. Else, the value that occurs with the greatest frequency is a mode of the data set.

6.2Lecture examples

Example 1: mode of three data sets.

Data setValuesMode
(1)2, 12, 5, 7, 6, 7, 37 occurs twice and every other value once: 7
(2)2, 105, 5, 7, 6, 7, 3Replacing 12 by 105 does not change it: 7
(3)2, 105, 5, 7, 6, 3No value occurs more than once: no mode

6.3Manipulating the data

Adding a constant
new mode=old mode+c\text{new mode} = \text{old mode} + c
Multiplying by a constant
new mode=old mode×c\text{new mode} = \text{old mode} \times c

Example 2: adding 5 marks. Marks: 68, 79, 38, 68, 35, 70, 61, 47, 58, 66. The mode is 68 (it occurs twice). Find the mode after adding 5 marks to each.

The data are 40, 43, 52, 63, 66, 71, 73, 73, 75, 84. The value 73 occurs twice, so the mode is 73 =68+5= 68 + 5.

Example 3: scaling down by 40%. Find the mode after multiplying each mark by 0.4.

The data are 27.2, 31.6, 15.2, 27.2, 14, 28, 24.4, 18.8, 23.2, 26.4. The value 27.2 occurs twice, so the mode is 27.2 =0.4×68= 0.4 \times 68.

0102030405060708090Marksmode 68Marks + 5mode 73Marks × 0.4mode 27.2
Figure 13. The two equal values (stacked dots) are the mode; the triangle follows them when the data are shifted or scaled
Summary of the three centresAdding cc to the data adds cc to all three (mean, median, mode); multiplying by cc multiplies all three by cc.

6.4Going deeper

  1. Mode can be missing or repeated. No value repeated: no mode. Two values tied for the top: two modes (bimodal), as in Week 2.
  2. From a frequency table: the mode is the value with the largest frequency. For grouped continuous data we speak of the modal class, the class with the tallest histogram bar (here 50-60 in the marks table). This is an extension, not a slide from the lecture.
  3. Compare the three centres. Mean uses every value (sensitive to outliers), median uses the middle position (not sensitive), mode uses only the counts (works even for categories).
  4. The mode is a data value. Unlike the mean (2.93 people), the mode always is one of the observations.
Exam tips
  • Tally the values; the biggest tally is the mode.
  • Always say “no mode” when every value occurs once.
Common mistakes
  • Giving the frequency of the mode instead of the mode itself.
  • Writing 0 for “no mode”.
Next · Lecture 3.4Measures of Dispersion and Range
07
Lecture 3.4

Measures of Dispersion and Range

Two data sets can have the same centre and still be different. Compare dataset 1: 3, 3, 3, 3, 3 and dataset 2: 1, 2, 3, 4, 5.

Dataset 1Dataset 2
Mean33
Median33
Mode3Not available
0123456Dataset 1mean = median = 3Dataset 2mean = median = 3
Figure 14. Same mean and median, different spread
Reading the diagram

Every dot of dataset 1 sits at 3 (the five dots are stacked), while dataset 2 spreads from 1 to 5. The mean and median (the triangles) are identical, so they cannot tell the data sets apart. We need a measure of the amount of variation, or spread.

Definition: dispersionA descriptive measure that indicates the amount of variation or spread in a data set is a measure of dispersion (variation, spread). The course covers: range, variance, standard deviation, interquartile range.

7.1Range

Definition: rangeThe range of a data set is the difference between its largest and smallest values.
Range=Max−Min\text{Range} = \text{Max} - \text{Min}

Example 1: range of the two data sets.

Dataset 1 (3, 3, 3, 3, 3)Dataset 2 (1, 2, 3, 4, 5)
Max35
Min31
Range3 - 3 = 05 - 1 = 4

The range separates the two data sets, which the mean and median could not.

7.2Range is sensitive to outliers

Example 2: one value changes the range. Compare dataset 1 (1, 2, 3, 4, 5) and dataset 2 (1, 2, 3, 4, 15).

Dataset 1Dataset 2
Max515
Min11
Range414
0246810121416Dataset 1Range = 5 - 1 = 4Dataset 2Range = 15 - 1 = 14
Figure 15. Range as the distance from the smallest to the largest value
Reading the diagram

The two datasets differ in only one data point, yet the range jumps from 4 to 14. This happens because the range takes into consideration only the Min and the Max of the data.

7.3Going deeper

  1. Range uses two observations. The values in between can be anything; the range does not see them. Chapter 8 introduces measures that use every observation.
  2. Range zero means no variation. Range 0 happens exactly when all the values are equal.
  3. Units. The range is in the same units as the data (marks, kilograms, years).
  4. Adding a constant to every value moves Max and Min by the same amount, so the range is unchanged. The lecture does not cover this, but it follows from the definition.
Exam tips
  • Range = Max - Min, always non-negative.
  • Use the range for a quick feel, but not when outliers are possible.
Common mistakes
  • Subtracting in the wrong order and getting a negative range.
  • Thinking equal means and medians imply equal spread.
Next · Lecture 3.4Variance and Standard Deviation
08
Lecture 3.4

Variance and Standard Deviation

In contrast to the range, the variance takes into account all the observations. One way of measuring the variability of a data set is to consider the deviations of the data values from a central value, the mean.

Population variance (N observations)
σ2=(x1−μ)2+(x2−μ)2+⋯+(xN−μ)2N\sigma^2 = \frac{(x_1-\mu)^2 + (x_2-\mu)^2 + \cdots + (x_N-\mu)^2}{N}
Sample variance (n observations)
s2=(x1−xˉ)2+(x2−xˉ)2+⋯+(xn−xˉ)2n−1s^2 = \frac{(x_1-\bar{x})^2 + (x_2-\bar{x})^2 + \cdots + (x_n-\bar{x})^2}{n-1}
  • The numerator is the sum of squared deviations of every observation from its mean.
  • The denominator for the population variance is NN, the total number of observations.
  • The denominator for the sample variance is (n−1)(n - 1). The reason will be clear in forthcoming courses on statistics.

8.1Lecture example: marks of ten students

The marks of ten students are given and the mean is 59. Find the population variance and the sample variance. 68, 79, 38, 68, 35, 70, 61, 47, 58, 66

Step 1. Subtract the mean from each mark (the deviation) and square it.

#Data xDeviation x - 59Squared deviation
168981
27920400
338-21441
468981
535-24576
67011121
76124
847-12144
958-11
1066749
Total59001898
mean 59+968+2079-2138+968-2435+1170+261-1247-158+766Positive and negative deviations cancel: the total is 0
Figure 16. The ten deviations from the mean: they add up to 0, so we square them before adding
Reading the figure

The labels on the axis are the marks. Bars above the axis are marks above the mean 59; bars below are marks below it. Positive and negative deviations cancel, so the plain sum is 0 and tells us nothing. Squaring makes every term non-negative.

Step 2. Sum of squared deviations = 1898.

Step 3. Divide:

Population variance=189810=189.8Sample variance=18989=210.89\text{Population variance} = \frac{1898}{10} = 189.8 \qquad \text{Sample variance} = \frac{1898}{9} = 210.89
A rounding noteThe slide prints the sample variance as 210.88 (the division 1898 ÷ 9 = 210.888... truncated); rounded to two decimals it is 210.89. The later slide values (14.522 and 5.808) match the exact value.

8.2Standard deviation

Definition: standard deviationThe square root of the sample variance is the sample standard deviation:
s=s2=(x1−xˉ)2+(x2−xˉ)2+⋯+(xn−xˉ)2n−1s = \sqrt{s^2} = \sqrt{\frac{(x_1-\bar{x})^2 + (x_2-\bar{x})^2 + \cdots + (x_n-\bar{x})^2}{n-1}}
UnitsThe sample variance is in square units of the original variable: if the data are weights in kilograms, the variance is in (kilogram)2. The sample standard deviation is in the same units as the data, so it would be in kilograms.

Example: standard deviation of the marks.

s=210.89=14.522s = \sqrt{210.89} = 14.522

8.3Manipulating the data

Adding a constant
new variance=old variance\text{new variance} = \text{old variance}

The standard deviation is also unchanged.

Multiplying by a constant
new variance=c2×old variance\text{new variance} = c^2 \times \text{old variance}

The standard deviation is multiplied by cc.

Example: adding 5 marks. New data: 73, 84, 43, 73, 40, 75, 66, 52, 63, 71. Every deviation from the new mean (64) is the same as before, so the sum of squared deviations is still 1898.

variance=18989=210.89,s=210.89=14.522\text{variance} = \frac{1898}{9} = 210.89, \qquad s = \sqrt{210.89} = 14.522

In general, adding a constant does not change the variability of a data set.

Example: scaling down by 40%. New data: 27.2, 31.6, 15.2, 27.2, 14, 28, 24.4, 18.8, 23.2, 26.4 with mean 23.6. Sum of squared deviations = 303.68.

variance=303.689=33.74,s=33.74=5.808\text{variance} = \frac{303.68}{9} = 33.74, \qquad s = \sqrt{33.74} = 5.808

Check: 0.42×210.89=0.16×210.89=33.740.4^2 \times 210.89 = 0.16 \times 210.89 = 33.74. For the standard deviation: 0.4×14.522=5.8080.4 \times 14.522 = 5.808.

8.4Going deeper

  1. Why square? The plain deviations add to 0. Squaring removes the signs, and it also punishes big deviations more than small ones.
  2. Why a standard deviation too? The variance is in square units (marks2); taking the square root brings it back to marks, so it can be compared directly with the data.
  3. Sample versus population. Divide by NN when you have the whole population, by n−1n - 1 when you have a sample. For the ten marks: 189.8 (population) and 210.89 (sample).
  4. A shortcut for calculation. The sum of squared deviations also equals ∑xi2−nxˉ2\sum x_i^2 - n\bar{x}^2. For the ten marks: 36708−10×592=36708−34810=189836708 - 10 \times 59^2 = 36708 - 34810 = 1898. This is an extra, not part of the lecture.
  5. Zero variance. Variance is 0 only when every value equals the mean (like 3, 3, 3, 3, 3).
  6. Negative multiplier. The variance is multiplied by c2c^2, which is never negative; the standard deviation is multiplied by ∣c∣|c|. The lecture uses positive cc.
Exam tips
  • Build the deviation table: x, x - mean, (x - mean)2, and check that the deviations add to 0.
  • Read the question: “variance” alone usually means the sample variance (divide by n - 1) unless the data are called a population.
  • Standard deviation is the square root of the variance, never the other way round.
Common mistakes
  • Dividing by n for a sample (use n - 1).
  • Squaring after adding the deviations instead of before.
  • Multiplying the variance by c instead of c2.
  • Reporting the variance in the units of the data (it is in square units).
Next · Lecture 3.5Percentiles
09
Lecture 3.5

Percentiles

Definition: percentileThe sample 100p percentile is that data value having the property that at least 100p percent of the data are less than or equal to it and at least 100(1 - p) percent of the data values are greater than or equal to it. If two data values satisfy this condition, the sample 100p percentile is the arithmetic average of these values. The median is the 50th percentile.
1%1%1%1%· · ·· · ·· · ·· · ·1%1%1%1%P1P2P3P97P98P99P50 = median
Figure 17. Percentiles P1 to P99 cut the ordered data into 100 portions of 1% each

9.1Computing a percentile: the n p rule

To find the sample 100p percentile of a data set of size nn:

  1. Arrange the data in increasing order.
  2. If npnp is not an integer, find the smallest integer greater than npnp. The data value in that position is the sample 100p percentile.
  3. If npnp is an integer, the average of the values in positions npnp and np+1np + 1 is the sample 100p percentile.

9.2Lecture example: percentiles of the ten marks

Let n=10n = 10. Arrange the marks in ascending order: 35, 38, 47, 58, 61, 66, 68, 68, 70, 79. Find the 10th, 25th, 50th, 75th and 100th percentiles.

pnpRulePercentile
0.11integer: average of positions 1 and 2(35 + 38)/2 = 36.5
0.252.5not an integer: next integer is 3, so position 347
0.55integer: average of positions 5 and 6(61 + 66)/2 = 63.5
0.757.5not an integer: next integer is 8, so position 868
110integer (there is no position 11)79 (the maximum)
A note on p = 1For p=1p = 1 the rule asks for positions 10 and 11, but there are only ten values; the slide gives the maximum, 79.

9.3Percentiles in Google Sheets

For example, if the data are in cells A1:A10 and we want the 90th percentile, enter PERCENTILE(A1:A10,0.9) in a blank cell.

  1. Paste the data set in a column.
  2. In a blank cell enter PERCENTILE(data, percentile), where data is the range of the data and percentile is the decimal form of the desired percentile.

The algorithm Google Sheets uses

  1. Arrange the data in increasing order and write x[i]x[i] for the i-th ordered value.
  2. Find the rank: rank=percentile×(n−1)+1\text{rank} = \text{percentile} \times (n - 1) + 1
  3. Split the rank into its integer part and fractional part.
  4. Find the ordered value x[i]x[i] for the integer part.
  5. Percentile =x[i]+fractional part×(x[i+1]−x[i])= x[i] + \text{fractional part} \times (x[i+1] - x[i]).

Example: the 25th percentile by the rank method. For the ten ordered marks 35, 38, 47, 58, 61, 66, 68, 68, 70, 79, find the 25th percentile.

  • rank=0.25×(10−1)+1=3.25\text{rank} = 0.25 \times (10 - 1) + 1 = 3.25: integer part 3, fractional part 0.25.
  • x[3]=47x[3] = 47, x[4]=58x[4] = 58.
  • 47+0.25×(58−47)=47+0.25×11=47+2.75=49.7547 + 0.25 \times (58 - 47) = 47 + 0.25 \times 11 = 47 + 2.75 = 49.75.
4045505560x[3] = 47x[4] = 5849.7549.75 = 47 + 0.25 × (58 - 47) = 47 + 2.75the answer lies one quarter of the way from x[3] to x[4]
Figure 18. The rank 3.25 lies a quarter of the way from the 3rd value to the 4th
Two methods, two answersThe lecture gives two ways to compute a percentile. For the 25th percentile of these marks, the n p rule gives 47 (position 3), while the Google Sheets rank method gives 49.75. For the 50th and 75th percentiles they agree (63.5 and 68). The interquartile-range example in the lecture uses the Google Sheets value 49.75.
Percentilen p ruleGoogle Sheets rank method
10th36.5rank 0.1×9+1=1.90.1 \times 9 + 1 = 1.9: 35+0.9×3=35 + 0.9 \times 3 = 37.7
25th4749.75
50th63.563.5
75th6868

The 10th percentile row is worked out here from the same two rules; the lecture states only the 25th percentile difference. Always use the method the question names.

9.4Going deeper

  1. Percentile means position, not marks. Being at the 75th percentile means that about 75% of the data are at or below your value.
  2. Why two methods? With small data sets there is no value that cuts exactly 25% off, so different rules choose differently. For large data sets the answers are almost the same.
  3. Sorted data first. Both methods need the ordered list. A sorted stemplot gives it for free.
  4. The median is a special case. For p=0.5p = 0.5 the n p rule is exactly the median rule of Chapter 5 (np=n/2np = n/2).
Exam tips
  • Write npnp first; integer or not decides the rule.
  • Positions start from 1 (the smallest value is position 1).
  • In the rank method, x[i+1]−x[i]x[i+1] - x[i] is the gap you travel the fractional part along.
Common mistakes
  • Using an unsorted list.
  • Rounding npnp to the nearest integer instead of the next integer.
  • Mixing the two methods in one question.
Next · Lecture 3.5Quartiles, Five-Number Summary and IQR
10
Lecture 3.5

Quartiles, Five-Number Summary and IQR

Definition: quartilesThe sample 25th percentile is the first quartile (Q1). The sample 50th percentile is the median or second quartile (Q2). The sample 75th percentile is the third quartile (Q3).

In other words, the quartiles break up a data set into four parts, with about 25 percent of the data values being less than the first (lower) quartile, about 25 percent between the first and second quartiles, about 25 percent between the second and third (upper) quartiles, and about 25 percent larger than the third quartile.

25%25%25%25%MinQ1 (25th)Q2 = median (50th)Q3 (75th)Maxabout 25%less than Q1about 25% betweenQ1 and Q2about 25% betweenQ2 and Q3about 25%larger than Q3
Figure 19. The three quartiles divide the ordered data into four parts of about 25% each

10.1The five-number summary

Min
  • Minimum: the smallest value.
Q1
  • First quartile: the lower quartile.
Q2
  • Second quartile: the median.
Q3
  • Third quartile: the upper quartile.
Max
  • Maximum: the largest value.

10.2The interquartile range

Definition: IQRThe interquartile range (IQR) is the difference between the first and third quartiles:
IQR=Q3−Q1\text{IQR} = Q_3 - Q_1

Lecture example: IQR of the ten marks. For the ten marks (ordered: 35, 38, 47, 58, 61, 66, 68, 68, 70, 79) find the interquartile range.

  • First quartile (25th percentile): Q1=49.75Q_1 = 49.75.
  • Third quartile (75th percentile): Q3=68Q_3 = 68.
IQR=Q3−Q1=68−49.75=18.25\text{IQR} = Q_3 - Q_1 = 68 - 49.75 = 18.25

The five-number summary of these marks is Min = 35, Q1 = 49.75, Q2 = 63.5, Q3 = 68, Max = 79.

303540455055606570758085IQR = Q3 - Q1 = 68 - 49.75 = 18.25Min 35Q1 49.75Q2 (median) 63.5Q3 68Max 79
Figure 20. Five-number summary and interquartile range of the ten marks
A note on the slideThe lecture states Q1 and Q3 and the IQR; the minimum, median and maximum listed here are read directly from the ordered data.
Reading the diagram

The five circles are the five numbers on the number line. The bracket from Q1 to Q3 is the IQR, 18.25: it measures the spread of the middle part of the data, between the 25th and 75th percentiles.

10.3Going deeper

  1. IQR versus range. The range of the ten marks is 79−35=4479 - 35 = 44; the IQR is 18.25. The IQR looks only at the middle half, so one extreme value cannot stretch it the way it stretches the range.
  2. The middle 50%. About half of the data lie between Q1 and Q3, and the IQR is the width of that stretch.
  3. Which method for Q1 and Q3? The lecture example uses the Google Sheets values. With the n p rule the same data would give Q1 = 47 and so IQR = 68 - 47 = 21. Use the method the question names.
  4. Centre and spread together. Median with IQR is a good pair for skewed data; mean with standard deviation is the other usual pair.
Exam tips
  • Write the five numbers in order: Min, Q1, Q2, Q3, Max.
  • IQR is one number (Q3 - Q1), not an interval.
Common mistakes
  • Calling Q2 the mean (it is the median).
  • Subtracting Max - Min and calling it the IQR.
Next · All lecturesWeek 3 Summary Sheet
11
All lectures

Week 3 Summary Sheet

Everything in Week 3 on one sheet, for a last-minute revision.

Effect of a constant on each measure

MeasureAdd c to every valueMultiply every value by cMarks example (+5 / × 0.4)
Meanmean + cmean × c59 → 64 / 23.6
Medianmedian + cmedian × c63.5 → 68.5 / 25.4
Modemode + cmode × c68 → 73 / 27.2
Varianceunchangedc² × variance210.89 → 210.89 / 33.74
Standard deviationunchangedc × standard deviation14.522 → 14.522 / 5.808

The lecture shows the effect of constants on the mean, median, mode, variance and standard deviation. It does not cover range or IQR, so they are not in the table.

Formulas

Sample mean
xˉ=∑xin\bar{x} = \frac{\sum x_i}{n}

Grouped: replace the sum by ∑fixi\sum f_i x_i (discrete) or ∑fimi\sum f_i m_i (class mid points).

Sample variance and SD
s2=∑(xi−xˉ)2n−1,s=s2s^2 = \frac{\sum (x_i - \bar{x})^2}{n-1}, \quad s = \sqrt{s^2}

Population variance divides by NN.

Range and IQR
Range=Max−Min,IQR=Q3−Q1\text{Range} = \text{Max} - \text{Min}, \quad \text{IQR} = Q_3 - Q_1
Percentile rank (Sheets) and median position
rank=p(n−1)+1\text{rank} = p(n-1) + 1

Median position: n+12\frac{n+1}{2}.

Which graph or table for which data

DataTableGraph
Discrete, few distinct valuesFrequency table with single valuesBar graph of frequencies
ContinuousFrequency table with class intervals (left end included)Histogram
Any numerical data (values kept)-Stem-and-leaf diagram

Topic by topic

Frequency tables
  • Discrete: one row per value.
  • Continuous: class intervals [low, high).
Graphs
  • Histogram of class frequencies.
  • Stem-and-leaf diagram.
Central tendency
  • Mean = sum / count.
  • Median = middle of the ordered list.
  • Mode = most frequent value.
Dispersion
  • Range = Max - Min.
  • Variance and standard deviation.
  • IQR = Q3 - Q1.
Percentiles
  • 100p percentile; n p rule.
  • Sheets: rank = p(n - 1) + 1.
  • Quartiles, five-number summary.
Constants
  • Add c: centre shifts, spread same.
  • Multiply by c: centre × c, variance × c².
Revision overview
Frequency tablesDiscrete: one row per value
Continuous: class intervals [low, high)
GraphsHistogram of class frequencies
Stem-and-leaf diagram
Central tendencyMean = sum / count
Median = middle of the ordered list
Mode = most frequent value
Describing numerical dataStatistics for Data Science 1
DispersionRange = Max - Min
Variance and standard deviation
IQR = Q3 - Q1
Percentiles100p percentile; n p rule
Sheets: rank = p(n - 1) + 1
Quartiles, five-number summary
ConstantsAdd c: centre shifts, spread same
Multiply by c: centre × c, variance × c²
Revision: the whole of Week 3 on one map
Back to top