Skip to content
Tactiverge

Comparing two conditions

Decide whether a change really made a difference by comparing means, spreads and overlap, and by measuring the size of the effect, not just its existence.

Lesson 5 of 6 · 30 min · Self-paced · Free

Did the change help?

Much of engineering is comparison. You tune a controller and want to know whether the joint now settles faster. You change a gripper's finger material and want to know whether it drops fewer objects. You run some trials with the old version and some with the new, and the means differ. But means always differ a little, even if nothing changed, because of noise. The real question is: is the difference larger than the noise, and is it large enough to matter?

The data

A robot joint is commanded to move to a target, and we record its settling time: how long until it stays within a small band around the target. We test the old controller and a new one, 8 trials each (made-up data for illustration):

old: 1.42, 1.35, 1.51, 1.38, 1.47, 1.40, 1.55, 1.44 s
new: 1.31, 1.36, 1.28, 1.40, 1.25, 1.33, 1.37, 1.30 s

Step 1: describe each condition

import math
import statistics

# Made-up data for illustration: settling time (s) of one joint, 8 trials each
old = [1.42, 1.35, 1.51, 1.38, 1.47, 1.40, 1.55, 1.44]
new = [1.31, 1.36, 1.28, 1.40, 1.25, 1.33, 1.37, 1.30]

def describe(name, data):
    m = statistics.mean(data)
    s = statistics.stdev(data)
    print(f"{name}: n = {len(data)}, mean = {m:.3f} s, sd = {s:.3f} s")
    return m, s

m1, s1 = describe("old", old)
m2, s2 = describe("new", new)
n1, n2 = len(old), len(new)

diff = m1 - m2
se_diff = math.sqrt(s1**2 / n1 + s2**2 / n2)
pooled = math.sqrt(((n1 - 1) * s1**2 + (n2 - 1) * s2**2) / (n1 + n2 - 2))
d = diff / pooled

print(f"difference = {diff:.3f} s, SE of difference = {se_diff:.3f} s")
print(f"rough 95% range: {diff - 2 * se_diff:.3f} to {diff + 2 * se_diff:.3f} s")
print(f"pooled sd = {pooled:.3f} s, effect size d = {d:.2f}")

Output:

old: n = 8, mean = 1.440 s, sd = 0.067 s
new: n = 8, mean = 1.325 s, sd = 0.050 s
difference = 0.115 s, SE of difference = 0.030 s
rough 95% range: 0.056 to 0.174 s
pooled sd = 0.059 s, effect size d = 1.94

We will unpack each line.

Step 2: how uncertain is the difference?

From the previous lessons, each mean has its own standard error, s / √n. When you subtract two independent means, their uncertainties combine. Variances (squared standard errors) add:

SE_difference = √( s₁²/n₁ + s₂²/n₂ )
              = √( 0.067²/8 + 0.050²/8 ) ≈ 0.030 s

Note that the uncertainties add, even though the means are subtracted. Comparing two noisy things is noisier than measuring either one.

The difference in means is 0.115 s, almost four times its standard error. A rough 95% range is the difference ± 2 SE, about 0.06 to 0.17 s. With only 8 trials per group, a more careful calculation uses a slightly larger multiplier from the t-distribution (about 2.2 here), but the range still sits comfortably above zero. So the improvement is very unlikely to be just noise.

Step 3: how big is the effect?

"Unlikely to be noise" is not the same as "important". With thousands of trials, even a 0.001 s improvement can be reliably detected, yet nobody would care. So engineers also report an effect size.

The simplest effect size is the raw difference in real units: the new controller settles about 0.115 s faster, roughly 8% of the old 1.44 s. Often that is the most useful number of all, because you can judge it against a requirement.

A unit-free effect size, called Cohen's d, divides the difference by the typical spread within the groups:

d = (mean₁ − mean₂) / pooled standard deviation

The pooled standard deviation is a weighted average of the two groups' spreads (0.059 s here). Here d ≈ 1.9: the means are about two standard deviations apart. As a loose convention, d around 0.2 is often called small, 0.5 medium and 0.8 or more large, but these labels came from behavioural science and are only a rough guide. In engineering, what counts as large depends on the job.

Step 4: look at the overlap

Means and effect sizes are summaries. Look at the individual trials as well:

old = [1.42, 1.35, 1.51, 1.38, 1.47, 1.40, 1.55, 1.44]
new = [1.31, 1.36, 1.28, 1.40, 1.25, 1.33, 1.37, 1.30]

print("old sorted:", sorted(old))
print("new sorted:", sorted(new))

wins = sum(1 for o in old for n in new if n < o)
ties = sum(1 for o in old for n in new if n == o)
pairs = len(old) * len(new)
print(f"new faster in {wins} of {pairs} pairs ({wins / pairs:.0%}), ties: {ties}")

Output:

old sorted: [1.35, 1.38, 1.4, 1.42, 1.44, 1.47, 1.51, 1.55]
new sorted: [1.25, 1.28, 1.3, 1.31, 1.33, 1.36, 1.37, 1.4]
new faster in 59 of 64 pairs (92%), ties: 1

The two groups overlap between 1.35 and 1.40 s: the best old trial beat the worst new trial. Comparing every old trial with every new trial, the new controller was faster in 59 of the 64 pairs. This is an intuitive way to describe an effect: "pick one trial from each at random, and the new one is faster about nine times in ten."

Overlap matters for engineering decisions. If the requirement were "always settle within 1.40 s", the new controller met it in all 8 trials and the old one in only 3. That is a different and often more useful statement than a difference in means.

Things that can fool you

  • Conditions that differ in more than one way. If all the old trials ran in the morning and all the new ones in the afternoon, after the motors warmed up, the comparison mixes two changes. Interleave or randomise the order of trials.
  • Too few trials. With 3 trials per group, standard deviations are themselves very uncertain, and a fluke can look like an effect.
  • Choosing the comparison after seeing the data. If you measure ten things and report the one that changed, you have probably found noise.
  • Reporting only "it was significant". Always give the size of the difference with its uncertainty, in real units.

Recap

  • Means always differ a little; compare the difference with its uncertainty, √(s₁²/n₁ + s₂²/n₂).
  • A rough 95% range for the difference is ± 2 SE; small samples need a slightly larger multiplier.
  • Report an effect size: the raw difference in units, and optionally Cohen's d = difference / pooled sd.
  • Look at the overlap of individual trials and relate it to your actual requirement.
  • Keep everything except the change you are testing the same, and decide on the comparison before you collect data.

Knowledge check

Check your understanding

  1. 1. Two means each have a standard error of 0.3. What is the standard error of their difference?
  2. 2. Controller B's mean is 0.002 s faster than A's, and with 10,000 trials each this is clearly larger than the noise. What is the most sensible conclusion?
  3. 3. Cohen's d is the difference in means divided by:
  4. 4. All 'old' trials were run on Monday and all 'new' trials on Tuesday after maintenance. What is the main problem?

Go further

Comparing two conditions — Computational Engineering — Tactiverge