getExplanatoryPCs {scater} | R Documentation

## Estimate the percentage of variance explained for each PC.

### Description

Estimate the percentage of variance explained for each PC.

### Usage

    getExplanatoryPCs(object, use_dimred = "PCA", ncomponents = 10,
      rerun = FALSE, run_args = list(), ...)

### Arguments

`object` | A SingleCellExperiment object containing expression values and per-cell experimental information.
`use_dimred` | String specifying the field in `reducedDims(object)` that contains the PCA results.
`ncomponents` | Integer scalar specifying the number of the top principal components to use.
`rerun` | Logical scalar indicating whether the PCA should be repeated, even if pre-computed results are already present.
`run_args` | A named list of arguments to pass to `runPCA`.
`...` | Additional arguments passed to `getVarianceExplained`.

### Details

This function computes the percentage of variance in PC scores that is explained by variables in the sample-level metadata. It allows identification of important PCs that are driven by known experimental conditions, e.g., treatment, disease. PCs correlated with technical factors (e.g., batch effects, library size) can also be detected and removed prior to further analysis.

By default, the function will attempt to use pre-computed PCA results in `object`. This is done by taking the top `ncomponents` PCs from the matrix identified by `use_dimred`. If these are not available or if `rerun=TRUE`, the function will rerun the PCA using `runPCA`.

### Value

A matrix containing the percentage of variance explained by each factor (column) and for each PC (row).

### Author(s)

Aaron Lun

### See Also

`plotExplanatoryPCs`, `getVarianceExplained`

### Examples

    data("sc_example_counts")
    data("sc_example_cell_info")
    example_sce <- SingleCellExperiment(
        assays = list(counts = sc_example_counts),
        colData = sc_example_cell_info)
    example_sce <- normalize(example_sce)

    r2mat <- getExplanatoryPCs(example_sce)

[Package scater version 1.12.2 Index]