Skip to main content
Back to module
Statistics Fundamentals · Describing Data

Mean, median, and spread

Reading39mLesson 2 of 3 in this module

Compute the mean, median, range and standard deviation, and pick the summary that fits the data.

Why this matters

"The average delivery takes 3 days" and "the average salary is $80,000" sound precise, but they hide two questions: which average, and how much do individual values vary around it? Two production lines can have the same mean part length while one of them scraps a third of its output. Describing centre and spread together is the most common job in statistics, and choosing the right measures is a skill you will use in every data, lab and engineering role.

Measures of centre

Mean: add the values and divide by how many there are.

data: 4, 8, 6, 5, 7
mean = (4 + 8 + 6 + 5 + 7) / 5 = 30 / 5 = 6

Median: sort the values and take the middle one. With an even count, average the two middle values.

sorted: 4, 5, 6, 7, 8        median = 6
sorted: 4, 5, 6, 7, 8, 40    median = (6 + 7) / 2 = 6.5

Mode: the most frequent value. Most useful for categorical data or for discrete data with many repeats.

Mean vs median: the outlier test

Add one large value and watch what happens. The list 4, 5, 6, 7, 8 has mean 6 and median 6. Add 40:

  • mean = 70 / 6 ≈ 11.7
  • median = 6.5

One value dragged the mean almost to double, while the median barely moved. The median is robust to outliers; the mean is not. That is why house prices and incomes are usually reported as medians: a few very large values pull the mean far above what a typical person sees.

Use the mean when the data is roughly symmetric with no extreme values (part dimensions, repeated lab measurements). Use the median when the data is skewed or has outliers (wait times, prices, response times). When in doubt, report both; a big gap between them is itself a finding.

Measures of spread

Range = max − min. Simple, but it depends entirely on the two most extreme values.

Interquartile range (IQR) = Q3 − Q1, the width of the middle 50% of the data. Robust, like the median. You will use it to flag outliers in the next lesson.

Variance and standard deviation measure the typical distance of values from the mean.

  1. Subtract the mean from each value (the deviations).
  2. Square each deviation, so negatives do not cancel positives.
  3. Add the squares.
  4. Divide by n − 1 for a sample (or by n for a whole population). That is the variance.
  5. Take the square root to get back to the original units. That is the standard deviation (SD).

Worked example

Five measured resistor values in ohms: 98, 101, 100, 99, 102.

mean = 500 / 5 = 100
deviations:        -2,  1,  0, -1,  2
squared:            4,  1,  0,  1,  4    sum = 10
sample variance = 10 / (5 - 1) = 2.5
sample SD       = sqrt(2.5) ≈ 1.58 ohms

A second batch, 90, 110, 100, 95, 105, also has mean 100, but its squared deviations sum to 250, so the sample SD is sqrt(62.5) ≈ 7.9 ohms. Same centre, very different consistency.

Why n − 1?

A sample's values sit a little closer to their own mean than to the true population mean, so dividing by n slightly underestimates the spread. Dividing by n − 1 corrects that. In practice: if your data is a sample from something bigger (almost always), use n − 1. Spreadsheets call this STDEV.S; Python calls it statistics.stdev. The population versions are STDEV.P and statistics.pstdev.

In Python

The standard library's statistics module covers all of this:

import statistics

ohms = [98, 101, 100, 99, 102]
print(statistics.mean(ohms))     # 100
print(statistics.median(ohms))   # 100
print(statistics.stdev(ohms))    # 1.58... (sample, n - 1)
print(statistics.pstdev(ohms))   # 1.41... (population, n)

Common mistakes

  • Reporting a mean for skewed data without the median.
  • Mixing up sample and population SD (and not saying which one you used).
  • Quoting a centre with no spread. "Mean 100 ohms" is half an answer; "mean 100, SD 1.6" is a whole one.
  • Forgetting units: the SD is in the same units as the data, the variance is in squared units.

Quick recap

  • Mean: sensitive to outliers. Median: robust. Mode: most common value.
  • Range is crude; IQR is robust; SD is the standard measure of spread around the mean.
  • Sample SD divides the sum of squared deviations by n − 1.
  • Always report a centre with a spread, and say which ones.

Try it

In the Do tab, finish a summarize function by writing the sample standard deviation formula.

Also in this lesson: