Computes principal components of the (optionally centered/scaled) genotype matrix, without any clustering. For wide data (more SNPs than individuals) the PCA is obtained from the n x n Gram matrix, so the large rotation matrix is never formed; when a fixed number of PCs is requested and RSpectra is installed, only the top PCs are computed with a matrix-free solver. This is the same PCA engine used by runAnticlusteringPCA, so the scores are directly comparable.

runPCA(object, n_pcs = NULL, center = TRUE, scale = TRUE)

Arguments

object

An object of class SNPDataLong.

n_pcs

Number of principal components to return. NULL (default) returns all PCs; a value >= 1 returns that many and enables the fast RSpectra path; a value < 1 is the proportion of variance to reach (e.g. 0.98).

center

Logical or numeric. Passed to scale. If TRUE, center columns; if numeric, a vector of column means. Default: TRUE.

scale

Logical or numeric. Passed to scale. If TRUE, scale to unit variance; if numeric, a vector of column sds. Default: TRUE.

Value

A list with components:

pca

A prcomp-like object: sdev, x (scores) and totvar (total column variance). rotation is NULL for the wide-data paths.

pcs

Numeric matrix with the selected top principal components.

Examples

if (FALSE) { # exists("nelore_imputed")
pr <- runPCA(nelore_imputed, n_pcs = 10)
head(pr$pcs[, 1:2])
}