Design a fair testLesson 08 of 30 · 6 min

Compare like with like

Calculate differences within matched blocks rather than mixing unlike conditions.

A block groups observations made under similar conditions, such as one machine or one experimental session. A paired comparison tests both treatments within each block. The analysis keeps those pairs together.

In the invented data, different machines have very different baseline times. B is compared with A on the same machine. Subtracting within a pair removes an additive machine baseline, making the treatment comparison easier to see.

Pairing is a design decision, not a way to match convenient observations after seeing results. Randomise order within blocks, define the block before collecting data, and check for carryover: one treatment can change the state inherited by the next. A reset or washout may be needed.

Keep the pair together
M1M2M3M4M550107163220Elapsed time (ms)
M1M2M3M4M550107163220Elapsed time (ms)
di=Bi−Aid_i=B_i-A_i
Five invented matched machines. Each horizontal segment connects B and A on the same machine. Pairing retains the comparison within a block; these lines are not confidence intervals.

Will between-machine variation disappear from each within-machine difference if the machine effect is additive?

Write a prediction (optional)

Run the prepared example

This page puts the example in the Python editor. Select Run Python with the code unchanged.

Invented data

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

What to compare

Find the M3 row and compare a_ms with b_ms. What does its b_minus_a say about the two treatments on that machine?

Published example output

The site ran the original code to produce this reference. Build environment ↗

machine  a_ms  b_ms  b_minus_a
     M1    80    72         -8
     M2   130   119        -11
     M3   200   187        -13
     M4   105    98         -7
     M5   160   150        -10
Five lines connect each machine’s A and B time. The gaps within each machine are smaller than the variation across machines.
Open full-size figure ↗

Each plotted line connects the two times from one machine. Subtracting A from B preserves that comparison even if the machines have different baseline speeds.

Change and run again

In the Python editor, add pairs.loc[pairs.machine == "M3", ["a_ms", "b_ms"]] += 100 before the line starting pairs["b_minus_a"]. Select Run Python again. Compare M3’s a_ms, b_ms and b_minus_a with the first run. Which values move, and which one keeps the same treatment comparison? Return to the Python editor

What this example supports. Matching removes only the influences captured by the block and the comparison model. Carryover and treatment-by-machine differences can remain.

Try a fresh case

You measure each participant with both devices. Which comparison preserves the paired design?

Choose an answer

Hints for this question
  1. Identify what makes a pair.
  2. Compare each person with themselves under the two device conditions.
Your notes