Calculate cluster purity against a reference label
Source:R/analysis_metrics.R
sn_calculate_cluster_purity.RdCluster purity summarizes how homogeneous each cluster is with respect to a reference label. This is useful for checking whether clustering preserves known cell identities after integration.
Examples
meta <- data.frame(
cluster = c("T", "T", "B", "B"),
label = c("T", "T", "B", "B")
)
sn_calculate_cluster_purity(meta, cluster = "cluster", label = "label")
#> cluster n_cells dominant_label dominant_label_n purity_score impurity_score
#> 1 T 2 T 2 1 0
#> 2 B 2 B 2 1 0