Tutorials › Multi-Omics Data Integration › Fixed-Effect and Random-Effect Batch Adjustment

Batch Effects and Confounding Across Cohorts · Tutorial 100 of 597

Fixed-Effect and Random-Effect Batch Adjustment

Learn when to model batch as fixed or random, how random-effect shrinkage works, and what each choice assumes about the batches and the study design.

Advanced 10 min read

What You'll Learn

  • Distinguish batch-specific fixed effects from exchangeable random batch deviations.
  • State the assumptions required for fixed-effect and random-effect batch models.
  • Derive and calculate the amount of shrinkage in a random-intercept model.
  • Compare the models when batches are few, numerous, or unevenly sampled.
  • Recognize how confounding, weak design connectivity, and model misspecification limit adjustment.

Why the Choice of Batch Model Matters

A batch term represents systematic differences associated with processing groups, such as assay runs, laboratories, or platforms. In an additive model, including this term can help estimate biological contrasts without attributing batch-associated shifts to biology. The modeling choice matters because a fixed-effect model estimates a separate effect for each observed batch, whereas a random-effect model treats batch deviations as draws from a shared distribution. Those models answer related but distinct questions: what are the effects of these particular batches, and what is the distribution of effects across a population of batches?

The distinction is not a device for repairing a poor design. As established in the earlier material on rank, connectivity, and confounding, a biological effect cannot be separated from a batch effect when the observed design does not identify that contrast. Treating batch as random does not create the missing comparison. The choice also does not determine whether an adjustment is safe: a model can remove real biological signal if biology and batch are confounded or if relevant biology is omitted.

Definition: A fixed batch effect is an unknown, batch-specific parameter estimated for each observed batch, without assuming that the parameters are draws from a common probability distribution. A random batch effect is a random deviation assigned a probability distribution, commonly \(u_b\sim N(0,\tau^2)\), where \(b\) indexes batches and \(\tau^2\) is the between-batch variance.

Two Models for a Batch Term

For one omics feature, let \(y_{ib}\) be the measured value for sample \(i\) in batch \(b\). Let \(x_{ib}\) denote the measured biological and other design covariates, and let \(\beta\) be their coefficient vector. A fixed-effect model can be written as

$$ y_{ib}=x_{ib}^{T}\beta+\alpha_b+\varepsilon_{ib}. $$

Here \(\alpha_b\) is the fixed effect for batch \(b\). To identify the intercept and batch terms, use a reference-batch constraint such as \(\alpha_1=0\), or a stated sum-to-zero constraint. Either parameterization gives the same fitted values and estimable contrasts. The effects need not follow a distribution across batches.

A random-intercept model instead writes

$$ y_{ib}=x_{ib}^{T}\beta+u_b+\varepsilon_{ib}, \qquad u_b\sim N(0,\tau^2), \qquad \varepsilon_{ib}\sim N(0,\sigma^2). $$

The usual model assumes the batch deviations are independent across batches, the residual errors are independent across samples conditional on the batch effects, and the two sets of random terms are independent of one another. It also assumes the random batch effects are independent of the included covariates. For standard small-sample likelihood-based inference, normality and a correctly specified mean and variance structure are commonly assumed; the distributional assumptions should not be confused with the design requirement that the biological contrast be identifiable.

A fixed model is often natural when inference concerns a small, particular set of observed batches. A random model is often useful when the batches can reasonably be regarded as exchangeable representatives of a broader population, especially when there are many batches or their sample sizes vary. In either case, covariates and batch structure must be represented so the desired biological contrast is estimable.

Worked Example: Estimating Effects for Three Observed Batches

Suppose a hypothetical feature has the following measurements, with two samples in each batch. There are no biological covariates in this illustration, so the fixed-effect model is a one-way batch model.

Batch A has measurements 10 and 12, with mean 11. Batch B has measurements 14 and 16, with mean 15. Batch C has measurements 11 and 13, with mean 12. The overall mean is

$$ \bar{y}=\frac{10+12+14+16+11+13}{6} =\frac{76}{6}=12.667. $$

With equal batch sizes, use a sum-to-zero constraint on the three batch effects. The fitted intercept is the overall mean, and the batch effects are the differences between each batch mean and that intercept:

$$ \hat{\alpha}_A=11-12.667=-1.667,\qquad \hat{\alpha}_B=15-12.667=2.333,\qquad \hat{\alpha}_C=12-12.667=-0.667. $$

The effects sum to zero, apart from rounding. The fitted batch mean for B is \(12.667+2.333=15\). If values are adjusted to the overall mean by subtracting the estimated batch effect, a measurement of 14 in B becomes \(14-2.333=11.667\). This is an estimate for these observed batches; the model has not assumed that their effects are draws from a population distribution.

The calculation assumes that an additive batch mean adequately describes the batch differences, and that there are no additional covariates needing adjustment. With only two observations per batch, the data provide limited information for checking the residual distribution or variance assumptions; the arithmetic estimates effects but does not verify those assumptions.

Random Effects and Partial Pooling

A random-effect model does not estimate each batch independently of the others. Instead, it combines the batch’s own data with the assumed distribution of batch effects. This is called shrinkage: an estimated batch deviation is pulled toward the population mean of zero. The pull is stronger when the batch has little information and weaker when it has more information.

The mechanism can be derived for a simple case. Suppose covariate contributions are known or removed, leaving residual values \(r_{ib}=y_{ib}-x_{ib}^{T}\beta\) in batch \(b\). Assume \(r_{ib}=u_b+\varepsilon_{ib}\), with \(u_b\sim N(0,\tau^2)\) and independent \(\varepsilon_{ib}\sim N(0,\sigma^2)\). Let \(\bar{r}_b\) be the mean residual for that batch. The likelihood for \(u_b\), up to a factor not depending on \(u_b\), is proportional to \(\exp[-n_b(\bar{r}_b-u_b)^2/(2\sigma^2)]\). Multiplying by the normal prior density for \(u_b\) adds the term \(u_b^2/(2\tau^2)\) in the exponent. Completing the square gives the conditional distribution of \(u_b\) given the residual data:

$$ u_b\mid \bar{r}_b \sim N\left( \frac{n_b\tau^2}{\sigma^2+n_b\tau^2}\bar{r}_b,\, \frac{\sigma^2\tau^2}{\sigma^2+n_b\tau^2} \right). $$

The conditional mean is the best linear predictor in this simple normal model. Its multiplier on the unpooled batch mean is between zero and one:

$$ \lambda_b=\frac{n_b\tau^2}{\sigma^2+n_b\tau^2}. $$

For a small batch, \(n_b\) is small and \(\lambda_b\) is closer to zero, so the estimate is pulled more toward zero. For a large batch, \(\lambda_b\) is closer to one, so the batch’s observed mean has more influence. In practice, \(\tau^2\), \(\sigma^2\), and \(\beta\) are usually estimated from the full data; treating the variance components as known is an explanation of the shrinkage mechanism, not a claim that they are known.

Worked Example: Uneven Batch Sizes and Shrinkage

Consider a hypothetical random-intercept analysis in which the fitted residual variance components are treated as known for illustration: \(\tau^2=4\) and \(\sigma^2=9\), in squared assay units. A small batch has one residual value, 5, so its residual mean is 5. A larger batch has nine residuals \(3,4,4,5,5,5,6,6,7\), whose mean is also \(45/9=5\).

For the batch with one sample, the shrinkage factor and predicted deviation are

$$ \lambda_{\text{small}}=\frac{1(4)}{9+1(4)}=\frac{4}{13}=0.3077, \qquad \hat{u}_{\text{small}}=0.3077(5)=1.538. $$

For the batch with nine samples, they are

$$ \lambda_{\text{large}}=\frac{9(4)}{9+9(4)}=\frac{36}{45}=0.8000, \qquad \hat{u}_{\text{large}}=0.8000(5)=4.000. $$

Although both unpooled residual means equal 5 assay units, the random-effect predictions differ: 1.538 assay units for the small batch and 4.000 for the larger one. The small batch receives stronger shrinkage because its mean is less precisely estimated. This result is conditional on the model and the assumed variance components; it is not evidence that the smaller batch’s true effect must be closer to zero.

Choosing Between the Models

The choice depends on the scientific target, the number and sampling of batches, and the design. A fixed-effect model has fewer distributional assumptions about batch effects and directly represents the observed batch levels. Its cost is that it estimates many batch parameters as the number of batches grows. A random-effect model uses a shared variance distribution and partial pooling, which can stabilize estimates, but its conclusions depend on the exchangeability and distribution assumptions.

SituationFixed batch effectsRandom batch effects
Few batches; interest is in these specific levelsOften straightforward; estimate each observed level directly.Between-batch variance can be difficult to estimate reliably with very few levels.
Many batches viewed as a broader populationUses a separate parameter per batch and can consume substantial degrees of freedom.Can estimate a shared between-batch variance and partially pool batch estimates.
Unequal batch sizesSmall batches still receive their own estimates, which may be imprecise.Shrinkage is stronger for less precise, smaller-batch estimates under the model.
Batch effects plausibly related to included covariatesDoes not require random effects to be independent of covariates.The usual random-intercept model’s independence assumption may be inappropriate.

These are tendencies, not automatic selection rules. A few batches do not guarantee that fixed effects will be adequate: a biological contrast may still be unidentifiable, or residual assumptions may be poor. Likewise, many batches do not guarantee that a random-effect model is appropriate: the observed batches may be the specific targets of inference, or their effects may not be plausibly exchangeable. A random-effect distribution is especially questionable when batch labels represent systematically different settings rather than levels drawn from a common population.

Worked Example: A Biological Contrast Within Each Batch

Suppose a hypothetical study measures a feature in control and treated samples in two batches. Batch A has control values 10 and 12, and treated values 14 and 16. Batch B has control values 20 and 22, and treated values 23 and 25. Both conditions occur in both batches, so the treatment contrast is represented within each batch.

The treatment difference in A is

$$ \bar{y}_{A,\text{treated}}-\bar{y}_{A,\text{control}} =\frac{14+16}{2}-\frac{10+12}{2} =15-11=4. $$

The treatment difference in B is

$$ \bar{y}_{B,\text{treated}}-\bar{y}_{B,\text{control}} =\frac{23+25}{2}-\frac{20+22}{2} =24-21=3. $$

With equal numbers of observations in the four condition-by-batch cells, the additive fixed-effect model’s common treatment estimate is the average of the two within-batch contrasts:

$$ \hat{\beta}_{\text{treatment}}=\frac{4+3}{2}=3.5 \text{ assay units}. $$

This is an adjusted association between treatment status and the measured feature, conditional on the additive model; it is not, by itself, proof of a causal treatment effect. The example assumes a common treatment effect across batches, independent errors, and an adequate residual variance model. The observed contrast differs between batches, but with these small samples that difference alone is not enough to establish a treatment-by-batch interaction. If one condition appeared only in one batch, its effect could not be separated from that batch’s effect by this comparison.

Diagnostics, Failure Modes, and Limits

Batch-model diagnostics should address both the design and the model assumptions. Before interpreting adjusted estimates, check that the biological contrasts of interest are estimable and that the design contains the comparisons needed to separate those contrasts from batch. Then examine whether residual patterns, outliers, or markedly different within-batch variability make the assumed error model implausible. Residual checks can reveal problems but cannot prove that batch levels are exchangeable or that confounding is absent.

  • Too few random-effect levels: estimates of \(\tau^2\) can be unstable or near a boundary. Report that limitation and consider whether inference about the observed batches is more appropriate than inference about a batch population.
  • Very small or highly uneven batches: fixed estimates for small batches can be noisy; random effects can shrink them strongly. Check how sensitive the biological estimate is to the batch specification rather than treating shrinkage as automatic correction.
  • Batch associated with biology: the random-effect assumption that batch deviations are independent of included covariates may fail. A fixed-effect formulation avoids that particular distributional independence assumption, but it cannot recover a biological contrast that the design does not identify.
  • Unmodeled variation in biological effects: a single additive treatment coefficient assumes the treatment contrast is common across batches. If that assumption is scientifically implausible, a common-effect estimate may conceal heterogeneity.
  • Uncertainty after adjustment: subtracting estimated batch effects and then treating the adjusted values as known can understate uncertainty. Prefer inference from the fitted model when uncertainty in batch estimates matters.

A frequent mistake is to claim that a random-effect model is always superior because it “corrects” small batches by borrowing information. The correction is conditional on the assumed common distribution and independence structure; if those assumptions are wrong, shrinkage can pull estimates in an inappropriate direction. The converse mistake is to insist that fixed effects are assumption-free. They avoid a probability distribution for the batch coefficients, but still require an adequate outcome model, identifiable contrasts, and defensible error assumptions.

Key takeaway: Use fixed effects to represent particular observed batches without assuming they are sampled from a common distribution. Use random effects when a shared, exchangeable batch population is scientifically credible and partial pooling is useful. Neither choice repairs confounding or substitutes for a design that identifies the biological contrast.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. In one sentence, distinguish the target of a fixed batch-effect model from that of a random batch-effect model.
  2. If \(n_b=2\), \(\tau^2=3\), \(\sigma^2=6\), and the batch residual mean is 4 assay units, calculate the shrinkage factor and predicted random batch deviation.
  3. Why can a random-effect model be problematic when only two batches are available?
  4. If treatment occurs only in batch A and control only in batch B, does modeling batch as random identify the treatment contrast? Explain.

Solutions. (1) A fixed model estimates effects for the particular observed batches; a random model treats their deviations as draws from a shared distribution and targets that distribution as well as the modeled biological effects. (2) \(\lambda_b=2(3)/(6+2(3))=6/12=0.5\), so \(\hat{u}_b=0.5(4)=2\) assay units. (3) Two levels provide little information about the between-batch variance, so its estimate may be unstable and distributional conclusions are weakly supported. (4) No. Treatment and batch are perfectly confounded in this design, so the observed difference cannot be separated into treatment and batch components by changing the batch model.

Clinical Biostats