runPCA: Principal components analysis

runPCAR Documentation

Principal components analysis

Description

Perform a principal components analysis (PCA) on a target matrix with a specified SVD algorithm.

Usage

runPCA(x, ...)

## S4 method for signature 'ANY'
runPCA(x, rank, center=TRUE, scale=FALSE, get.rotation=TRUE,
    get.pcs=TRUE, ...) 

Arguments

x

A numeric matrix-like object with samples as rows and variables as columns.

rank

Integer scalar specifying the number of principal components to retain.

center

A logical scalar indicating whether columns of x should be centered before the PCA is performed. Alternatively, a numeric vector of length ncol(x) containing the value to subtract from each column of x.

scale

A logical scalar indicating whether columns of x should be scaled to unit variance before the PCA is performed. Alternatively, a numeric vector of length ncol(x) containing the scaling factor for each column of x.

get.rotation

A logical scalar indicating whether rotation vectors should be returned.

get.pcs

A logical scalar indicating whether the principal component scores should be returned.

...

For the generic, this contains arguments to pass to methods upon dispatch.

For the ANY method, this contains further arguments to pass to runSVD. This includes BSPARAM to specify the algorithm that should be used, and BPPARAM to control parallelization.

Details

This function simply calls runSVD and converts the results into a format similar to that returned by prcomp.

The generic is exported to allow other packages to implement their own runPCA methods for other x objects, e.g., scater for SingleCellExperiment inputs.

Value

A list is returned containing:

  • sdev, a numeric vector of length rank containing the standard deviations of the first rank principal components.

  • rotation, a numeric matrix with rank columns and nrow(x) rows, containing the first rank rotation vectors. This is only returned if get.rotation=TRUE.

  • x, a numeric matrix with rank columns and ncol(x) rows, containing the scores for the first rank principal components. This is only returned if get.pcs=TRUE.

Author(s)

Aaron Lun

See Also

runSVD for the underlying SVD function.

?BiocSingularParam for details on the algorithm choices.

Examples

a <- matrix(rnorm(100000), ncol=20)
str(out <- runPCA(a, rank=10))

LTLA/BiocSingular documentation built on Sept. 26, 2024, 4:14 a.m.