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.
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
A saved draft is open. To run the published example, open Editor tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
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?
Your result
Result tools
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.
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
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?
Hints for this question
- Identify what makes a pair.
- Compare each person with themselves under the two device conditions.