
Build a negative-control panel from principal components
Source:R/negative_controls.R
build_w_pcs.RdComputes the top n_pcs principal components of a features x
samples matrix (typically residualized with
residualize_matrix()) and returns the sample scores as a W panel
(PCs x samples) in the orientation expected by iconic_data().
Uses irlba for fast truncated PCA when available, falling back to
stats::prcomp().
Arguments
- x
Numeric matrix, features x samples (e.g. residualized M-values or predicted expression).
- n_pcs
Integer: number of PCs to return. Default 20.
- scale_features
Logical: scale features to unit variance before PCA. Default
FALSE(appropriate for M-values); useTRUEfor predicted-expression panels where feature scales differ.- prefix
Character: row-name prefix for the PCs. Default
"PC".
Value
A list with:
- W
numeric matrix, PCs x samples, suitable as the
Wargument oficonic_data().- variance_explained
numeric vector: percent of total variance explained by each returned PC.