characterize_clusters: Characterise clusters with external (biological / clinical)...

View source: R/characterize.R

characterize_clustersR Documentation

Characterise clusters with external (biological / clinical) variables

Description

For a clustering, summarise how each external variable differs across the clusters. Continuous variables get n, mean, SD, median, IQR and range per cluster, an overall Kruskal-Wallis test, a rank \eta^2 effect size, and gradient detection (are the cluster means monotonically ordered?). Categorical variables get per-cluster counts and column percentages, a chi-squared / Fisher test and Cramer's V. The emphasis is on effect sizes and descriptive summaries rather than p-values alone.

Usage

characterize_clusters(labels, metadata, continuous = NULL, categorical = NULL)

Arguments

labels

Cluster label of each object (vector; NA allowed).

metadata

A data frame of external variables, one row per object, in the same order as labels.

continuous, categorical

Optional character vectors naming the columns to treat as continuous / categorical. If NULL, numeric columns are taken as continuous and the rest as categorical.

Value

A list with continuous (per-cluster summary, long format), continuous_tests (one row per variable: KW_p, eta2, gradient – the clusters ordered by mean – and a monotone-trend trend_rho/trend_p), categorical (counts and column percentages) and categorical_tests (p, cramers_v).

See Also

plot_cluster_profile, cluster_biology_panel

Examples

data(mosaic_toy)
fit <- M_ABC(mosaic_toy$List, numsim = 40, NC = 3)
cl  <- mosaic_labels(fit, 3)
meta <- data.frame(score = rnorm(length(cl)), grp = sample(c("A", "B"), length(cl), TRUE))
ch  <- characterize_clusters(cl, meta)
ch$continuous_tests

MosaiClusteR documentation built on Oct. 25, 2026, 1:08 a.m.