Tutorials › Multi-Omics Data Integration › PCA Diagnostics for Batch Effects Before and After Correction

Preprocessing, Scaling and Block Weighting · Tutorial 52 of 597

PCA Diagnostics for Batch Effects Before and After Correction

Use PCA to assess whether batch aligns with major axes of variation and whether that alignment changes after correction, without mistaking a diagnostic pattern for proof of successful adjustment.

Intermediate 13 min read

What You'll Learn

  • Construct and interpret PCA score plots for omics data before and after batch correction.
  • Calculate explained variance and cumulative explained variance from PCA eigenvalues.
  • Quantify how much variation in a principal-component score is associated with batch.
  • Compare pre- and post-correction patterns without assuming their principal-component axes are identical.
  • Recognize confounding, scaling choices, outliers, and other limits of PCA diagnostics.

Why Diagnose Batch Effects With PCA?

Technical batches can create systematic differences between samples. If those differences are large relative to other sources of variation, samples from the same batch may cluster in a principal-component (PC) score plot. Such a pattern can help identify batch as a prominent feature of the data, and comparing plots before and after correction can show whether the pattern changes. PCA is a diagnostic, however, not a test that proves a batch effect is present or that correction has succeeded.

A PCA diagnostic is useful only when the data and analysis are defined clearly. The rows should represent the same samples before and after correction, and the columns should represent the same features. For a meaningful comparison, use a consistent feature set and documented transformation, centering, scaling, and block-weighting choices. The correction may change the values, but changing other analysis choices at the same time makes it harder to tell what caused a changed plot.

Definition: Let \(Y\) be an \(n \times p\) matrix with one row per sample and one column per feature. PCA is applied to a centered (and, when chosen, scaled) version of \(Y\). A principal component is a direction through feature space that maximizes the variance of the projected samples, subject to being orthogonal to earlier directions. A score is a sample's coordinate along a principal component.

For example, a PC1-versus-PC2 score plot shows each sample's coordinates on the first two principal components. Colors can identify batch, while a second visual encoding, such as point shape, can identify a biological group. The plot is most informative when batch labels and relevant biological covariates are available and displayed together.

What PCA Variance Summaries Mean

Let \(Z\) be the centered data matrix, after any selected feature scaling, and let \(S=Z^\mathsf{T}Z/(n-1)\) be its sample covariance matrix. The eigenvalues of \(S\), written \(\lambda_1 \geq \lambda_2 \geq \cdots \geq 0\), are the variances along the corresponding principal components. The proportion of total variance explained by PC \(j\) is its eigenvalue divided by the sum of all eigenvalues.

$$ \text{Proportion explained by PC }j = \frac{\lambda_j}{\sum_{k=1}^{p}\lambda_k}, \qquad \text{cumulative proportion through PC }r = \frac{\sum_{j=1}^{r}\lambda_j}{\sum_{k=1}^{p}\lambda_k}. $$

The justification follows directly from the definition of a principal component. For a unit vector \(v\), the projected scores are \(t=Zv\), and their sample variance is \(t^\mathsf{T}t/(n-1)=v^\mathsf{T}Sv\). The first principal-component direction maximizes this quantity over unit vectors; subsequent directions maximize it subject to orthogonality to earlier directions. The eigenvalues are these successive variances, and their sum is the total variance because the trace of \(S\) is the sum of its eigenvalues.

A scree plot displays eigenvalues or explained-variance proportions by component. It helps show whether a small number of directions account for much of the observed variation. It does not identify the source of that variation: a high PC1 proportion might reflect batch, biology, an outlier, or a combination.

Worked Example: Reading a Scree Summary Before and After Correction

Suppose a hypothetical analysis uses the same three features and samples before and after batch correction, with the same centering and scaling rules. The pre-correction PCA has eigenvalues 9, 3, and 2; the post-correction PCA has eigenvalues 4.5, 3.5, and 2. These are illustrative values, not results from a real study.

Before correction, total variance is \(9+3+2=14\). PC1 explains \(9/14\approx0.6429\), or 64.29%; the first two PCs explain \((9+3)/14=12/14\approx0.8571\), or 85.71%.

After correction, total variance is \(4.5+3.5+2=10\). PC1 explains \(4.5/10=0.45\), or 45.00%; the first two PCs explain \((4.5+3.5)/10=0.80\), or 80.00%.

The leading component accounts for a smaller share of total variance after correction. This is a change in the variance summary, not by itself evidence that batch variation decreased: the shares do not say which source of variation each component represents. The score plot and batch-associated summaries are needed to interpret the pattern.

Assessing Batch Alignment in Score Plots

Start by coloring samples by batch and looking for separation, gradients, or clusters across the leading PCs. Then check whether those patterns also align with biological covariates, such as phenotype or collection time. Batch-aligned clustering is a warning that technical variation may be prominent in the displayed directions; overlap between batches is not proof that batch has no effect, because an effect may lie in later PCs or be obscured by other variation.

A descriptive summary for a single PC score is the fraction of its total sum of squares explained by batch. For scores \(t_i\), let \(\bar{t}\) be their mean, and let \(\bar{t}_g\) be the mean in batch \(g\). The between-batch sum of squares divided by total sum of squares gives the usual one-factor \(R^2\). It ranges from 0 to 1 when the total sum of squares is positive. This is a descriptive measure of score separation; it is not the proportion of all feature-level variation caused by batch.

$$ R^2_{\text{batch}} = \frac{\sum_g n_g(\bar{t}_g-\bar{t})^2} {\sum_i(t_i-\bar{t})^2}. $$

This summary is most interpretable when the batch labels are accurate and the samples provide relevant comparisons across batches. If biological groups are imbalanced across batches, report that imbalance and inspect the biological labels as well. A batch-associated score pattern cannot, on its own, distinguish technical effects from biology that is aligned with batch.

Worked Example: Calculating Batch-Associated Variation in PC1

Consider eight hypothetical samples, four in each of two batches. Their PC1 scores before correction are \(-3,-2,-2,-1\) in batch A and \(1,2,2,3\) in batch B. The overall mean score is 0, and the batch means are \(-2\) and 2.

The between-batch sum of squares is \(4(-2-0)^2+4(2-0)^2=32\). The total sum of squares is \(18+18=36\), because the squared scores in each batch sum to 18. Therefore, \(R^2_{\text{batch}}=32/36\approx0.8889\): 88.89% of the observed PC1 score variation in this example is associated with the two batch labels.

Suppose the scores after correction are \(-1.2,-0.2,-0.2,0.8\) in batch A and \(0.8,1.8,1.8,2.8\) in batch B. The group means are \(-0.2\) and 1.8, and the overall mean is 0.8. The between-batch sum of squares is \(4(-0.2-0.8)^2+4(1.8-0.8)^2=8\). The total sum of squares is 12: the squared deviations from 0.8 sum to 6 in each batch. Thus \(R^2_{\text{batch}}=8/12\approx0.6667\), or 66.67%.

The score variation associated with batch is lower in the post-correction scores, but remains substantial in this illustrative calculation. The values do not establish that correction was appropriate or that biological information was preserved. Also, when PCA is fitted separately before and after correction, the PC1 directions can differ; compare batch alignment in each analysis rather than treating the two PC1 axes as identical measurements.

Assumptions, Confounding, and Comparisons

PCA describes linear directions of variation in the matrix supplied to it. Its diagnostics depend on the input: centering, feature scaling, filtering, and block weights affect which directions dominate. The usual covariance-based calculation also requires numerical values for the analyzed entries; missing data need an explicitly chosen handling strategy before applying it. Extreme samples can strongly influence the leading components, so inspect the score plot for isolated points and check whether conclusions depend on them.

The main interpretive requirement is adequate overlap between batches and biological groups. If every case is in one batch and every control in another, batch and phenotype are confounded. No PCA plot can identify which factor explains their shared pattern. The same caution applies if only a subset of groups appears in some batches. When groups are represented across batches, color and shape can help assess whether a batch pattern remains after considering the biological labels, but PCA still does not isolate causal sources of variation.

Worked Example: When Batch and Phenotype Cannot Be Separated

In a hypothetical six-sample dataset, three controls are measured in batch A and three cases in batch B. The PC1 scores are \(-2,-1,0\) for the controls and \(1,2,3\) for the cases. Here batch membership and phenotype are identical labels for the observed samples.

The group means are \(-1\) and 2, and the overall mean is 0.5. The between-group sum of squares, equivalently the batch sum of squares or phenotype sum of squares, is \(3(-1-0.5)^2+3(2-0.5)^2=13.5\). The total sum of squares is \(17.5\), so \(R^2=13.5/17.5\approx0.7714\), or 77.14%.

This calculation shows strong separation along PC1, but it cannot say whether batch or phenotype accounts for it: both groupings make exactly the same partition of these samples. Additional samples that break the confounding, such as cases and controls represented in both batches, are needed to distinguish the patterns.

PCA diagnostics complement, rather than replace, other checks. A score plot summarizes sample-level structure in a few directions; it can miss batch patterns outside the plotted PCs. A batch association summary for a PC adds a numerical description but remains limited to that score and does not adjust away confounding. Feature-level comparisons can reveal changes not apparent in sample-level projections, while multivariable adjustment methods use a specified model and assumptions. Neither a plot nor a single summary should be treated as a substitute for understanding the design and the correction model.

Comparing Before and After Correction Carefully

Use the same samples and selected features where possible, and keep the transformation, scaling, and weighting choices consistent. Fit PCA to each matrix and examine the score plots, scree summaries, and batch association in several leading PCs, not only PC1. Because PCA is refitted on each matrix, its axes can rotate, change sign, or exchange order. Thus, a score shift on a separately fitted PC1 is not automatically a directly comparable change in a fixed direction.

For a clearer comparison, describe what is stable and what changes: for example, whether batch-colored clusters are less distinct in the displayed projections, whether batch-associated \(R^2\) values change, and whether biological labels still show structure. If correction is assessed using a different set of features or newly chosen scaling in each analysis, say so; those choices may contribute to the apparent difference.

1
Define comparable inputs.
Confirm sample identities, feature set, transformations, scaling, and block weights for the pre- and post-correction matrices.
2
Fit and summarize PCA.
Record eigenvalues or explained-variance proportions and inspect enough leading PCs to represent the major variation.
3
Display technical and biological labels.
Color by batch and use another visual cue for relevant biological groups; look for confounding and influential outliers.
4
Compare cautiously.
Describe changes in batch alignment and score summaries without treating separately fitted PC axes as identical or claiming that a diagnostic proves success.

Common Mistakes and Limitations

  • Calling less visible separation proof of successful correction. A batch pattern may remain in later PCs, while biology may also have been reduced. Inspect multiple components and biological labels; PCA alone cannot establish preservation of relevant biological effects.
  • Comparing PC1 coordinates as if they were on a fixed axis. Separate PCA fits can produce different directions and signs. Compare the patterns and summaries in context, not the raw coordinates as though the axes were identical.
  • Ignoring scaling and block weights. A block with greater numerical variance or influence can dominate the leading components. Interpret the PCA relative to the actual preprocessing choices.
  • Attributing a confounded pattern to batch. If batch and phenotype coincide, the observed separation cannot distinguish them. The study design, not a more detailed plot, must provide the missing overlap.
  • Relying only on PC1 versus PC2. Important structure may occur in later components or may not be captured by linear PCA. Examine variance summaries and appropriate additional diagnostics.

The practical value of these diagnostics is that they expose prominent structure and make assumptions visible. Their limitation is equally important: PCA is a projection of the observed data, not a causal attribution procedure or a guarantee that the correction preserves the signal of interest.

Check Your Understanding

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

  1. A PCA has eigenvalues 6, 3, and 1. What proportion of total variance is explained by PC1, and what cumulative proportion is explained by the first two PCs?
  2. Why is a lower batch-associated \(R^2\) after correction not, by itself, proof that the correction was successful?
  3. All cases are measured in batch B and all controls in batch A. Can a PC score plot identify whether a separation is due to batch or phenotype? Explain.
  4. Name two analysis choices that should be kept consistent when comparing PCA before and after correction.

Solutions. (1) Total variance is \(6+3+1=10\); PC1 explains \(6/10=0.60\), or 60%, and the first two explain \(9/10=0.90\), or 90%. (2) The summary concerns a projected score and does not show whether biological variation was also reduced or whether relevant patterns remain elsewhere. (3) No. The labels are completely confounded, so both groupings give the same separation; samples represented in both batches are needed to distinguish them. (4) Examples include the samples, feature set, transformation, centering, scaling, and block weights.

Clinical Biostats