runPCA: Principal components analysis

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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

Usage

1
2
3
4
5
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:

Author(s)

Aaron Lun

See Also

runSVD for the underlying SVD function.

?BiocSingularParam for details on the algorithm choices.

Examples

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

Example output

List of 3
 $ sdev    : num [1:10] 1.06 1.04 1.04 1.03 1.03 ...
 $ rotation: num [1:20, 1:10] 0.0259 0.2733 0.2581 -0.1309 -0.1749 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:10] "PC1" "PC2" "PC3" "PC4" ...
 $ x       : num [1:5000, 1:10] -2.049 -1.38 0.896 2.226 -0.555 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:10] "PC1" "PC2" "PC3" "PC4" ...

BiocSingular documentation built on Nov. 8, 2020, 10:59 p.m.