Skill Tracer
Skills › Scientific Agent Skills › experimental-design › randomization_and_blocking.md

randomization_and_blocking.md

133 lines · skills/experimental-design/references/randomization_and_blocking.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# Randomization, Blocking, Stratification, and Controls
2
3These are the tools of *local control*: removing or balancing nuisance variation so
4the comparison you care about is clean. Randomization handles the unknown
5confounders; blocking and stratification handle the known ones; controls and
6blinding handle the systematic biases.
7

Randomization, Blocking, Stratification, and Controls

These are the tools of local control: removing or balancing nuisance variation so the comparison you care about is clean. Randomization handles the unknown confounders; blocking and stratification handle the known ones; controls and blinding handle the systematic biases.

Raw lines 1 to 7
8## Randomization — why and how
9
10Randomization assigns treatments to units by chance, so that in expectation every
11confounder (measured or not, known or unknown) is balanced across arms. This is the
12foundation of causal inference: without it, an observed difference could always be
13due to some variable that happened to track the grouping.
15Use a **seeded, reproducible** schedule (see `scripts/randomization.py`) and follow
16it exactly. Record the seed. "I randomized somehow" is neither auditable nor
17reproducible.

Randomization — why and how

Randomization assigns treatments to units by chance, so that in expectation every confounder (measured or not, known or unknown) is balanced across arms. This is the foundation of causal inference: without it, an observed difference could always be due to some variable that happened to track the grouping.

Use a seeded, reproducible schedule (see scripts/randomization.py) and follow it exactly. Record the seed. "I randomized somehow" is neither auditable nor reproducible.

Raw lines 8 to 18
Runs code scripts/randomization.py :15
19### Methods (and when each is right)
21| Method | What it does | Use when |
22|--------|--------------|----------|
23| **Simple** | Independent random assignment per unit | Independent allocation is appropriate; imbalance is tolerable |
24| **Permuted block** | Within each block, arms appear in fixed ratio; order shuffled | You need balance at completed-block boundaries during sequential intake |
25| **Stratified block** | Separate blocks within each level of a prognostic factor | A known covariate (site, sex, stage) must be balanced across arms |
26| **Cluster** | Whole groups (clinics, classes) assigned to arms | The intervention is delivered at a group level |
27| **Minimization** | Adaptively assign to minimize imbalance across several covariates | Many prognostic factors and small n (specialized; not in the script) |
29**Simple randomization caveat:** with small n it behaves like flipping a few coins —
30you can easily get 12 vs. 8 instead of 10 vs. 10, and worse for subgroups. Blocking
31controls this at complete-block boundaries; a partial block can remain imbalanced.
33**Block size:** must be a multiple of the ratio unit (e.g. for 1:1, sizes 2, 4, 6).
34Smaller blocks balance more tightly but are more predictable in unblinded trials
35(a clinician who knows the block size can guess the last allocation). Vary block
36size with an appropriate allocation system when predictability matters. The bundled
37helper supports a fixed size only; it does not implement concealment or variable
38block sizes. Never give recruiting staff the seed or future schedule.

Methods (and when each is right)

MethodWhat it doesUse when
SimpleIndependent random assignment per unitIndependent allocation is appropriate; imbalance is tolerable
Permuted blockWithin each block, arms appear in fixed ratio; order shuffledYou need balance at completed-block boundaries during sequential intake
Stratified blockSeparate blocks within each level of a prognostic factorA known covariate (site, sex, stage) must be balanced across arms
ClusterWhole groups (clinics, classes) assigned to armsThe intervention is delivered at a group level
MinimizationAdaptively assign to minimize imbalance across several covariatesMany prognostic factors and small n (specialized; not in the script)

Simple randomization caveat: with small n it behaves like flipping a few coins — you can easily get 12 vs. 8 instead of 10 vs. 10, and worse for subgroups. Blocking controls this at complete-block boundaries; a partial block can remain imbalanced.

Block size: must be a multiple of the ratio unit (e.g. for 1:1, sizes 2, 4, 6). Smaller blocks balance more tightly but are more predictable in unblinded trials (a clinician who knows the block size can guess the last allocation). Vary block size with an appropriate allocation system when predictability matters. The bundled helper supports a fixed size only; it does not implement concealment or variable block sizes. Never give recruiting staff the seed or future schedule.

Raw lines 19 to 39
40## Blocking — removing known nuisance variation
42A **block** is a group of units expected to be similar (same day, batch, litter,
43plate, instrument run). You randomize treatments *within* each block. The nuisance
44variation between blocks is then removed from the error term, so the treatment
45comparison is more precise — often dramatically so.
47Block on anything that (a) you can identify before the experiment and (b) you
48expect to affect the response but isn't of interest itself:
49- **Time:** day, week, session, processing batch.
50- **Space:** plate, plate position/edge, shelf, cage rack, field plot.
51- **Material:** reagent lot, animal litter, cell passage, donor.
52- **People/instruments:** technician, machine, sequencing run.
54Rule of thumb: *"Block what you can, randomize what you cannot."* If you suspect a
55factor matters but can't block it, at least randomize across it and record it as a
56covariate.
58**Randomized complete block design (RCBD):** every treatment appears once in every
59block. This is the workhorse design — analyze with treatment + block in the model.

Blocking — removing known nuisance variation

A block is a group of units expected to be similar (same day, batch, litter, plate, instrument run). You randomize treatments within each block. The nuisance variation between blocks is then removed from the error term, so the treatment comparison is more precise — often dramatically so.

Block on anything that (a) you can identify before the experiment and (b) you expect to affect the response but isn't of interest itself:

  • Time: day, week, session, processing batch.
  • Space: plate, plate position/edge, shelf, cage rack, field plot.
  • Material: reagent lot, animal litter, cell passage, donor.
  • People/instruments: technician, machine, sequencing run.

Rule of thumb: "Block what you can, randomize what you cannot." If you suspect a factor matters but can't block it, at least randomize across it and record it as a covariate.

Randomized complete block design (RCBD): every treatment appears once in every block. This is the workhorse design — analyze with treatment + block in the model.

Raw lines 40 to 60
61## Stratification vs. blocking vs. covariate adjustment
63These overlap; the distinction is about *when* you control the variable:
64- **Stratify / block at design time** when the factor is known before assignment and
65 you want treatment-count balance within completed blocks in its levels. This
66 does not guarantee balance on all covariates or within incomplete blocks.
67- **Adjust as a covariate at analysis time** (ANCOVA, regression) when the factor is
68 a pre-specified **baseline** variable, including a continuous prognostic factor.
69 Often you both stratify and adjust. Do not automatically adjust for a variable
70 measured after assignment: treatment may affect it, changing the estimand or
71 introducing bias. See the [FDA covariate guidance](https://www.fda.gov/media/148910/download).
73A few strata are better than many: stratifying on too many factors at once leaves
74strata with too few units to block effectively. For many covariates and small n,
75minimization is the alternative.

Stratification vs. blocking vs. covariate adjustment

These overlap; the distinction is about when you control the variable:

  • Stratify / block at design time when the factor is known before assignment and you want treatment-count balance within completed blocks in its levels. This does not guarantee balance on all covariates or within incomplete blocks.
  • Adjust as a covariate at analysis time (ANCOVA, regression) when the factor is a pre-specified baseline variable, including a continuous prognostic factor. Often you both stratify and adjust. Do not automatically adjust for a variable measured after assignment: treatment may affect it, changing the estimand or introducing bias. See the FDA covariate guidance.

A few strata are better than many: stratifying on too many factors at once leaves strata with too few units to block effectively. For many covariates and small n, minimization is the alternative.

Raw lines 61 to 76
77## Controls
79A comparison needs a concurrent baseline. Match the control to the threat you're
80ruling out:
81- **Untreated / standard-of-care control** — isolates the treatment effect from time.
82- **Vehicle / sham control** — isolates the active ingredient from the delivery
83 (injection stress, vehicle solvent, sham surgery).
84- **Positive control** — a treatment known to produce the effect, to confirm the
85 assay can detect one at all.
86- **Concurrent, not historical** — controls run at the same time as the treatment;
87 historical controls reintroduce time confounding.

Controls

A comparison needs a concurrent baseline. Match the control to the threat you're ruling out:

  • Untreated / standard-of-care control — isolates the treatment effect from time.
  • Vehicle / sham control — isolates the active ingredient from the delivery (injection stress, vehicle solvent, sham surgery).
  • Positive control — a treatment known to produce the effect, to confirm the assay can detect one at all.
  • Concurrent, not historical — controls run at the same time as the treatment; historical controls reintroduce time confounding.
Raw lines 77 to 88
89## Blinding
91Blinding prevents expectation from biasing measurement and behavior:
92- **Single-blind:** the subject doesn't know the assignment.
93- **Double-blind:** neither subject nor experimenter/assessor knows.
94- **Blinded outcome assessment:** at minimum, whoever measures the outcome shouldn't
95 know the group — cheap and high-value even in animal/bench work.
96Allocation concealment (the person enrolling can't foresee the next assignment) is
97distinct from blinding. A seed or CSV alone does not provide concealment: an
98independent allocator or access-controlled assignment system must release only
99the next allocation after eligibility/enrollment is irrevocably recorded. See
100[CONSORT 2025 allocation concealment](https://www.consort-spirit.org/item18-allocationconcealment).

Blinding

Blinding prevents expectation from biasing measurement and behavior:

  • Single-blind: the subject doesn't know the assignment.
  • Double-blind: neither subject nor experimenter/assessor knows.
  • Blinded outcome assessment: at minimum, whoever measures the outcome shouldn't know the group — cheap and high-value even in animal/bench work.

Allocation concealment (the person enrolling can't foresee the next assignment) is distinct from blinding. A seed or CSV alone does not provide concealment: an independent allocator or access-controlled assignment system must release only the next allocation after eligibility/enrollment is irrevocably recorded. See CONSORT 2025 allocation concealment.

Raw lines 89 to 101
102## Batch effects and plate layout (especially omics / HTS)
104Batch effects are systematic technical differences between processing groups and are
105a leading cause of irreproducible high-throughput results.
106- **Never let batch align with the biological condition.** If all cases are in batch
107 1 and all controls in batch 2, condition and batch are perfectly confounded and
108 no normalization can separate them.
109- **Randomize or block sample-to-batch and position-within-plate.** Spread each
110 condition across all batches and across plate positions.
111- **Avoid edge effects:** evaporation and thermal gradients make outer wells differ;
112 don't load all controls into edge columns. Randomize positions, or include
113 replicates spanning edge and interior.
114- **Include anchor/reference samples** in every batch to estimate and correct batch
115 shifts.
116- `assign_factorial_runs()` shuffles an existing table; it does not design a plate
117 map or preserve blocks automatically. Build and validate the plate/block/position
118 columns first, then apply randomization only within permitted groups. A whole-table
119 shuffle is unsuitable for a split-plot or other restricted randomization.

Batch effects and plate layout (especially omics / HTS)

Batch effects are systematic technical differences between processing groups and are a leading cause of irreproducible high-throughput results.

  • Never let batch align with the biological condition. If all cases are in batch 1 and all controls in batch 2, condition and batch are perfectly confounded and no normalization can separate them.
  • Randomize or block sample-to-batch and position-within-plate. Spread each condition across all batches and across plate positions.
  • Avoid edge effects: evaporation and thermal gradients make outer wells differ; don't load all controls into edge columns. Randomize positions, or include replicates spanning edge and interior.
  • Include anchor/reference samples in every batch to estimate and correct batch shifts.
  • assign_factorial_runs() shuffles an existing table; it does not design a plate map or preserve blocks automatically. Build and validate the plate/block/position columns first, then apply randomization only within permitted groups. A whole-table shuffle is unsuitable for a split-plot or other restricted randomization.
Raw lines 102 to 120
121## Documentation
123Record, and ideally pre-register: the randomization method, the seed, block sizes,
124stratification factors, package/script versions, the schedule itself, and the planned analysis (which must
125include block/stratum/cluster terms). This is what makes the study auditable and the
126primary analysis confirmatory rather than exploratory.
128For sequence inputs to `stratified_block_randomization`, `unit_id` is the original
129one-based position; preserve the subject-ID mapping before joining. Dict inputs
130represent grouped future slots. Check complete-block counts separately from overall
131counts and examine the incomplete final block in each stratum. Zero is a valid
132cohort size; negative/fractional counts, zero block sizes, missing strata, duplicate
133arms, and duplicate cluster IDs are invalid.

Documentation

Record, and ideally pre-register: the randomization method, the seed, block sizes, stratification factors, package/script versions, the schedule itself, and the planned analysis (which must include block/stratum/cluster terms). This is what makes the study auditable and the primary analysis confirmatory rather than exploratory.

For sequence inputs to stratified_block_randomization, unit_id is the original one-based position; preserve the subject-ID mapping before joining. Dict inputs represent grouped future slots. Check complete-block counts separately from overall counts and examine the incomplete final block in each stratum. Zero is a valid cohort size; negative/fractional counts, zero block sizes, missing strata, duplicate arms, and duplicate cluster IDs are invalid.

Raw lines 121 to 133