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.

See the reasoning
1A2B3A4B5B6B7B8A9A10A11B12A
1A2B3A4B5B6B7B8A9A10A11B12A
The actual seeded reference schedule: six A and six B positions. Balanced counts do not guarantee equal average positions. The seed reproduces this schedule, not a proof of balance or generalisation.

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

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

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?

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?

Choose an answer

Hints for this question
  1. Think about a machine warming up over time.
  2. Ask which treatment receives the warm state if order never changes.
Your notes