Tutorials › High-Dimensional Genomic Data Analysis › Residual Diagnostics for Principal Component Models

Dimension Reduction and Clustering · Tutorial 603 of 795

Residual Diagnostics for Principal Component Models

You will learn to calculate and interpret sample and variable reconstruction residuals, inspect their structure, and recognize when residual diagnostics point to preprocessing or component-model problems.

Intermediate 10 min read

What You'll Learn

  • Define the residual matrix for a rank-k PCA reconstruction.
  • Calculate sample-level residual sums of squares and compare them with the overall reconstruction error.
  • Calculate variable-level residual sums of squares and interpret them in light of the data scaling.
  • Use residual patterns to distinguish isolated poorly represented samples from coherent omitted structure.
  • Recognize why residual size alone is not a formal outlier test or a definitive rule for choosing k.

Why Examine What PCA Leaves Behind?

A rank-k principal component model summarizes each profile using only its projections onto k directions. The reconstruction is useful when those directions retain the structure relevant to the analysis. But a small reconstruction error overall does not guarantee that every sample or every variable is represented well. A few samples may have unusually large errors, or a group of variables may retain a coordinated pattern that the chosen components do not capture.

Residual diagnostics examine these differences between observed and reconstructed values. They complement explained variance: explained variance summarizes the total information retained, while residual diagnostics show where the remaining error lies. They are descriptive tools, not, by themselves, formal tests for outliers or a proof that the component model is wrong.

Residuals From a Rank-k Reconstruction

Let \(X\) be an \(n \times p\) data matrix, with samples in rows and variables in columns. The matrix should be prepared using the centering and, when appropriate, scaling chosen for the PCA analysis. Write its singular value decomposition as \(X=UDV^\mathsf{T}\), with singular values in descending order. The rank-k reconstruction is \(\hat{X}_k=U_kD_kV_k^\mathsf{T}\). The residual matrix is \(E=X-\hat{X}_k\), with entry \(e_{ij}=x_{ij}-\hat{x}_{ij}\).

Definition: The sample residual sum of squares for sample \(i\) is \(Q_i=\sum_{j=1}^{p}e_{ij}^2\). The variable residual sum of squares for variable \(j\) is \(R_j=\sum_{i=1}^{n}e_{ij}^2\). \(Q_i\) measures how poorly the model reconstructs sample \(i\) across variables; \(R_j\) measures how much of variable \(j\)'s total variation remains unreconstructed.

Both quantities depend on the scale used in \(X\). If variables have been standardized, residuals are in standard-deviation units and squared residuals are in squared standard-deviation units. If variables remain in their original units, a variable measured on a numerically large scale can dominate sums of squares. In that case, raw \(R_j\) values across variables are not directly comparable without accounting for their scales.

A useful summary of a sample's residual size is its residual root-mean-square, \(\sqrt{Q_i/p}\), in the units of the analyzed data. A variable's residual root-mean-square, \(\sqrt{R_j/n}\), is similarly interpretable in that variable's analysis scale. These summaries aid comparisons, but there is no universal cutoff that makes a sample or variable an outlier.

Worked Example: Finding a Poorly Reconstructed Sample

Consider a hypothetical centered, two-variable data matrix with four sample score values \(t=(2,0,-2,0)\) on the leading loading \(v=(1,1)^\mathsf{T}/\sqrt{2}\). Suppose the residual rows are \(0\), \((1,-1)/\sqrt{2}\), \(0\), and \((-1,1)/\sqrt{2}\). These residuals are perpendicular to \(v\); their score pattern is also perpendicular to \(t\). The score direction has squared length \(8\), greater than the residual direction's squared length \(2\), so this is a rank-one PCA reconstruction.

The fitted values are \(t_i v\). Subtracting them leaves the stated residual rows, so the sample residual sums of squares are \(Q_1=0\), \(Q_2=(1/\sqrt{2})^2+(-1/\sqrt{2})^2=1\), \(Q_3=0\), and \(Q_4=1\).

The total squared residual is \(0+1+0+1=2\). The overall squared data length is \(8+2=10\), so this reconstruction leaves \(2/10=0.20\), or 20%, of the total sum of squares unreconstructed. Samples 2 and 4 each have residual RMS \(\sqrt{1/2}=0.7071\) analysis units per variable, whereas samples 1 and 3 have zero residual. In context, samples 2 and 4 are less well represented by this rank-one reconstruction; the calculation alone does not establish why.

What the Residual Sums of Squares Show

The row and column summaries partition the same total error in two different ways: \(\sum_i Q_i=\sum_j R_j=\lVert E\rVert_F^2\), where \(\lVert E\rVert_F^2\) is the sum of the squared entries of \(E\). A large \(Q_i\) identifies a sample contributing substantially to the reconstruction error. A large \(R_j\) identifies a variable contributing substantially to that error. Neither summary describes the direction or pattern of the errors, so the residual matrix itself also matters.

Result: For the rank-k truncated singular value decomposition, \(E=\sum_{\ell>k}d_\ell u_\ell v_\ell^\mathsf{T}\), where \(d_\ell\), \(u_\ell\), and \(v_\ell\) are the omitted singular values and corresponding singular vectors. Therefore \(\lVert E\rVert_F^2=\sum_{\ell>k}d_\ell^2\). This is the total squared reconstruction error, not a statement about how that error is distributed among samples or variables.

The equality follows because distinct singular-vector outer products are orthogonal under the matrix inner product \(\langle A,B\rangle=\operatorname{tr}(A^\mathsf{T}B)\). Each \(u_\ell\) and \(v_\ell\) has length one, so \(\lVert u_\ell v_\ell^\mathsf{T}\rVert_F^2=1\). Consequently, the squared norm of the sum of omitted terms is the sum of their squared coefficients, \(\sum_{\ell>k}d_\ell^2\). Summing the entries of \(E\) by rows gives \(\sum_i Q_i\), and summing by columns gives \(\sum_j R_j\); both sums equal \(\lVert E\rVert_F^2\).

This result connects residual diagnostics to the rank-k reconstruction: adding components cannot increase the training-data residual sum of squares, but it can make the residuals appear smaller simply by fitting more directions. A lower total error alone does not show that the added components represent stable or scientifically meaningful structure.

Worked Example: Locating Variables That Contribute Residual Error

Suppose a hypothetical rank-one PCA fit to four samples and three variables has the following residual matrix, in the units used for analysis:

$$ E= \begin{pmatrix} 1 & -1 & 0\\ -1 & 1 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0 \end{pmatrix}. $$

The variable residual sums of squares are \(R_1=1^2+(-1)^2=2\), \(R_2=(-1)^2+1^2=2\), and \(R_3=0\). The total residual sum of squares is \(2+2+0=4\). Thus variables 1 and 2 each contribute half of the remaining squared error, and variable 3 contributes none. Their residual RMS values are \(\sqrt{2/4}=0.7071\), \(0.7071\), and \(0\) analysis units, respectively.

This pattern points to variables 1 and 2 as locations of the reconstruction error, but it does not automatically mean they are noisy or should be removed. If the variables were not placed on comparable scales, their raw contributions would need careful interpretation. Even with standardized variables, a substantial residual contribution may reflect meaningful structure omitted by the rank-one model.

Residual Structure: More Than Large Errors

An isolated large residual and a repeated residual pattern call for different interpretations. A single sample with a large \(Q_i\) may deserve review for data quality, unusual biology, or a profile unlike the dominant patterns. In contrast, residuals that change together across multiple samples can indicate a coherent pattern not represented by the retained components. Residuals that repeatedly concentrate in the same variables can point to a variable-specific issue, a preprocessing concern, or a systematic feature of the data.

Inspecting a residual heat map or selected residual-versus-sample displays can reveal patterns that row and column totals hide. Residual correlations can also summarize whether pairs of variables tend to have residuals that vary together. These are exploratory views: the residuals were computed after fitting PCA to these data, so they are not independent observations generated from a specified error distribution.

Worked Example: Detecting a Coordinated Residual Pattern

Consider a hypothetical rank-one fit with three variables. Let the leading loading be \(v=(1,1,1)^\mathsf{T}/\sqrt{3}\), and suppose the residual rows for four samples are \((1,-1,0)/\sqrt{2}\), \((-1,1,0)/\sqrt{2}\), \((1,-1,0)/\sqrt{2}\), and \((-1,1,0)/\sqrt{2}\). Each residual row is perpendicular to \(v\). Suppose the fitted scores are \(t=(2,2,-2,-2)\); their inner product with the residual coefficient pattern \((\sqrt{2},-\sqrt{2},\sqrt{2},-\sqrt{2})\) is \(2\sqrt{2}-2\sqrt{2}-2\sqrt{2}+2\sqrt{2}=0\). The residuals are therefore orthogonal to the fitted score direction as well.

Every sample has \(Q_i=(1/\sqrt{2})^2+(-1/\sqrt{2})^2=1\). No sample stands out by residual size. But the first residual column is the negative of the second, and the third is zero. The first two residual columns each have sum of squares 2, and their cross-product is \(-2\). Their sample residual variances are \(2/3\), and their sample residual covariance is \(-2/3\), so their residual correlation is \((-2/3)/\sqrt{(2/3)(2/3)}=-1\).

The coordinated, opposite-signed residuals are not explained by one unusually poorly reconstructed sample. They suggest a pattern shared across samples that the rank-one model leaves behind. This is evidence to investigate the adequacy of that reconstruction, not proof that a particular additional component is scientifically valid.

Assumptions, Diagnostics, and Alternatives

The residual calculations are algebraic and do not require normally distributed data. Their interpretation does require care. Samples and variables must have been arranged consistently with the PCA fit; the same centering and scaling must be used for reconstruction and residual calculation; and missing or invalid entries must not be treated as ordinary observed values. If samples are related, such as repeated measurements from the same subject, their residuals should not be interpreted as independent evidence.

A practical diagnostic sequence is:

1
Check the analysis scale.
Confirm which variables were centered or scaled and interpret residual magnitudes in those units.
2
Summarize residual size.
Compare \(Q_i\) across samples and \(R_j\) across variables, then examine their contributions to the total residual sum of squares.
3
Inspect patterns.
Look for concentrated errors, repeated sample-variable patterns, or coordinated residuals across variables.
4
Investigate before acting.
Check data processing and context, then assess whether a different component count or analysis is justified. Do not remove a sample or variable solely because its residual is large.

Residual size is not the same as position within the retained PCA space. A sample can have an extreme score on a retained component yet be reconstructed well, while a sample near the center of the score plot can have a large residual. Score displays and residual diagnostics answer different questions: the first show variation represented by the model, the second show variation it leaves out.

A scree plot and explained-variance summaries describe how total variation changes as components are retained; residual diagnostics describe the distribution and structure of what remains. Neither substitutes for the other. There is no general residual cutoff or residual-based p-value without a justified reference model or calibration procedure. Moreover, fitting PCA and inspecting residuals on the same data can make reconstruction errors look more favorable than they would be on new samples. The diagnostics are best treated as evidence for review, not automatic selection or deletion rules.

Common Mistakes and Limitations

  • Calling the largest \(Q_i\) a proven outlier. It only identifies a sample poorly reconstructed relative to this fit. Review its measurements and context before deciding what it means.
  • Comparing raw \(R_j\) values across incompatible scales. A large numerical scale can produce a large residual sum of squares. Interpret the values in light of the preprocessing.
  • Concluding that small total error proves adequacy. A small total can conceal a poorly represented sample or a structured residual pattern.
  • Increasing k just to eliminate residuals. More components reduce training reconstruction error, but that alone does not establish that the extra structure is stable or useful.
  • Treating residual patterns as formal tests. Without an explicit probability model and appropriate calibration, residual summaries are diagnostic quantities, not p-values or controlled error rates.

PCA residual diagnostics are limited by the chosen preprocessing, sample, and component count. They cannot by themselves distinguish noise from meaningful unmodeled structure, identify the cause of an unusual profile, or guarantee performance on future data. Their value is in making the weaknesses of a particular reconstruction visible and directing careful follow-up.

Check Your Understanding

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

  1. What does a large \(Q_i\) indicate, and what does it not establish?
  2. If \(\sum_i Q_i=12\), what must \(\sum_j R_j\) equal?
  3. Why can a variable with the largest raw \(R_j\) be misleading when variables are measured on different scales?
  4. All samples have similar \(Q_i\), but two variables have strongly coordinated residuals across samples. What might this suggest?
  5. Why is a smaller training residual sum of squares after increasing k not sufficient evidence that the larger-k model is preferable?

Solutions: (1) Sample \(i\) is poorly reconstructed across the analyzed variables; this alone does not prove it is an outlier or explain the cause. (2) It must also equal 12, because both sums equal \(\lVert E\rVert_F^2\). (3) A variable's measurement scale can inflate its squared residual contribution, so raw sums may not be comparable. (4) It may indicate coherent structure left out by the retained components, even though no one sample has an unusually large residual. (5) Adding components cannot increase training reconstruction error, but the reduction alone does not show that the added pattern is stable or meaningful.

Clinical Biostats