TL;DR
A batch effect is a difference in measurements that comes from how samples were handled, not from the biology being studied. Samples prepared on one day, by one person, with one lot of reagent, often differ from samples prepared on another day in ways that have nothing to do with the question. The effect can be removed with a model of the batches, but only if the batches are not tangled up with the biology.
Builds on: RNA Sequencing, which counts reads per gene, and Linear Regression, which estimates a shift between groups · Leads to: Differential Expression Analysis, where a batch effect can look like a gene that is switched on, and Harmony, a method for merging many batches of single-cell data
Where it's used
Single-cell atlases. A study that profiles many cells often runs them in several batches, because one run cannot hold every sample. When the batches are merged, the cells from one batch can cluster apart from the cells of the same type in another batch. Researchers must separate that clustering from real differences between cell types before they name the clusters.
Gene expression studies. A lab that compares patient and control samples over several months will often process the groups on different dates. Any gene expression level that shifts with the date will look different between the groups, even when the biology is the same. Analysts use differential expression analysis to find real differences, and they need a batch term in the model so that batch differences are not called real.
Microarray and sequencing archives. Public datasets are often combined from many labs and many years. Their processing differs, so combining them without correction can make unrelated studies look alike or different. This was a widely reported problem in the 2000s, when microarray data were first pooled at scale.
How it works
Take one gene measured in four samples. The biology is the same in every sample, so the true level is the same everywhere. The samples were processed in two batches, A and B, and the measured values are these:
| Sample | Batch | Measured value |
|---|---|---|
| 1 | A | 10 |
| 2 | A | 12 |
| 3 | B | 16 |
| 4 | B | 18 |
Batch B reads about 6 higher than batch A, even though the biology is identical. The steps below find that shift and remove it.
-
Detect the batches. A first check is to plot the samples on their two largest directions of variation with Principal Component Analysis. If the samples split by batch rather than by biology, a batch effect is present. Here the two batches are already obvious from the values. Check: the batch means are 11 for A and 17 for B, a gap of 6.
-
Compute the overall mean. Add all four values and divide by four. . This is the level the data would have if there were no batches. Check: two values sit below 14 and two above, as expected.
-
Find each batch's offset. The offset is the batch mean minus the overall mean. For batch A it is . For batch B it is . Check: the two offsets sum to zero, so the correction does not shift the whole dataset.
-
Subtract the offset. Batch A samples become and . Batch B samples become and . Check: both batches now have mean 14, and the gap of 6 is gone.
-
Check that the biology survived. The within-batch spread, 13 and 15 in each batch, is unchanged. The correction moved the batches, not the samples within them. Check: the spread of 2 within each batch is the same before and after.
Step 3 is the key step. The offsets are estimated from the batch means, and the correction is only correct when each batch contains a similar mix of biology. If batch A held all the controls and batch B all the patients, the offset would also remove the real difference between them.
The math
For a measured value from sample in batch , a simple model is where is the overall level, is the offset of batch , and is the noise. When each offset is weighted by its batch size, the offsets sum to zero, so is the average over all samples.
In words: every sample is the overall level, plus the shift of its batch, plus random noise. Correction means estimating the and subtracting them.
Step 1 in symbols: the batches as indicator variables
Write one indicator for batch B, which is 1 for a sample in batch B and 0 otherwise. Then the model is a linear regression on : Here is the mean of batch A and is the difference between the batch means.
Step 2 in symbols: the least-squares estimates
With the indicator model, and . These match the measured gap of 6 in the walkthrough. The offsets in the sum-to-zero form are With , and , this gives and .
Step 3 in symbols: the correction
The corrected value is . For sample 2 in batch A, . For sample 3 in batch B, . Both batches now have mean .
Step 4 in symbols: the check
After correction, the batch means are equal by construction. A useful check is that the residual spread within each batch matches the spread before correction, since only the mean was moved.
Worked examples
Use the four values from the walkthrough: batch A holds 10 and 12, and batch B holds 16 and 18.
- Batch means: and .
- Gap: .
- Overall mean: .
- Offsets: for A and for B.
- Corrected values: for batch A and for batch B.
Interpretation: after the correction the four samples form two identical groups, so the gap that came from processing has been removed.
A gene is measured in batch A, with three samples at 8, 9 and 10, and in batch B, with one sample at 14. The batches have different sizes, so the overall mean must weight each sample equally.
- Overall mean over all four samples: .
- Batch A mean: .
- Batch B mean: , since there is one sample.
- Offsets: for A and for B.
- Check: the offsets weighted by sample count sum to zero: .
- Corrected sample in batch B: .
Interpretation: the single sample in batch B is pulled to the overall mean. With one sample, its batch offset is estimated from very little data, which is a warning sign. The estimate is noisy, and this is where the methods in the tradeoffs section help.
A single-cell study measures a gene as a log2-normalised expression value. The cells were run in three batches with equal numbers of cells in each, and the batch means were , and .
- Overall mean: .
- Offset for batch 1: .
- Offset for batch 2: .
- Offset for batch 3: .
- Check: the three offsets sum to about zero: .
- Corrected cell in batch 2 with a measured value of 5.6: .
Try it: a cell from batch 3 has a measured value of 3.9. What is its corrected value?
Answer: . The corrected value is about 4.53, which is higher than the measured value because batch 3 reads low.
Common mistakes and tradeoffs
It is tempting to think that batch effects are just noise, and that averaging over enough samples will remove them. In fact a batch effect is systematic: every sample in a batch shares the shift, so averaging does not cancel it. A batch that holds more of one group makes the group look different for reasons that have nothing to do with biology.
It is tempting to think that correction is always safe. In fact correction removes whatever differs between batches, and if the groups you are comparing are confounded with batch, the correction removes the real difference too. This is the confounding problem in another form. The fix is in the design, not the software: process groups in balanced batches, and randomise the order of processing.
It is tempting to think that stronger correction is always better. In fact aggressive integration can merge cell types that really differ, because two distinct types can look similar after the batch shift is removed. Check the result against known markers before naming clusters.
Use a simple offset or a regression term when the batches are known, the design is balanced, and there are few batches. Use a mixed model, which treats batch as a random effect and shrinks small or noisy batch estimates toward zero, when there are many batches or some batches are small. Use Empirical Bayes methods when many genes must be corrected at once and each batch estimate is noisy. Use an integration method, as in the single-cell tools that merge many batches at once, when the data are large and not a simple shift. None of these fixes an unbalanced design, so the design should come first.
History
Batch effects were noticed early in the age of microarrays, when labs in the late 1990s and early 2000s found that measurements shifted with the day and the reagent lot. Researchers at first treated the shifts as an annoyance to be avoided by careful handling.
By the late 2000s, large pooled datasets made the problem impossible to ignore. Leek and colleagues argued in 2010 that batch effects were widespread and could produce false findings in high-throughput studies, and that they needed to be modelled explicitly.
In 2007 Johnson, Li and Rabinovic published a method called ComBat, which estimates batch shifts with an Empirical Bayes approach that borrows strength across genes. It became a common tool for microarray and later sequencing data. Single-cell studies, which pool many batches of cells, pushed the field toward integration methods in the late 2010s.
Recap
- A batch effect is a systematic shift in measurements from processing, and it is not biology.
- A simple model writes each measurement as the overall level, plus a batch offset, plus noise, and the offsets are the differences between batch means and the overall mean.
- Correction subtracts the estimated offsets and leaves the within-batch spread unchanged.
- The correction is only valid when the biology is balanced across batches; if the groups are confounded with batch, the correction removes real signal.
- Read next: Differential Expression Analysis for finding real differences once batches are handled, and Harmony for merging many batches of single-cell data.