scmorph.pp.pca

Contents

scmorph.pp.pca#

scmorph.pp.pca(adata, n_comps=None, whiten=False, *, copy=False, zero_center=True, random_state=0, **kwargs)#

Principal component analysis [Pedregosa et al., 2011].

Computes PCA coordinates, loadings and variance decomposition. Uses the implementation of scikit-learn [Pedregosa et al., 2011].

This function wraps the higher-level function pca() ([Wolf et al., 2018]).

It provides addional functionality to whiten the resulting PCA coordinates, which may help de-correlate them.

Parameters:
  • adata (AnnData) – AnnData object

  • n_comps (Optional[int] (default: None)) – Number of principal components to compute. Defaults to 50, or 1 - minimum dimension size of selected representation.

  • whiten (bool (default: False)) – Whether to whiten the data. This can help remove correlation in the resulting PC axes.

  • copy (bool (default: False)) – Return a copy instead of writing to adata.

  • zero_center (bool | None (default: True)) – If True, compute standard PCA from covariance matrix (strongly recommended). If False, omit zero-centering variable.

  • random_state (int | None (default: 0)) – Change to use different initial states for the optimization.

  • kwargs (Any) – Additional arguments passed to pca().

Return type:

AnnData | None

Returns:

Returns None if copy=False, else returns an AnnData object. Sets the following fields:

.obsm['X_pca' | key_added]spmatrix | ndarray (shape (adata.n_obs, n_comps))

PCA representation of data.

.varm['PCs' | key_added]ndarray (shape (adata.n_vars, n_comps))

The principal components containing the loadings.

.uns['pca' | key_added]['variance_ratio']ndarray (shape (n_comps,))

Ratio of explained variance.

.uns['pca' | key_added]['variance']ndarray (shape (n_comps,))

Explained variance, equivalent to the eigenvalues of the covariance matrix.