Tutorials › High-Dimensional Genomic Data Analysis › Blocking and Paired Designs for Batch Control

Normalization and Batch Effects · Tutorial 92 of 795

Blocking and Paired Designs for Batch Control

Build paired and blocked design matrices, use within-unit contrasts to isolate treatment effects, and recognize when batch and biology cannot be separated.

Intermediate 10 min read

What You'll Learn

  • Represent paired samples with subject indicators and a biological-condition column.
  • Derive how within-subject differences remove stable subject and batch offsets.
  • Distinguish batch offsets that cancel from those that remain in paired contrasts.
  • Build blocked design matrices and identify when treatment effects are estimable.
  • Diagnose rank deficiency, imbalance, and complete batch-condition confounding.
  • Choose between paired contrasts, fixed blocking, and an unpaired comparison.

Why Pairing and Blocking Matter

In genomic studies, a measured expression value can reflect both biology and technical circumstances: the sample’s condition, the individual it came from, and the laboratory batch in which it was processed. A paired or blocked design arranges comparisons so that some sources of variation are controlled by design, rather than left to be handled after data collection. The central question is whether the biological comparison varies independently enough from batch and subject effects to be identified.

The discussion below concerns a single gene at a time, using normalized or transformed expression values for which an additive linear model is a reasonable working approximation. The design-matrix principles apply across genes. They do not make an unsuitable measurement scale or an invalid error model appropriate; those must be assessed separately.

Definition: A paired design measures two conditions on the same subject or matched unit, so the biological comparison is made within that unit. A blocked design groups experimental units into blocks that share a relevant nuisance feature, then arranges the treatments so that comparisons can be made within blocks. A design matrix is the matrix whose rows represent samples and whose columns encode model terms, such as condition, subject, or batch.

Model and Design-Matrix Logic

For sample \(i\) and gene \(g\), consider the additive model

$$ y_{ig}=\mu_g+\tau_g T_i+\alpha_{s(i),g}+\gamma_{b(i),g}+\varepsilon_{ig}. $$

Here \(y_{ig}\) is the expression value, \(\mu_g\) is a reference level, \(T_i\) indicates the biological condition of interest, \(\tau_g\) is its effect, \(\alpha_{s(i),g}\) is a subject or block effect, and \(\gamma_{b(i),g}\) is a batch effect. The error \(\varepsilon_{ig}\) is the remaining sample-level variation. A reference level or an equivalent constraint is needed for categorical terms so the model is parameterized without redundant columns.

For ordinary least-squares interpretation, assume the mean is correctly represented by the included terms, the relevant treatment contrast is identifiable, and errors have conditional mean zero. For standard model-based uncertainty calculations, also assume errors are independent across independent experimental units and have a common variance, unless the analysis explicitly uses a suitable alternative. Paired observations from the same subject need not be independent in their original form; the within-subject contrast is the natural unit for assessing their variation. If subjects are independent, those contrasts can be modeled as independent across subjects.

The key design question is not simply whether the matrix has one column for every factor. It is whether the effect of interest can be distinguished from the other columns. A model matrix may be rank deficient, yet a particular contrast such as \(\tau_g\) can still be estimable. Conversely, software returning coefficients does not establish that the biological effect is separated from batch.

Key result: A within-subject contrast removes any additive effect that is constant across the two measurements from that subject. It removes a batch offset only when the two measurements share the same batch, or when batch differences can be estimated from other, sufficiently varied comparisons in the design.

Why the Within-Subject Contrast Works

For a subject observed in control and treated conditions, write the two values as \(y_{s,C,g}\) and \(y_{s,T,g}\). Subtracting the control value from the treated value gives

$$ d_{s,g}=y_{s,T,g}-y_{s,C,g} =\tau_g+\left(\gamma_{b(s,T),g}-\gamma_{b(s,C),g}\right) +\left(\varepsilon_{s,T,g}-\varepsilon_{s,C,g}\right). $$

The subject-specific baseline \(\alpha_{s,g}\) cancels because it is present in both measurements. If both samples were processed in the same batch, the batch term also cancels. Averaging the \(d_{s,g}\) values across subjects then estimates the common treatment effect, provided the model and sampling assumptions are reasonable.

If the paired samples were processed in different batches, the contrast still removes the subject baseline, but it retains the difference in batch offsets. Treating every paired difference as a pure biological effect in that situation is not justified. Batch must either be balanced or estimable through the full design, or the biological and technical effects may remain inseparable.

Worked Example: Same-Batch Pairs Remove Stable Offsets

Suppose five hypothetical subjects each provide a control and a treated sample. Both samples from each subject are processed in the same batch; different subjects may be processed in different batches. The transformed expression values for one gene are:

SubjectBatchControlTreatedWithin-subject difference
1A6.17.31.2
2A5.46.20.8
3B7.08.51.5
4B6.57.51.0
5C5.87.31.5

For each subject, the control and treated values share both the subject and batch terms. The contrast therefore removes both additive offsets. The mean paired difference is

$$ \bar{d}_g=\frac{1.2+0.8+1.5+1.0+1.5}{5} =\frac{6.0}{5}=1.20. $$

The estimated mean change is 1.20 transformed-expression units for this gene. This is a within-subject estimate, not a claim that batch effects have been separately estimated: because each subject belongs to only one batch, subject and batch indicators are redundant if both are included as fixed effects. The biological contrast is nevertheless available from the paired differences.

For two subjects, one possible design-matrix structure has columns for an intercept, treatment, and a subject indicator:

$$ \begin{array}{c|ccc} & 1 & T & \text{Subject 2}\\ \text{Subject 1, control} & 1&0&0\\ \text{Subject 1, treated} & 1&1&0\\ \text{Subject 2, control} & 1&0&1\\ \text{Subject 2, treated} & 1&1&1 \end{array} $$

With more subjects, additional subject-indicator columns are added. A batch column that is constant within each subject is a combination of subject indicators, so its separate coefficient is not identified in this design. Adding that redundant column does not improve the treatment comparison.

When Batch Changes Within a Pair

Pairs split across batches need more careful treatment. The batch contribution to each difference may be nonzero, but it can sometimes be separated from treatment if the assignments create enough independent variation. The model must include the relevant batch term, and the design matrix must support the desired contrast.

Worked Example: Balanced Batch Switching

Consider two hypothetical subjects. Subject 1 has control in batch A and treated in batch B; subject 2 has control in batch B and treated in batch A. Their values for one gene are respectively 10, 14, 13, and 15. Use an intercept, a subject-2 indicator, a treatment indicator, and a batch-B indicator. The design matrix and outcomes are:

$$ \begin{array}{c|rrrr|r} & 1 & \text{Subject 2} & T & \text{Batch B} & y\\ \text{Subject 1, control, A} & 1&0&0&0&10\\ \text{Subject 1, treated, B} & 1&0&1&1&14\\ \text{Subject 2, control, B} & 1&1&0&1&13\\ \text{Subject 2, treated, A} & 1&1&1&0&15 \end{array} $$

Let \(\tau_g\) denote the treatment effect and \(\gamma_g\) the difference for batch B relative to A. The within-subject differences are 14 − 10 = 4 and 15 − 13 = 2. From the batch assignments, these satisfy

$$ 4=\tau_g+\gamma_g,\qquad 2=\tau_g-\gamma_g. $$

Adding the equations gives \(6=2\tau_g\), so \(\tau_g=3\). Subtracting the second equation from the first gives \(2=2\gamma_g\), so \(\gamma_g=1\). Thus the fitted treatment and batch offsets are 3 and 1 expression units, respectively. The design has enough crossing to distinguish the two terms algebraically. It is saturated, however: four observations estimate four coefficients, leaving no residual degrees of freedom for estimating residual variance or making a reliable uncertainty statement. Identifiability alone does not guarantee precise inference.

Blocked Experiments

Blocking generalizes the paired idea. A block can be a subject, a processing day, a plate, or another grouping defined before analysis. To estimate a treatment effect separately from block offsets, the treatment comparison must occur within blocks, or there must otherwise be adequate overlap between treatment and block. For example, if each processing batch contains both control and treated samples, batch can be represented as a nuisance factor while estimating the treatment effect.

In a balanced design with one control and one treated unit per block, the treatment estimate under an additive block model is the average of the within-block differences. The same comparison can be obtained by fitting a model with block indicators and a treatment column. The equality follows because each block contributes one control and one treated observation, so subtracting within blocks cancels the block intercept before averaging.

Worked Example: Treatment Comparisons Within Blocks

Suppose three hypothetical processing blocks each contain one control and one treated sample. Expression values for a gene are 8 and 10 in block 1, 9 and 13 in block 2, and 7 and 10 in block 3. The within-block differences are \(10-8=2\), \(13-9=4\), and \(10-7=3\). The common additive treatment-effect estimate is

$$ \hat{\tau}_g=\frac{2+4+3}{3}=\frac{9}{3}=3 $$

expression units. For a reference block coding, the six rows of a design matrix with columns for intercept, treatment, block 2, and block 3 are:

$$ \begin{array}{c|rrrr} & 1&T&\text{Block 2}&\text{Block 3}\\ \text{Block 1, control}&1&0&0&0\\ \text{Block 1, treated}&1&1&0&0\\ \text{Block 2, control}&1&0&1&0\\ \text{Block 2, treated}&1&1&1&0\\ \text{Block 3, control}&1&0&0&1\\ \text{Block 3, treated}&1&1&0&1 \end{array} $$

All blocks include both conditions, so the treatment column is not a linear combination of the block columns. The variation in differences, 2, 4, and 3 around their mean of 3, also reminds us that a common-effect model is an assumption. With only three blocks, these data provide little information about how treatment effects vary among blocks.

Assumptions, Diagnostics, and Alternatives

A design matrix cannot repair a design that never separated treatment from batch. If all controls were processed in batch A and all treated samples in batch B, the treatment indicator and batch indicator are identical. Their separate effects are not estimable: the observed difference is compatible with many treatment and batch contributions. No regression adjustment can determine which contribution caused it without additional assumptions or external information.

Useful checks include tabulating the number of samples for every condition-by-batch combination, verifying that each intended pair has both measurements, and inspecting the model matrix for duplicate or dependent columns. Check whether the proposed treatment contrast is estimable, not merely whether a fitting program produced output. Also inspect within-pair differences or model residuals for outliers, unequal variability, and patterns associated with batch. A contrast that still tracks batch is a warning that the offset did not cancel or that the design is not adequately balanced.

The main alternatives answer related but distinct questions. An unpaired comparison ignores the within-subject structure and can waste information or misstate uncertainty when observations from the same subject are related. A paired-difference analysis is transparent when pairs are complete and the same-batch offset cancels. A fixed-effect blocked model gives the same treatment comparison in the balanced paired case and can accommodate incomplete blocks when the effect remains identifiable. A random-effects model is another option when blocks are regarded as sampled from a broader population and its assumptions are appropriate; it does not remove the need for treatment and batch overlap.

Pairing can also fail operationally: missing one member of a pair prevents its direct difference from being calculated, and a systematic pattern of missingness can bias the comparison. Additive models may be inadequate if batch effects differ by condition or biological effects vary across blocks. Finally, statistical control of a known batch term is not the same as proving that all technical artifacts have been removed. The earlier material on linear adjustment for known batch effects addresses that adjustment; the design determines whether the biological term can be estimated in the first place.

Common mistake: “The samples are paired, so subtracting within each subject removes batch.” This is true only if the paired samples share the same batch, or if batch differences can be estimated from a sufficiently crossed design. Otherwise, the difference contains both treatment and batch contributions.
1
Map the observations.
Make a sample-level table listing subject or block, biological condition, and processing batch.
2
Write the intended model.
Specify which columns encode the biological contrast and which encode nuisance structure.
3
Check overlap and estimability.
Confirm that the biological contrast is distinguishable from block and batch columns before interpreting its estimate.
4
Interpret the contrast in context.
State which offsets cancel, which remain, and what assumptions are needed for the estimated expression difference to represent biology.

Check Your Understanding

Work through each question, then compare with the solutions.

  1. Two conditions are measured on each subject, with both samples from a subject processed in the same batch. Which additive terms cancel in the paired difference?
  2. Every control is processed in batch A and every treated sample in batch B. Can a model with treatment and batch indicators separately estimate both effects? Why?
  3. In a balanced three-block experiment, the within-block treatment differences are 1, 2, and 6 expression units. What is the common additive treatment estimate?
  4. Why can a paired treatment estimate be identifiable even if a separate batch coefficient is not?

Solutions. (1) Both the subject-specific intercept and the shared batch offset cancel; the difference retains the treatment effect and the difference between the two errors. (2) No. The treatment and batch indicators coincide, so their separate coefficients are not identifiable. (3) The estimate is \((1+2+6)/3=9/3=3\) expression units. (4) If batch is constant within each subject, its indicator may be redundant with subject indicators, while the treatment indicator still varies within subjects. The within-subject treatment contrast can therefore be estimable without estimating a separate batch coefficient.

Clinical Biostats