references/randomization_and_blocking.md
7.6 KB查看排版效果| 1 | # Randomization, Blocking, Stratification, and Controls |
| 2 | |
| 3 | These are the tools of *local control*: removing or balancing nuisance variation so |
| 4 | the comparison you care about is clean. Randomization handles the unknown |
| 5 | confounders; blocking and stratification handle the known ones; controls and |
| 6 | blinding handle the systematic biases. |
| 7 | |
| 8 | ## Randomization — why and how |
| 9 | |
| 10 | Randomization assigns treatments to units by chance, so that in expectation every |
| 11 | confounder (measured or not, known or unknown) is balanced across arms. This is the |
| 12 | foundation of causal inference: without it, an observed difference could always be |
| 13 | due to some variable that happened to track the grouping. |
| 14 | |
| 15 | Use a **seeded, reproducible** schedule (see `scripts/randomization.py`) and follow |
| 16 | it exactly. Record the seed. "I randomized somehow" is neither auditable nor |
| 17 | reproducible. |
| 18 | |
| 19 | ### Methods (and when each is right) |
| 20 | |
| 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) | |
| 28 | |
| 29 | **Simple randomization caveat:** with small n it behaves like flipping a few coins — |
| 30 | you can easily get 12 vs. 8 instead of 10 vs. 10, and worse for subgroups. Blocking |
| 31 | controls this at complete-block boundaries; a partial block can remain imbalanced. |
| 32 | |
| 33 | **Block size:** must be a multiple of the ratio unit (e.g. for 1:1, sizes 2, 4, 6). |
| 34 | Smaller 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 |
| 36 | size with an appropriate allocation system when predictability matters. The bundled |
| 37 | helper supports a fixed size only; it does not implement concealment or variable |
| 38 | block sizes. Never give recruiting staff the seed or future schedule. |
| 39 | |
| 40 | ## Blocking — removing known nuisance variation |
| 41 | |
| 42 | A **block** is a group of units expected to be similar (same day, batch, litter, |
| 43 | plate, instrument run). You randomize treatments *within* each block. The nuisance |
| 44 | variation between blocks is then removed from the error term, so the treatment |
| 45 | comparison is more precise — often dramatically so. |
| 46 | |
| 47 | Block on anything that (a) you can identify before the experiment and (b) you |
| 48 | expect 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. |
| 53 | |
| 54 | Rule of thumb: *"Block what you can, randomize what you cannot."* If you suspect a |
| 55 | factor matters but can't block it, at least randomize across it and record it as a |
| 56 | covariate. |
| 57 | |
| 58 | **Randomized complete block design (RCBD):** every treatment appears once in every |
| 59 | block. This is the workhorse design — analyze with treatment + block in the model. |
| 60 | |
| 61 | ## Stratification vs. blocking vs. covariate adjustment |
| 62 | |
| 63 | These 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). |
| 72 | |
| 73 | A few strata are better than many: stratifying on too many factors at once leaves |
| 74 | strata with too few units to block effectively. For many covariates and small n, |
| 75 | minimization is the alternative. |
| 76 | |
| 77 | ## Controls |
| 78 | |
| 79 | A comparison needs a concurrent baseline. Match the control to the threat you're |
| 80 | ruling 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. |
| 88 | |
| 89 | ## Blinding |
| 90 | |
| 91 | Blinding 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. |
| 96 | Allocation concealment (the person enrolling can't foresee the next assignment) is |
| 97 | distinct from blinding. A seed or CSV alone does not provide concealment: an |
| 98 | independent allocator or access-controlled assignment system must release only |
| 99 | the next allocation after eligibility/enrollment is irrevocably recorded. See |
| 100 | [CONSORT 2025 allocation concealment](https://www.consort-spirit.org/item18-allocationconcealment). |
| 101 | |
| 102 | ## Batch effects and plate layout (especially omics / HTS) |
| 103 | |
| 104 | Batch effects are systematic technical differences between processing groups and are |
| 105 | a 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. |
| 120 | |
| 121 | ## Documentation |
| 122 | |
| 123 | Record, and ideally pre-register: the randomization method, the seed, block sizes, |
| 124 | stratification factors, package/script versions, the schedule itself, and the planned analysis (which must |
| 125 | include block/stratum/cluster terms). This is what makes the study auditable and the |
| 126 | primary analysis confirmatory rather than exploratory. |
| 127 | |
| 128 | For sequence inputs to `stratified_block_randomization`, `unit_id` is the original |
| 129 | one-based position; preserve the subject-ID mapping before joining. Dict inputs |
| 130 | represent grouped future slots. Check complete-block counts separately from overall |
| 131 | counts and examine the incomplete final block in each stratum. Zero is a valid |
| 132 | cohort size; negative/fractional counts, zero block sizes, missing strata, duplicate |
| 133 | arms, and duplicate cluster IDs are invalid. |
文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。

