Mean, spread and the histogram
Ten readings of the same distance never match. Which single number should the robot believe, and how much should it trust it?
About 35 min · 3 goals · Checked by automated tests
1.Why should I care?
A single reading hides its own uncertainty. Repeating it and summarising the results with a mean and a standard deviation tells you both the best estimate and how much it wobbles: the two numbers every honest measurement report needs.
- ◇ Compute the mean and the sample standard deviation of a set of readings.
- ◇ Read a histogram of repeated measurements and estimate its centre and spread.
- ◇ Explain why the sample standard deviation divides by n − 1.
2.Predict
A sensor with noise σ = 4 gives 64 readings. Roughly how wide is the middle two-thirds of the histogram?
Guess first. Being wrong here is how the surprise works.
3.Discover
Stay on 'One batch'. Take 64 readings with σ = 4 and look at the histogram's shape. Compare the sample standard deviation with σ. Now try n = 4 several times with new data: how much does the estimate of σ itself jump around?
Loading the interactive…
Can't use the interactive? Read a description instead
The diagram draws a histogram of readings from a sensor with adjustable noise σ and bias. With n = 64 and σ = 4, the bars form a hump centred near the true value plus bias, about 16 units wide in total; the readout lists the readings, the mean and the sample standard deviation, which comes out close to 4.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
Readings 4.1, 3.9, 4.3, 3.7 V. What is the mean, in volts?
5.Understand
The mean: best single estimate
The mean x̄ = (x₁ + x₂ + … + xₙ) ÷ n. When errors are random and unbiased, it is the best single guess of the true value. It is sensitive to outliers: one glitch reading of 9999 drags it badly, which is why spikes are often removed first.
Standard deviation: typical distance
The sample standard deviation s = √(Σ(xᵢ − x̄)² ÷ (n − 1)) measures how far readings typically sit from their mean. Same units as the readings. For bell-shaped (normal) noise, about 68% of readings fall within ±s of the mean and about 95% within ±2s.
Why n − 1?
The deviations are measured from x̄, which was computed from the same readings, so they come out a little smaller than deviations from the true value would. Dividing by n − 1 instead of n corrects that on average. With 3 readings it matters a lot; with 300 it barely matters.
Histograms show the shape
A histogram counts readings in equal bins. A single tall, symmetric hump suggests random noise. Two humps suggest two different conditions mixed together; a long tail on one side suggests occasional glitches. Always look before you average.
Explain it another way
The mean is the balance point of the readings on a seesaw. The standard deviation is how far, typically, each reading sits from that balance point.
x̄ = Σxᵢ/n, s² = Σ(xᵢ − x̄)²/(n − 1). For independent normal noise of standard deviation σ, s is an estimate of σ whose own uncertainty is roughly σ/√(2(n − 1)).
Σ(xᵢ − x̄)² = Σ(xᵢ − μ)² − n(x̄ − μ)². Its expected value is nσ² − σ² = (n − 1)σ², so dividing by n − 1 gives an unbiased estimate of σ².
Datasheets often quote noise as an RMS value (a standard deviation) and sometimes as peak-to-peak, which is several times larger for the same sensor. Know which you are reading before comparing two sensors.
Worked example 1
Readings: 10.2, 9.8, 10.4, 9.6, 10.0 cm. Find x̄ and s.
x̄ = 50.0 ÷ 5 = 10.0 cm. Deviations: 0.2, −0.2, 0.4, −0.4, 0. Squares add to 0.04 + 0.04 + 0.16 + 0.16 + 0 = 0.40. s = √(0.40 ÷ 4) = √0.10 ≈ 0.32 cm.
Common mix-ups
- More readings make the histogram narrower.
✓ More readings fill in the histogram's shape; its width is set by the sensor's noise. It is the mean that becomes more certain. - Standard deviation and range (max − min) are the same.
✓ Range depends on the two most extreme readings and grows with n; standard deviation summarises them all.
6.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2 · a fresh version every time
A distance sensor gives these repeated readings (cm): 98, 98, 102, 102.5. What is their mean, in cm?
Practice 3 · a fresh version every time
A distance sensor gives these repeated readings (cm): 48.5, 48.5, 47.5, 46, 45. What is their sample standard deviation (divide by n − 1), in cm?
Practice 4
Noise is bell-shaped with mean 50 and s = 2. About what share of readings lie between 46 and 54?
Practice 5
A histogram of a robot's distance readings has two separate humps. What should you suspect first?
7.Apply it
Write a Python function summary(readings) that returns the mean, sample standard deviation and the share of readings within ±2s. Test it on the readings from the diagram with n = 64, and compare the share with 95%.
8.Reflect
Concepts: Describing data · Measurement error and uncertainty