scib.metrics.pcr

scib.metrics.pcr(adata, covariate, embed=None, n_comps=50, recompute_pca=True, verbose=False)

Principal component regression for anndata object

Wraps pc_regression() while checking whether to:

  • compute PCA on embedding or expression data (set embed to name of embedding matrix e.g. embed='X_emb')

  • use existing PCA (only if PCA entry exists)

  • recompute PCA on expression matrix (default)

Parameters
  • adata – Anndata object

  • covariate – Key for adata.obs column to regress against

  • embed – Embedding to use for principal component analysis. If None, use the full expression matrix (adata.X), otherwise use the embedding provided in adata.obsm[embed].

  • n_comps – Number of PCs, if PCA is recomputed. The PCA will be recomputed if neither PCA loadings nor the principle components can be found.

  • recompute_pca – whether to recompute a PCA on the

Returns

Variance contribution of regression

The function can be computed on full corrected feature spaces and latent embeddings. No preprocessing is needed, as the function can perform PCA if recompute_pca=True. Alternatively, you can also provide precomputed PCA, if the principle components are saved under .obsm["X_pca"] and the PC loadings are saved in .uns["pca"]["variance"].

Examples

# full feature output
scib.me.pcr(adata, covariate="batch", recompute_pca=True)

# embedding output
scib.me.pcr(adata, covariate="batch", embed="X_emb")