Skip to contents

Uses 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.

Usage

.fit_pca(X, n_components = 120L)

Arguments

X

Numeric matrix (rows = samples, cols = preprocessed bands)

n_components

Number of PCs to retain (default 120, per Safanelli)

Value

List with rotation, center, scale, n_components, scores, var_explained