
Calculate the principal component regression on batch
calculate_pcr_sc.RdRegresses each embedding dimension on the batch labels and weights the
per-dimension R-squared by the variance of that dimension. On its own the
number says how much of the embedding variance batch explains. For a
corrected embedding, the function also runs it on the uncorrected PCA and
reports the scIB comparison (pre - post) / pre: 1 means the batch
variance is gone, 0 means nothing changed, negative means it got worse.
Value
A PcrScores object with the following elements
pcr - Variance-weighted R-squared of batch on
embd_to_use.pcr_pca - The same on the uncorrected PCA.
pcr_comparison -
(pcr_pca - pcr) / pcr_pca.NAifembd_to_use = "pca".var_explained - Variance per embedding dimension.
r_squared - Batch R-squared per embedding dimension.
embedding_used - Which embedding the PCR was computed on.
Examples
# share of PCA variance explained by batch
sc <- demo_single_cells(
syn_data_params = params_sc_synthetic_data(
n_cells = 600L, n_genes = 50L, n_batches = 3L
)
)
calculate_pcr_sc(sc, batch_column = "batch_index")
#> Principal Component Regression (batch)
#> Embedding: pca | Dimensions: 10
#> PCR: 0.1414
unlink(sc@dir_data, recursive = TRUE, force = TRUE)