Tutorials › High-Dimensional Genomic Data Analysis › Detecting Batch Effects With Principal Components

Normalization and Batch Effects · Tutorial 88 of 795

Detecting Batch Effects With Principal Components

Learn to interpret PCA score plots as quality-control evidence, while distinguishing visible batch structure from proof of its cause.

Intermediate 11 min read

What You'll Learn

  • Define the expression matrix and the sample scores shown in a principal-component plot.
  • Interpret principal components and their explained-variance percentages.
  • Compare the arrangement of samples when plots are colored by batch and by biological group.
  • Identify patterns that suggest batch-associated variation without treating a plot as a causal test.
  • Recognize preprocessing choices, outliers, and design limitations that can mislead PCA interpretation.
  • Use other exploratory displays to check, rather than overstate, a PCA pattern.

Why Examine Principal Components?

An expression study may measure thousands of genes in a relatively small number of samples. A table of all measurements is too large to inspect directly, but samples can often be represented in a few dimensions that summarize major patterns of expression variation. Principal-component analysis (PCA) provides such a summary. A plot of the first two principal components can reveal whether samples processed in different batches tend to occupy different regions of the plot, or whether samples instead arrange themselves by a biological group of interest.

The plot is an exploratory diagnostic, not a test that identifies the cause of a pattern. A separation by batch is evidence that expression profiles are associated with batch in the analyzed data. It does not establish that batch caused the separation, nor does overlap establish that batch has no effect. Interpretation depends on the preprocessing, the variance captured by the plotted components, and the study design.

What a PCA Score Plot Represents

Let \(X\) be an \(n \times p\) expression matrix, with one row for each of \(n\) samples and one column for each of \(p\) genes. The entries should be measurements on a comparable scale, such as normalized and transformed expression values. For the usual sample-level expression PCA, center each gene across samples by subtracting its sample mean. Write the resulting centered matrix as \(X_c\). Each row then describes a sample's deviations from the gene-wise means.

Definition: A principal component is a direction through the gene-expression feature space. The score of a sample on that component is its centered expression profile projected onto the direction. The first component is the direction with the greatest sample variance; each later component maximizes remaining variance subject to being orthogonal to the earlier directions. The loading of a gene is its coefficient in a component direction.

In matrix notation, the sample covariance matrix is \(S=X_c^T X_c/(n-1)\). If \(v_k\) is a unit-length eigenvector of \(S\) with eigenvalue \(\lambda_k\), the score vector for component \(k\) is \(t_k=X_c v_k\). The eigenvalue is the sample variance of those scores. The proportion of total variance explained by component \(k\) is \(\lambda_k/\sum_j \lambda_j\), where the sum is over the nonzero components. A PC1-versus-PC2 plot places each sample at coordinates \((t_{i1},t_{i2})\).

A component's sign is arbitrary: multiplying its loadings and all its scores by \(-1\) gives the same PCA. Thus left-versus-right on an axis has no inherent biological meaning. Distances and relative arrangements within the plotted axes are usually more useful, though they describe only the variation retained in those axes.

Why the First Components Capture Variation

The maximization defining PC1 can be justified directly. For a unit vector \(v\), the sample variance of the projected observations \(X_c v\) is \(v^T S v\). Thus PCA chooses the unit direction that maximizes this quadratic form.

$$ \text{maximize } v^T S v \quad \text{subject to } v^T v=1. $$

Using a Lagrange multiplier \(\lambda\), set the derivative of \(v^T S v-\lambda(v^T v-1)\) with respect to \(v\) equal to zero. Since \(S\) is symmetric, this gives \(2Sv-2\lambda v=0\), or \(Sv=\lambda v\). Therefore a maximizing direction is an eigenvector of \(S\), and its projected variance is the corresponding eigenvalue. Choosing the largest eigenvalue gives PC1. Requiring later directions to be orthogonal to earlier ones gives the subsequent principal components in descending order of variance.

This derivation also clarifies the scope of PCA: it finds directions of greatest overall variation, without using batch labels or biological group labels. Labels are added afterward to help interpret the sample score plot.

Worked Example: A Leading Component Aligned With Batch

Consider four hypothetical samples measured on two genes after preprocessing and gene-wise centering. Their centered expression profiles are A1 \((2,2)\), A2 \((1,1)\), B1 \((-1,-1)\), and B2 \((-2,-2)\). Suppose A1 and A2 are from batch A, while B1 and B2 are from batch B.

The two gene columns are identical, so the direction \(v_1=(1/\sqrt{2},1/\sqrt{2})\) captures all nonzero variation. For sample A1, its PC1 score is \((2,2)\cdot v_1=4/\sqrt{2}=2.828\). Applying the same calculation to all samples gives scores \(2.828,\ 1.414,\ -1.414,\ -2.828\).

The total centered sum of squares is \(2(2^2+1^2+(-1)^2+(-2)^2)=20\), so the total sample variance across the two genes is \(20/3=6.667\). The PC1 score sum of squares is \(2.828^2+1.414^2+(-1.414)^2+(-2.828)^2=20\), giving PC1 variance \(20/3=6.667\). PC1 therefore explains \(6.667/6.667=100\%\) of the nonzero variance. In a PC1 score plot, the batches separate completely. This is a strong batch-associated pattern in this small example; by itself, it does not establish why the batches differ.

Coloring the Plot to Evaluate Labels

A useful diagnostic is to examine the same sample coordinates with different label colors. First color samples by recorded technical variables such as processing batch, plate, or instrument run. Then examine the plot colored by the biological group relevant to the study. The question is not merely whether colored points form separate clouds: consider whether labels change systematically across the plotted directions, whether groups overlap, and whether any apparent pattern is driven by one sample.

Worked Example: Comparing Batch and Biological Labels

Suppose a hypothetical PCA gives PC1 scores \(-3,-2,2,3\) for samples A1, A2, B1, and B2, respectively. A1 and A2 are batch A; B1 and B2 are batch B. A1 and B1 are controls, while A2 and B2 are treated samples.

The batch means on PC1 are \((-3-2)/2=-2.5\) for batch A and \((2+3)/2=2.5\) for batch B. The biological-group means are \((-3+2)/2=-0.5\) for controls and \((-2+3)/2=0.5\) for treated samples. In this particular set of scores, the batch labels show a larger difference in PC1 position than the biological labels.

The appropriate reading is that the leading plotted direction is more visibly aligned with batch than with the treatment label in these hypothetical data. It is not a formal comparison of causal effects: there are only four samples, and visual separation is not a hypothesis test. The plot also cannot determine whether the biological effect is absent; biological variation may occur in later components or in directions not apparent from this display.

Practical Assumptions and Diagnostic Checks

PCA does not require normal expression values or a particular probability model to produce a score plot. Its interpretation does, however, rely on a meaningful input matrix. Samples must be comparable observational units, and columns must represent the same genes measured and processed consistently. Apply appropriate normalization and transformation before the PCA; raw sequencing counts, for example, can be dominated by library size. The earlier material on normalization and transformation addresses these preprocessing choices.

PCA is sensitive to scale. In covariance-based PCA, genes with larger variance can dominate the components. Standardizing every gene to unit variance changes the analysis by giving low-variance genes much more influence, which may also amplify noise. State which approach was used and choose it in light of the expression measurement and question. Check for missing values and extreme observations, since methods for handling missingness and a single unusual sample can alter the resulting directions.

For a practical reading, note the explained-variance percentages for the displayed axes, inspect sample labels and metadata, and look for outliers or gradients as well as clusters. A plot with a low combined percentage for PC1 and PC2 may omit substantial structure in later components. Conversely, a large percentage does not identify the source of the variation. If a technical label aligns with a component, inspect the underlying sample records and quality-control information before drawing conclusions.

1
Confirm the input.
Verify that the matrix contains appropriately normalized and transformed measurements, with samples as rows and genes as columns, and note any scaling choices.
2
Read the axes.
Record the explained-variance percentage for each displayed component; remember that the score coordinates summarize only those directions.
3
Compare labels.
Color the same coordinates by batch and by biological group, looking for consistent alignment, overlap, and individual samples that drive the pattern.
4
Check interpretation.
Use metadata and complementary displays to investigate a pattern. Report it as an observed association unless the design supports stronger claims.

Alternatives, Limitations, and Common Mistakes

PCA is a linear summary: it shows directions of high variance and can miss nonlinear structure or a group distinction that contributes little overall variation. A sample-score plot can also obscure separation when it occurs in PC3 or later. A distance-based multidimensional scaling plot is an alternative low-dimensional display based on pairwise sample dissimilarities; hierarchical clustering emphasizes groupings rather than continuous axes. A heatmap of selected genes can show gene-level patterns, but requires choices about which genes and how to scale them. These methods answer related but not identical exploratory questions. Agreement across displays can strengthen confidence that a pattern merits investigation, but none alone establishes its cause.

A particularly important limitation is that batch and biology can vary together in the study. If labels align, a PCA plot alone cannot disentangle their contributions. That requires attention to design and appropriate analysis, not a stronger visual claim. This tutorial uses PCA to detect and describe alignment; it does not provide a method for partitioning or removing the aligned variation.

  • Mistake: “PC1 separates batches, so batch caused the expression differences.” Correction: the scores are associated with batch labels; other sample characteristics or design features may also explain the pattern.
  • Mistake: “The batches overlap on PC1 and PC2, so there is no batch effect.” Correction: structure may occur on later components or be too subtle to see in this projection.
  • Mistake: “PC1 explains most variance, so it must be biological.” Correction: PCA is blind to labels; technical variation can be the largest source of variance.
  • Mistake: “A PCA plot is a significance test.” Correction: it is a descriptive projection, with no p-value or calibrated error rate attached to visual separation.
Key takeaway: A principal-component plot summarizes expression variation across samples. Coloring its scores by batch and biological group can reveal which recorded labels align with leading variation, but the pattern is diagnostic evidence—not a causal conclusion or a complete account of the data.

Worked Example: A Batch Pattern Outside the First Two Axes

In hypothetical data, PC1 explains 42% of total variance and PC2 explains 18%. Batch-colored points overlap substantially in the PC1-versus-PC2 plot. A separate inspection shows PC3 explains 15% of total variance and its scores are \( -2,-1,1,2 \) for two samples in batch A followed by two in batch B.

The displayed two axes explain \(42\%+18\%=60\%\) of total variance, leaving \(100\%-60\%=40\%\) outside that plot. PC3 explains 15 percentage points of total variance, and its batch score means are \((-2-1)/2=-1.5\) and \((1+2)/2=1.5\). Thus the overlap on the first two components does not rule out batch alignment: in this example, it appears along PC3. The conclusion remains descriptive, and the later component should be interpreted with the same care as the first two.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A PC1-versus-PC2 plot shows batch-colored clusters, and the axes explain 55% of total variance together. State one valid conclusion and one conclusion the plot does not justify.
  2. For centered expression data, \(\lambda_1=6\), \(\lambda_2=3\), and the sum of all nonzero eigenvalues is 12. What percentage of total variance do PC1 and PC1 plus PC2 explain?
  3. A treatment label is strongly separated on PC1, but the batch labels also separate in the same direction. What can the plot establish about their relative contributions?
  4. Why can overlap in the PC1-versus-PC2 plot not establish that no batch-associated structure exists?

Solutions. 1. The plotted scores are associated with batch, and the first two axes summarize 55% of the total variance. The plot does not prove batch caused the differences or describe the remaining 45%. 2. PC1 explains \(6/12=0.50\), or 50%. PC1 and PC2 together explain \((6+3)/12=0.75\), or 75%. 3. It establishes that both labels align with the displayed scores, but cannot separate their contributions or identify a cause from the plot alone. 4. The projection omits later components; relevant structure may occur outside the first two axes or be too subtle to distinguish visually.

Clinical Biostats