Calculate silhouette widths from a Seurat embedding
Source:R/analysis_metrics.R
sn_calculate_silhouette.RdSilhouette widths summarize how well cells are separated by a categorical metadata label in the selected embedding.
Usage
sn_calculate_silhouette(
x,
label,
reduction = "pca",
dims = NULL,
cells = NULL,
max_cells = 3000,
stratify_by = label,
seed = 717
)Arguments
- x
A Seurat object.
- label
Metadata column used as the grouping label.
- reduction
Reduction name used to extract embeddings. Defaults to
"pca".- dims
Optional integer vector of embedding dimensions to retain.
- cells
Optional character vector of cell names to score.
- max_cells
Optional integer cap used to subsample cells before running the metric. Defaults to
3000because silhouette needs a full distance matrix.- stratify_by
Optional metadata column used to preserve representation during subsampling. Defaults to
label.- seed
Random seed used when
max_cellstriggers subsampling.
Examples
if (FALSE) { # \dontrun{
data("pbmc_small", package = "Shennong")
pbmc <- sn_run_cluster(
pbmc_small,
batch = "sample",
species = "human",
verbose = FALSE
)
sil_tbl <- sn_calculate_silhouette(
pbmc,
label = "seurat_clusters",
reduction = "harmony"
)
head(sil_tbl)
} # }