scib.metrics.pcr_comparison

scib.metrics.pcr_comparison(adata_pre, adata_post, covariate, embed=None, n_comps=50, linreg_method='numpy', recompute_pca=False, scale=True, verbose=False, n_threads=1)

Principal component regression score

Compare the explained variance before and after integration using pc_regression(). Return either the raw difference in variance contribution before and after integration or a scaled score (scale=True).

With scale=True, the score is computed as (pcr_before - pcr_after) / pcr_before and clipped to 0 if it becomes negative (i.e. when variance contribution increases after integration).

Parameters:
  • adata_pre – Anndata object before integration

  • adata_post – Anndata object after integration

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

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

  • n_comps – Number of principal components to compute

  • linreg_method – Method for linear regression passed to pc_regression() ('sklearn', 'numpy', or 'sequential').

  • recompute_pca – Whether to recompute PCA. If False (default), use existing PCA stored in adata.obsm["X_pca"] and adata.uns["pca"]["variance"] if available.

  • scale – If True (default), scale score between 0 and 1, where 0 means no change in variance contribution after integration. If False, return the raw difference of variance contributions (post minus pre).

  • verbose – If True, print progress information

  • n_threads – Number of threads to pass to the selected regression backend (for example BLAS/OpenMP thread limits for 'numpy' and estimator-level parallelism where supported).

Returns:

Difference of variance contribution of PCR (scaled between 0 and 1 by default)

The function can be computed on full corrected feature spaces and latent embeddings for both integrated and unintegrated anndata.Anndata objects. No preprocessing is needed, as the function will perform PCA directly on the feature or embedding space.

Examples

# full feature output
scib.me.pcr_comparison(adata_unintegrated, adata, covariate="batch")

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