Reporting comparisons with uncertainty
Two averages are not a comparison until you know how much they could vary. Learn to report spread, standard error and the uncertainty of a difference, with a worked Python example and a rough rule for success rates.
Lesson 5 of 6 · 35 min · Self-paced · Free
Two averages are not the whole story
A team tests a new line-following controller against their old one, ten laps each. The new controller's average lap is 12.16 seconds; the old one's is 12.62 seconds. The new one is 0.46 seconds faster. Done?
Not yet. Every lap is slightly different: tiny wheel slips, small differences in starting position, sensor noise. If the team ran another ten laps of each, the averages would come out a little different. So the real question is: is a 0.46-second gap bigger than the wobble you would expect from luck alone? Answering it means reporting uncertainty, not just averages.
This lesson builds a simple, honest toolkit. If you have taken the data analysis module in the computational engineering pathway, some of this will be familiar; here the focus is on comparisons.
Step 1: spread within each condition
The standard deviation (SD) measures how far individual trials typically sit from their average. A small SD means the trials were consistent; a large one means they varied a lot. For a sample of trials, it is calculated by:
- finding the mean;
- subtracting the mean from each value and squaring the result;
- adding those squares and dividing by n − 1 (one less than the number of trials);
- taking the square root.
Dividing by n − 1 instead of n is the usual choice for a sample. It slightly corrects for the fact that a sample's own mean sits closer to its values than the true mean would.
Step 2: uncertainty in each average
The SD describes individual laps. But we want to know how uncertain the average is. That is the standard error of the mean (SE):
SE = SD ÷ √nMore trials make the average more trustworthy, but only slowly: because of the square root, you need four times as many trials to halve the standard error.
Step 3: uncertainty in the difference
When you subtract one average from another, both uncertainties carry over. For two independent sets of trials, the standard error of the difference is:
SE_diff = √(SE₁² + SE₂²)A useful rough rule: the true difference probably lies within about 2 × SE_diff of the measured difference. This gives an approximate 95% interval, a range that would capture the true difference in about 95% of repeated experiments like this one. The rule is rough. With small samples, statisticians use a slightly larger multiplier (from what is called the t distribution), and it assumes trials are independent of one another.
Worked example in Python
Go deeper: work through it step by stepabout 1 min
The lap times below are made-up for illustration. This code uses only Python's standard library.
import math
import statistics
# Made-up lap times in seconds, for illustration only.
baseline = [12.4, 12.9, 12.1, 13.0, 12.6, 12.8, 12.3, 12.7, 12.5, 12.9]
new = [11.9, 12.5, 12.2, 11.6, 12.8, 12.0, 11.8, 12.4, 12.1, 12.3]
def summarise(name, data):
n = len(data)
mean = statistics.mean(data)
sd = statistics.stdev(data) # sample standard deviation
se = sd / math.sqrt(n) # standard error of the mean
print(f"{name}: n={n} mean={mean:.2f} s sd={sd:.2f} s se={se:.2f} s")
return mean, se
m_b, se_b = summarise("baseline", baseline)
m_n, se_n = summarise("new ", new)
diff = m_b - m_n # positive = new is faster
se_diff = math.sqrt(se_b**2 + se_n**2)
print(f"difference = {diff:.2f} s, rough 95% range {diff - 2*se_diff:.2f} to {diff + 2*se_diff:.2f} s")Output:
baseline: n=10 mean=12.62 s sd=0.29 s se=0.09 s
new : n=10 mean=12.16 s sd=0.36 s se=0.11 s
difference = 0.46 s, rough 95% range 0.17 to 0.75 sInterpreting it
The rough range runs from 0.17 to 0.75 seconds. It does not include zero, so a difference this large is unlikely to be luck alone: the new controller does seem faster on this track. But the range is wide. The true improvement might be as small as about 0.2 seconds or as large as about 0.7. An honest report says exactly that, rather than "the new controller is 0.46 seconds faster".
If the range had included zero, the right conclusion would be "no clear difference was found with ten laps each", not "there is no difference". Absence of evidence is not evidence of absence; more trials might reveal a small real effect.
Success rates have uncertainty too
Many robot tests count successes out of a number of attempts. For a success rate p measured over n attempts, a rough standard error is:
SE = √( p × (1 − p) ÷ n )Worked example
Made-up results: a new gripper succeeds in 36 of 40 lifts (p = 0.90), and the baseline in 30 of 40 (p = 0.75). The new gripper looks 15 percentage points better.
- New: SE = √(0.90 × 0.10 ÷ 40) = √0.00225 ≈ 0.047, about 4.7 percentage points.
- Baseline: SE = √(0.75 × 0.25 ÷ 40) = √0.0046875 ≈ 0.068, about 6.8 points.
- Difference: SE_diff = √(0.047² + 0.068²) ≈ 0.083, about 8.3 points.
- Rough 95% range: 15 ± 2 × 8.3, which is about −2 to +32 points.
The range includes zero. A 15-point gap looks large, yet with only 40 attempts each, it could still be partly or wholly luck. The honest conclusion is "promising, but not yet clear; more trials are needed". This rough rule also works poorly when success rates are very close to 0% or 100%, or when n is small; for those cases, statisticians use more careful methods.
Error bars: always say what they show
Graphs often show averages with error bars. The trouble is that error bars can show the SD, the SE or a 95% interval, and these differ greatly in size. An SD bar is about √n times longer than an SE bar for the same data. So always state in the caption what your bars represent and how many trials each average is based on. Also note that whether two error bars overlap is not, on its own, a reliable test of a difference; calculate the uncertainty of the difference itself, as above.
Better still, show every individual trial as a dot alongside the averages. Readers can then see the spread, any odd trials and how many trials there were, all at once.
What a good comparison report includes
- The number of trials in each condition.
- The mean (and median, if useful) for each condition.
- The spread (SD) for each condition.
- The difference and its uncertainty, for example an approximate 95% interval.
- All trials, or a link to the raw data, with any exclusions explained by a rule decided in advance.
- The conditions of the test and its limitations.
A good sentence might read: "Across 10 laps each, the new controller averaged 12.16 s (SD 0.36 s) and the baseline 12.62 s (SD 0.29 s). The new controller was 0.46 s faster, with an approximate 95% interval of 0.17 to 0.75 s. Tests used one track and one battery type." (All values made-up.)
Knowledge check
Check your understanding
Go further
- Standard error — Wikipedia ↗
A fuller treatment of standard error and how it is used to build confidence intervals.
Lesson materials · free to download
Sign in to track your progress. Reading is free without an account.