
Fit a PCA on a spectral matrix and keep the first n_components scores
Source:R/cubist_baseline.R
dot-fit_pca.RdUses irlba::prcomp_irlba() when available (randomised truncated SVD —
much less memory and faster for rank-120 on large matrices like 130k × 1076)
and falls back to stats::prcomp() otherwise. Returns the fitted
object plus centred/scaled metadata for projecting new spectra and computing
Q-statistic residuals.