Skip to contents

Evaluates both unsupervised cluster separation (ASW, Dunn, Connectivity, DB, CH, Neighborhood Purity, CDI) and supervised concordance against ground truth labels (Clustering Accuracy ACC, Hungarian F1/Precision/Recall, ARI, NMI, AMI, FMI, Homogeneity, Completeness, V-measure).

Usage

evaluate_clustering_metrics(
  data,
  cluster_info = NULL,
  pred_clusters = NULL,
  dist_mat = NULL,
  cell_types = NULL,
  ref_data = NULL
)

Arguments

data

Count or normalized matrix (features x cells).

cluster_info

Cluster or cell type labels.

pred_clusters

Optional predicted cluster labels (if different from ground truth). If NULL, k-means is automatically run.

dist_mat

Optional precomputed distance matrix.

cell_types

Optional alias for cluster_info.

ref_data

Optional reference data to compute reference clustering quality.

Value

A named list of all clustering metrics.

Examples

data <- matrix(stats::rnorm(200), 20, 10)
cl <- factor(rep(c("A", "B"), each = 5))
dist_mat <- stats::dist(data)
evaluate_clustering_metrics(data, cl)
#> Warning: NaNs produced
#> $silhouette_sim
#> [1] 0.003646974
#> 
#> $silhouette
#> [1] 0.003646974
#> 
#> $dunn_sim
#> [1] 0.5774565
#> 
#> $dunn
#> [1] 0.5774565
#> 
#> $connectivity_sim
#> [1] NA
#> 
#> $connectivity
#> [1] NA
#> 
#> $davies_bouldin_sim
#> [1] 2.80252
#> 
#> $davies_bouldin
#> [1] 2.80252
#> 
#> $calinski_harabasz_sim
#> [1] 1.018402
#> 
#> $calinski_harabasz
#> [1] 1.018402
#> 
#> $neighborhood_purity
#> [1] 0.44
#> 
#> $cdi
#> [1] -4.558348
#> 
#> $CDI_AIC
#> [1] -4.558348
#> 
#> $CDI_BIC
#> [1] -4.497831
#> 
#> $clustering_accuracy
#> [1] 0.5
#> 
#> $accuracy
#> [1] 0.5
#> 
#> $hungarian_F1
#> [1] 0.4505495
#> 
#> $hungarian_precision
#> [1] 0.5
#> 
#> $hungarian_recall
#> [1] 0.5
#> 
#> $ari
#> [1] -0.07655502
#> 
#> $ARI
#> [1] -0.07655502
#> 
#> $nmi
#> 1 
#> 0 
#> 
#> $NMI
#> 1 
#> 0 
#> 
#> $ami
#> [1] 0
#> 
#> $AMI
#> [1] 0
#> 
#> $fmi
#> [1] 0.4982729
#> 
#> $FMI
#> [1] 0.4982729
#> 
#> $homogeneity
#> [1] 0
#> 
#> $completeness
#> [1] 0
#> 
#> $v_measure
#> [1] 0
#> 
#> $matched_pairs
#>   pred truth precision recall        F1
#> 1    2     A       0.5    0.8 0.6153846
#> 2    1     B       0.5    0.2 0.2857143
#>