Design a fair testLesson 07 of 30 · 6 min
Do not let order choose the winner
Construct a balanced random order and explain what randomisation does not guarantee.
Randomisation uses a chance procedure to assign treatments or their order. If A always runs first, an improving warm-up trend can masquerade as a B advantage. A random order prevents the schedule from deliberately linking treatment to position.
A seed sets the initial state of a pseudo-random generator. Recording it makes a schedule reproducible. Reusing one seed forever does not establish that an experiment generalises; it simply recreates that one random schedule.
Below, shuffle equal numbers of A and B. Inspect their positions against an invented time trend. Randomisation balances other influences in expectation over assignments, not perfectly in each small experiment. Record order and conditions so you can inspect remaining imbalance.
Will a balanced number of A and B runs guarantee equal average positions?
Write a prediction (optional)
Run the prepared example
This page puts the example in the Python editor. Select Run Python with the code unchanged.
Seeded schedule and invented timings
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
Count A and B in the treatment column, then compare Mean position by treatment. Does an equal number of runs give the treatments equal average positions?
Your result
Result tools
The schedule contains six of each treatment. One treatment can land later by chance, even though the scheduling rule favours neither treatment.
Published example output
The site ran the original code to produce this reference. Build environment ↗
position treatment background_ms
1 A 118
2 B 116
3 A 114
4 B 112
5 B 110
6 B 108
7 B 106
8 A 104
9 A 102
10 A 100
11 B 98
12 A 96
Mean position by treatment:
treatment
A 7.17
B 5.83
Name: position, dtype: float64
The schedule contains six of each treatment. One treatment can land later by chance, even though the scheduling rule favours neither treatment.
Change and run again
In the Python editor, change the 42 in np.random.default_rng(42) to 7 and select Run Python. Repeat with 19. Compare Mean position by treatment and the treatment counts across all three runs. Does the treatment that ran later on average stay the same? Return to the Python editor
What this example supports. The code shuffles treatment order on one model schedule. A real experiment must also justify the choice of machine, workload and reset.
Try a fresh case
Why randomise which treatment goes first?
Hints for this question
- Think about a machine warming up over time.
- Ask which treatment receives the warm state if order never changes.