Tutorials › Multi-Omics Data Integration › Detecting Overfitting In Latent Factor Models

Latent Factor Models and Their Interpretation · Tutorial 254 of 597

Detecting Overfitting In Latent Factor Models

Learn how to distinguish useful latent structure from factors that fit noise, and how validation and regularization can guide a more reliable model.

Advanced 12 min read

What You'll Learn

  • Define training and held-out prediction error for a rank-constrained factor model.
  • Explain why training fit alone cannot determine a useful number of factors.
  • Recognize weak or unstable factors as potential signs of overfitting.
  • Use residual structure and validation design to diagnose model failure.
  • Compare reducing the factor rank with shrinking model loadings.

Why Overfitting Is a Concern

A latent factor model can summarize coordinated variation across omics measurements, but adding factors also gives the model more flexibility to fit idiosyncratic noise. A factor that improves the reconstruction of the observed data is not automatically a reproducible biological signal. Overfitting is present when a model captures features of the training data that do not generalize to new subjects or held-out measurements.

This tutorial focuses on diagnosing that gap. The earlier material on residual diagnostics, posterior predictive checks, and factor stability provides useful tools; here the emphasis is on combining them to judge whether a factor solution is too flexible. A diagnostic is evidence, not a definitive label: weak factors, unstable loadings, and poor validation performance should be interpreted together and in light of the data and intended use.

Definition: Let \(Y\) be an \(n \times p\) matrix of continuous, preprocessed measurements, with subjects in rows and features from one or more omics blocks in columns. A rank-\(K\) Gaussian factor model represents the data as \(Y=ZL^\mathsf{T}+E\), where \(Z\) is an \(n \times K\) matrix of subject scores, \(L\) is a \(p \times K\) loading matrix, and \(E\) contains residuals. For a fitted model, training error summarizes discrepancies on observations used for fitting; held-out error summarizes discrepancies on observations withheld from fitting and prediction.

In the simple Gaussian version, each residual has mean zero and variance \(\sigma^2\); residuals are independent conditional on the factors and loadings. The model also assumes that the chosen factor structure is a reasonable representation of the systematic dependence in the measurements. Omics applications may use block-specific residual variances or more specialized likelihoods, but the central overfitting logic is the same: in-sample fit measures accommodation of the data used to estimate the model, while validation assesses performance on data not used to fit it.

A fair held-out assessment requires a prediction task that can actually be performed. For example, one can hold out selected feature values for subjects, infer their scores from the features still observed, and predict the withheld values. Alternatively, in a new-subject assessment, the procedure for inferring a new subject's scores must be specified using available measurements. It is not an honest test to estimate a subject's scores using the very held-out values whose reconstruction is then scored. All preprocessing steps that learn from data, including centering and scaling, should be estimated using training data alone and applied to held-out data without refitting.

Training Fit, Held-Out Fit, and Rank

For a set \(\mathcal{A}\) of observed feature values, define mean squared reconstruction error as the average squared difference between the observed value and the model's prediction:

$$ \operatorname{MSE}(\mathcal{A})= \frac{1}{|\mathcal{A}|} \sum_{(i,j)\in\mathcal{A}} \left(Y_{ij}-\widehat{Y}_{ij}\right)^2 . $$

When features have been standardized using training data, this error is in squared standard-deviation units. Otherwise, a combined error across blocks can be dominated by features with larger measurement scales. Report block-specific errors or state how features were scaled and weighted. Compare validation errors on the same held-out observations across candidate models.

For an unconstrained least-squares rank-\(K\) approximation, the rank-\(K\) model class is contained in the rank-\((K+1)\) class: the additional factor can have zero loading. Therefore, the minimum training reconstruction error cannot increase as \(K\) increases. Held-out error is different: adding factors can initially improve prediction but can later increase error by fitting noise. The size of the training-to-validation gap is informative, but it is not a universal threshold; it depends on sample size, noise, model constraints, and the validation design.

Key takeaway: A lower training error is expected when a sufficiently flexible model is fitted. Evidence for overfitting comes from lack of generalization or unreliable structure, not from training error alone.

Worked Example: Choosing Rank With Held-Out Error

Suppose a hypothetical analysis of standardized multi-omics features compares ranks \(K=2,3,4\). A feature-masking validation design holds out values for prediction while leaving other measurements available to infer subject scores. Preprocessing is estimated on training observations only. The resulting mean squared errors are:

Rank \(K\)Training MSEHeld-out MSE
20.820.90
30.680.79
40.561.08

Training error falls at each rank, as expected for increasingly flexible models. Held-out error improves from \(0.90\) to \(0.79\) when moving from two to three factors, but then rises to \(1.08\) for four factors. The increase from rank three to rank four is \(1.08-0.79=0.29\) squared standardized units per held-out value. The rank-four training-to-held-out difference is \(1.08-0.56=0.52\), compared with \(0.79-0.68=0.11\) for rank three.

In this hypothetical comparison, rank three has the smallest held-out MSE, so it is preferred for this prediction task among these candidates. The rank-four model's smaller training error does not outweigh its worse validation performance. This conclusion is conditional on the chosen split and scoring target; repeated or grouped validation can help assess whether the pattern is reproducible.

Weak and Unstable Factors

Overfitting may also appear in the factors themselves. A factor is weak when it explains little variation relative to the overall variation or to other factors. A weak factor is not necessarily spurious: a small, reproducible signal can matter scientifically. Concern is greater when weak contribution is accompanied by unstable loadings or scores, inconsistent associations across resamples, or poor held-out prediction.

Factor signs and order can change across fitted solutions without changing the model's substantive content. Thus, stability comparisons should align factors for sign and permutation before interpreting their apparent variability. A factor that cannot be matched reliably after this alignment is less convincing as a reproducible direction of variation. Stability by itself does not establish biological validity: a systematic technical artifact can be highly stable.

Worked Example: A Weak Factor That Is Also Unstable

In a hypothetical standardized data set, the first three factors together account for 8.00 units of fitted variation, while a fourth accounts for 0.12 units. The total standardized variation considered is 10.0 units. Across 50 bootstrap resamples, after matching signs and order, the fourth factor has a clear counterpart in only 24 resamples; its loading-profile correlation with the original is at least 0.70 in 20 resamples.

The fourth factor's share of total variation is \(0.12/10.0=0.012\), or \(1.20\%\). Its small contribution alone is not proof of overfitting. However, a counterpart appears in only \(24/50=0.48\), or \(48.0\%\), of resamples, and a reasonably similar loading profile appears in \(20/50=0.40\), or \(40.0\%\). Together, low contribution and poor resampling stability raise concern that this factor reflects sample-specific variation.

The appropriate conclusion is not that the factor is certainly noise. The analysis should check whether its variation is concentrated in a block, linked to a known technical source, or supported by held-out prediction. If it contributes no useful generalization and remains unstable under reasonable analyses, a lower-rank model is more defensible.

Residual Patterns and Diagnostic Checks

Residuals are the differences between observed and fitted measurements. Residual patterns can indicate that the model is not capturing systematic structure, but this is not the same as overfitting: structured residuals often indicate underfitting, misspecification, or a preprocessing problem. Conversely, a very flexible model may have small training residuals while leaving structured patterns in held-out residuals. Interpret residual diagnostics alongside validation and factor stability.

Useful checks include examining residuals by subject, feature, omics block, and relevant covariates; comparing training and held-out residual distributions; and checking whether held-out residuals show correlations or other systematic patterns. A large training-to-held-out increase suggests weak generalization. A training fit that is already poor, with clear residual structure in both sets, instead suggests that the model may be too simple or otherwise misspecified. Review the validation split too: a split that separates sites, batches, families, or repeated observations may reveal a generalization problem hidden by random splitting, while an inappropriate split can make performance appear better than it would be in the intended application.

Worked Example: Reading a Residual Pattern in Context

A hypothetical two-block model predicts masked standardized feature values. For a particular held-out feature, the observed-minus-predicted residuals for four subjects in one batch are \(1.2, 1.0, 1.1, 0.9\); for four subjects in another batch they are \(-0.8, -1.0, -0.9, -1.1\). The mean residual in the first batch is \((1.2+1.0+1.1+0.9)/4=1.05\), and in the second it is \((-0.8-1.0-0.9-1.1)/4=-0.95\).

The residuals are not centered similarly across batches: their mean difference is \(1.05-(-0.95)=2.00\) standardized units. This pattern suggests batch-related structure not captured by the fitted model, or a mismatch between training and held-out data. It does not, by itself, show that the model overfit. The analyst should check whether batch effects were handled appropriately and whether the validation split reflects the intended prediction setting. Adding factors solely to reduce training residuals would not address the finding unless the resulting model also predicts held-out values better.

Addressing Overfitting: Rank Reduction and Shrinkage

Rank reduction restricts the model to fewer factors. It removes directions that may be fitting noise, at the cost of potentially omitting real but modest signals. Shrinkage penalizes model complexity while retaining a chosen rank. For example, a loading penalty adds \(\lambda\lVert L\rVert_F^2\) to the training loss, where \(\lambda\geq 0\) controls the strength of the penalty and \(\lVert L\rVert_F^2\) is the sum of squared loadings. Larger penalties generally pull loadings toward zero. The tuning parameter should be chosen using validation appropriate to the intended prediction task, not by minimizing training error.

These approaches are alternatives, not guarantees. Rank reduction is simple to interpret but removes whole directions; shrinkage can retain more directions while reducing their magnitude. Either can leave overfitting unresolved if the validation design leaks information or if other model assumptions fail. Comparing candidate ranks and penalties on the same splits, and reporting uncertainty across splits when feasible, gives a clearer basis for choice than relying on a single diagnostic.

Worked Example: How Loading Shrinkage Trades Fit for Simplicity

Consider a hypothetical single-feature regression on a fixed factor score vector \(z\), with \(\sum_i z_i^2=10\), and \(\sum_i z_iY_i=8\). The least-squares loading is \(\hat{l}=8/10=0.800\). Suppose residual variation orthogonal to \(z\) contributes a sum of squared errors of 4.00.

With a squared-loading penalty \(\lambda l^2\), the fitted loading minimizes \(\sum_i(Y_i-z_il)^2+\lambda l^2\). Differentiating with respect to \(l\) and setting the derivative to zero gives \(-2\sum_i z_iY_i+2l\sum_i z_i^2+2\lambda l=0\), hence \(l_\lambda=\sum_i z_iY_i/(\sum_i z_i^2+\lambda)\). For \(\lambda=2\), \(l_\lambda=8/(10+2)=0.667\), rounded to three significant figures.

The training sum of squared errors at this shrunken loading is \(4.00+10(0.800-0.667)^2\approx4.18\), compared with 4.00 at the unpenalized loading. The added training error is expected: the penalty trades some in-sample fit for a smaller loading. In a separate hypothetical five-fold validation, suppose mean squared errors are 0.94 for \(\lambda=0\) and 0.78 for \(\lambda=2\). The penalized fit then predicts better on those held-out values, supporting shrinkage for this task. That result should still be checked across suitable splits and should not be interpreted as proof that the factor is biological.

Common Pitfalls and Practical Interpretation

  • Choosing the model with the smallest training error. Training error tends to fall as flexibility increases. Compare held-out performance and factor reliability instead.
  • Calling every small factor overfit. A small factor may be reproducible or scientifically important. Assess its stability, context, and predictive contribution.
  • Treating residual structure as proof of overfitting. Residual patterns can signal underfitting or misspecification. Check where the pattern appears and whether it is present in held-out data.
  • Leaking held-out information. If held-out values influence preprocessing, factor fitting, or score estimation, validation error no longer measures performance on unseen values. Keep these steps within the training data or define a valid score-inference procedure.
  • Overinterpreting one split. A validation estimate can vary with the split. Use repeated or grouped splits when appropriate, and choose a split that reflects the intended use.

A practical diagnosis combines three questions: does added complexity improve held-out prediction; are the additional factors reasonably strong and stable; and do held-out residuals still show systematic structure? Rank reduction or shrinkage is most persuasive when it improves validation without discarding reproducible structure. No single threshold answers these questions for every multi-omics study.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. Why can training MSE decrease when rank increases even if held-out MSE gets worse?
  2. A candidate factor explains 2% of fitted variation but is consistently matched across resamples and improves held-out prediction. Is low contribution alone enough to reject it?
  3. What is wrong with estimating a held-out subject's factor scores using the same masked feature values that are then scored for prediction?
  4. Held-out residuals show a batch pattern, while training residuals do not. Name one interpretation and one check that should follow.

Solutions. (1) Higher rank enlarges the set of models that can be fitted, so training error cannot increase for the unconstrained least-squares rank approximation. It may fit noise that does not generalize, increasing held-out error. (2) No. Low contribution is a warning to investigate, not a rejection rule; reproducibility and validation benefit are relevant evidence in favor of retaining it. (3) The prediction uses information from the values being evaluated, so the validation is not independent of fitting and can underestimate prediction error. Infer scores using only measurements available under the stated prediction task. (4) The model may not capture batch structure, or the training and held-out distributions may differ. Check batch composition and preprocessing, and confirm that the split represents the intended use.

Clinical Biostats