scmorph.pp.pca#
- scmorph.pp.pca(adata, n_comps=None, scale_by_var=False, *, copy=False, zero_center=True, random_state=0, **kwargs)[source]#
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
int|None(default:None) Number of principal components to compute. Defaults to 50, or 1 - minimum dimension size of selected representation.
- scale_by_var
bool(default:False) Whether to scale PC coordinates by variance explained. This is useful when computing distances on PCs.
- 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). IfFalse, 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().
- adata
- Return type:
AnnData|None- Returns:
Returns
Noneifcopy=False, else returns anAnnDataobject. 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.