pcMetaCorrelations provides tools to identify metadata columns that are driving principal component embeddings.
# install.packages("devtools")
devtools::install_local("../pcMetaCorrelations")
library(pcMetaCorrelations)
res <- pc_meta_correlations(pca_matrix, metadata, mode = "lm")
plot_pc_meta_heatmap(res)
plot_top_pc_meta(res, n = 10, value = "effect_size")mode = "lm" fits a linear model for each metadata/PC combination.
lm(PC ~ metadata)
lm(PC ~ factor(metadata))
mode = "correlation" preserves the original correlation-based approach.metadata: metadata field namepc: PCA axis nametype: numeric or categorical
statistic: model coefficient or test statisticp.value: raw p-value for the associationadj.p.value: adjusted p-valueeffect_size: magnitude of the associationdirection: direction or top factor level
library(pcMetaCorrelations)
if (requireNamespace("Seurat", quietly = TRUE)) {
seurat_obj <- Seurat::pbmc_small
res <- pc_meta_correlations(seurat_obj, reduction = "pca", mode = "lm")
plot_pc_meta_heatmap(res)
}A richer metadata example is available from SeuratData::celegans.embryo, which contains more than 20 metadata columns.
if (requireNamespace("SeuratData", quietly = TRUE)) {
SeuratData::InstallData("celegans.embryo")
data("celegans.embryo", package = "celegans.embryo.SeuratData")
celegans.embryo <- Seurat::UpdateSeuratObject(celegans.embryo)
res2 <- pc_meta_correlations(celegans.embryo, reduction = "pca", mode = "lm")
plot_pc_meta_heatmap(res2, top_n = 15, top_pcs = 8)
plot_top_pc_meta(res2, n = 10, value = "effect_size")
}Read the full package website at https://lachland.github.io/pcMetaCorrelations/index.html.