Tutorials › Multi-Omics Data Integration › Detecting Batch Structure With PCA

Batch Effects and Confounding Across Cohorts · Tutorial 102 of 597

Detecting Batch Structure With PCA

Use PCA plots to screen for structure associated with technical and biological variables while distinguishing visual patterns from causal conclusions.

Advanced 10 min read

What You'll Learn

  • Define the PCA scores and explained-variance proportions shown in a score plot.
  • Understand how centering, scaling, and feature selection affect the visible structure.
  • Compare plot patterns after coloring samples by cohort, platform, and biological covariates.
  • Calculate simple score summaries to describe group separation.
  • Recognize confounding, projection loss, and other reasons visual separation can mislead.
  • Distinguish exploratory PCA diagnostics from variance decomposition and formal association analysis.

Why Examine Batch Structure With PCA?

A multi-omics matrix may contain thousands of measured features and many samples, so inspecting feature-by-feature plots is rarely an effective first screen for unexpected structure. A principal-component analysis (PCA) compresses the feature measurements into a few directions that capture large amounts of variation. Plotting samples on those directions can make broad patterns visible: samples may cluster by cohort, separate by platform, or vary along a biological gradient.

A PCA plot is a diagnostic view, not a test of whether batch caused the observed pattern. The same separation might reflect biological differences, technical differences, a mixture of both, or other features of the data. The essential practice is to examine the same scores while coloring samples by several recorded variables, then interpret the patterns alongside the study design.

Definition: Let \(x_{ij}\) be the measured value of feature \(j\) in sample \(i\), for \(i=1,\ldots,n\) and \(j=1,\ldots,p\). After centering and, if appropriate, scaling the features, PCA represents each sample by scores on orthogonal directions of variation. A score plot displays samples using two selected principal-component scores, commonly PC1 and PC2. The directions are calculated from the feature matrix, not from sample labels such as cohort or platform.

What the Axes Represent

PCA usually begins by centering each feature: subtract its sample mean from each observed value. Features may also be scaled to have unit sample standard deviation. Centering makes the analysis describe variation around feature means; scaling changes how much influence each feature has. Without scaling, features with large measurement scales or variances can dominate. With scaling, a noisy low-variance feature can receive as much initial weight as a stable high-variance feature. Neither choice is universally correct, so the transformation should reflect the measurement scale and the scientific aim.

For centered data, let \(S\) be the sample covariance matrix across the \(p\) features. The first principal-component direction is a unit vector \(v_1\) that maximizes the variance of the projected samples. Its sample scores are the centered measurements multiplied by \(v_1\). Subsequent directions maximize remaining variance subject to being orthogonal to earlier directions. The eigenvalues of \(S\) give the variances along these directions.

$$ v_1=\arg\max_{\|v\|=1} v^\top S v, \qquad S v_k=\lambda_k v_k, \qquad \text{proportion explained by PC}k= \frac{\lambda_k}{\sum_{\ell=1}^{p}\lambda_\ell}. $$

The eigenvalue equation follows by maximizing \(v^\top S v\) subject to \(v^\top v=1\). The Lagrangian is \(v^\top S v-\lambda(v^\top v-1)\). Its derivative with respect to \(v\) is \(2Sv-2\lambda v\), so a stationary direction satisfies \(Sv=\lambda v\). Since a covariance matrix is symmetric, its eigenvectors can be chosen orthogonal; ordering the eigenvalues from largest to smallest gives the directions in order of explained variance.

This construction is descriptive and does not require the feature values to be normally distributed. It does require the analyzed values and transformations to be meaningful and comparable. Missing values, extreme outliers, inconsistent feature definitions, or poorly chosen scaling can distort the covariance structure and therefore the plot. In high-dimensional omics data, preprocessing and feature selection can materially change what appears as the leading pattern.

Worked Example: Reading the Explained-Variance Labels

Suppose a hypothetical PCA of an omics matrix has eigenvalues \(\lambda_1=4\), \(\lambda_2=1\), and the remaining eigenvalues sum to \(5\). The total variance is \(4+1+5=10\).

The proportion explained by PC1 is \(4/10=0.40\), or 40%. For PC2 it is \(1/10=0.10\), or 10%. A PC1-versus-PC2 plot therefore displays \(40\%+10\%=50\%\) of the total variance. The plot can show a compelling pattern while still omitting half of the total variation. Conversely, an uncolored plot with no visible clusters does not establish that every technical effect is negligible; an effect may lie in later components or affect only a subset of features.

Color the Same Scores by Different Variables

The PCA coordinates are fixed once the feature matrix and analysis choices are fixed. Coloring points by cohort, platform, processing date, disease status, or another biological covariate does not recalculate the components. It asks whether a recorded label aligns with a pattern already present in the scores. A useful diagnostic therefore reuses the same plot coordinates and changes the coloring, rather than interpreting separate PCA fits as if their axes were directly comparable.

Inspect both broad separation and within-group spread. A color pattern may be a gradient rather than distinct clusters; group centers may differ while their distributions overlap; or an apparent cluster may be driven by one unusual sample. Include sample labels when feasible, and check whether the pattern persists under reasonable preprocessing choices. A plot of the first two components is a projection: differences in other directions are not visible there.

Worked Example: Comparing Cohort and Platform Patterns

In a hypothetical analysis, eight samples have the following PC1 scores. The scores are held fixed while the labels are changed from cohort to platform.

SampleCohortPlatformPC1 score
1C1P1-3
2C1P1-2
3C1P2-2
4C1P2-1
5C2P11
6C2P12
7C2P22
8C2P23

For cohort C1, the mean PC1 score is \((-3-2-2-1)/4=-2\); for C2 it is \((1+2+2+3)/4=2\). For platform P1, it is \((-3-2+1+2)/4=-0.5\); for P2, it is \((-2-1+2+3)/4=0.5\). In this hypothetical example, the scores show a stronger descriptive separation by cohort than by platform. Both platforms occur in both cohorts, so the cohort pattern is not merely a display of one platform appearing only in one cohort.

These averages summarize the plotted scores; they do not show that cohort caused the pattern, nor do they prove that platform has no effect. The feature loadings, other components, and study design remain relevant. The earlier material on variance decomposition by cohort and platform provides a different way to quantify contributions that a plot alone cannot resolve.

Biological Covariates and Causal Ambiguity

Coloring by biological covariates is important because an apparent batch pattern may track genuine biology. For example, if disease status, age, or treatment group differs across cohorts, a PC aligned with cohort could also reflect those biological differences. Conversely, a biological gradient may align with platform if samples at different stages of a study were measured using different technologies. Plotting only technical labels can hide this ambiguity; plotting only biology can hide it as well.

Worked Example: A Score Gradient Shared by Age and Batch

Consider four hypothetical samples with ages of 20, 30, 40, and 50 years, PC1 scores of \(-2,-1,1,2\), and processing batches A, A, B, and B, respectively. The mean age is \(35\) years, and the mean score is \(0\). The centered age values are \(-15,-5,5,15\); the centered scores are \(-2,-1,1,2\).

The sample correlation between age and PC1 score is \(r=\sum_i (a_i-\bar{a})(s_i-\bar{s})/\sqrt{\sum_i(a_i-\bar{a})^2\sum_i(s_i-\bar{s})^2}\). Substitution gives a numerator of \(30+5+5+30=70\), an age sum of squares of \(225+25+25+225=500\), and a score sum of squares of \(4+1+1+4=10\). Thus \(r=70/\sqrt{500\times10}=70/\sqrt{5000}\approx0.990\).

The scores are strongly aligned with age in this small hypothetical sample, and the batch labels also change across the same ordering. The plot cannot determine whether the pattern reflects age, batch, both, or another variable associated with them. In particular, the correlation is descriptive, not evidence that age or batch caused the feature variation. Additional samples with age and batch represented in overlapping combinations would help distinguish these explanations.

A Practical Diagnostic Sequence

1
Choose and document the input.
Record the features, transformations, centering, scaling, and any filtering used. Confirm that samples and feature definitions are aligned across cohorts and platforms.
2
Inspect the leading components.
Report the explained-variance proportions and examine PC1 against PC2. Remember that these axes show only a projection of the total feature variation.
3
Recolor by technical and biological labels.
Compare cohort, platform, processing variables, and scientifically relevant covariates on the same coordinates. Look for alignment, overlap, gradients, and isolated samples.
4
Check the design before interpreting.
Ask whether the labels overlap across groups or are entangled. If biological and technical labels move together, the plot cannot assign the pattern to one cause.
5
Follow up with an appropriate analysis.
Use design-aware summaries or models to assess the pattern quantitatively, and examine whether conclusions depend on preprocessing or influential samples.

Alternatives, Failure Modes, and Limits

PCA is useful because its axes have a clear variance-maximizing definition and the same sample coordinates can be inspected against many labels. It is not a substitute for the earlier material on batch-associated models or variance decomposition: those approaches can quantify effects under an explicit design, while a PCA plot is an exploratory summary. A formal association analysis can address uncertainty and covariate adjustment, but it still depends on an adequate design and appropriate assumptions. A supervised method that uses group labels to construct separation answers a different question and should not be presented as independent evidence that the groups naturally separate.

  • Separation is not causation. A label aligned with a component may be associated with the pattern, but the plot cannot establish the mechanism.
  • Confounding limits attribution. If each cohort was measured on only one platform, the observed alignment cannot by itself distinguish cohort from platform.
  • Two components omit information. A batch pattern may occur on later components or in a direction that is not prominent in the displayed projection.
  • Scaling and outliers can dominate. A small number of extreme observations or a different scaling rule can change the leading components. Check the raw measurements and compare defensible preprocessing choices.
  • Visual inspection is subjective. Apparent clusters depend on plotting choices and may not correspond to a reproducible difference. Treat them as candidates for follow-up, not as a decision rule.

A common mistake is to see two platform-colored clusters and conclude, “platform caused the separation, so platform correction will remove it.” That reasoning skips both confounding and model assumptions. The correction is to describe the observation narrowly (“PC1 scores differ by recorded platform in this plot”), inspect biological labels and the study design, and then use an analysis capable of separating effects only when the design supports that distinction.

Key takeaway: PCA score plots are exploratory maps of major variation. Coloring the same scores by cohort, platform, and biological covariates can reveal candidate structure, but visual alignment alone does not identify its cause or quantify a batch effect.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. If PC1 explains 35% of the variance and PC2 explains 15%, what proportion is displayed in a PC1-versus-PC2 plot? What does the remaining proportion imply?
  2. Why should cohort and biological covariates also be examined when a score plot appears separated by platform?
  3. Suppose two cohorts occupy visibly different regions of a PCA plot, but each cohort was processed on a different platform. What can and cannot be concluded from the plot?
  4. Name two ways preprocessing or data quality can alter a PCA plot, and state one diagnostic response to each.

Solutions. (1) The plot displays \(35\%+15\%=50\%\) of total variance; the other 50% lies outside the two displayed directions, so the plot is not a complete representation. (2) Biological variables may align with platform and contribute to the same separation, so platform coloring alone cannot identify the source. (3) The plot shows that the measured feature patterns differ in the displayed projection and align with the recorded cohort/platform labels. It cannot distinguish cohort from platform as the cause when those labels coincide. (4) Scaling can change feature influence, so document and compare scientifically defensible scaling choices; an extreme sample can dominate a component, so inspect sample-level measurements and assess whether the pattern persists without undue influence from that sample.

Clinical Biostats