CDiscover · discover.sigclust
Is the split significant? (SigClust)
Is the best two-group split of these rows stronger than what a single Gaussian cloud would give?
Tests whether the data hold two real clusters or one Gaussian cloud. The statistic is the cluster index — the within-cluster sum of squares of the best 2-means split over the total — and its null distribution comes from simulating Gaussian data with the same eigenvalues as the data, raised to a background noise level estimated robustly from all values (soft thresholding by default, Huang et al. 2015). A small p-value says the split is stronger than one Gaussian cloud of this shape would give. Give a split of your own to test it instead of the 2-means split.
A real result
Example “One cloud”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
The best 2-means split has cluster index 0.722 (null mean 0.734); p = 0.33: the split is explained by one Gaussian cloud.
- Cluster index
- 0.7215
- p (simulated)
- .330
- p (Gaussian fit)
- .345
Plots
Normal curve fitted to 100 simulated cluster indices; a split far to the left of it is stronger than one cloud would give.
View data
| 5% critical value | Null density (normal fit) | Observed cluster index | Cluster index |
|---|---|---|---|
| 0.6838 | 1.710e-5 | 0.7215 | 0.5758 |
| 0.6838 | 2.273e-5 | 0.7215 | 0.5774 |
| 0.6838 | 3.010e-5 | 0.7215 | 0.5791 |
| 0.6838 | 3.976e-5 | 0.7215 | 0.5808 |
| 0.6838 | 5.235e-5 | 0.7215 | 0.5824 |
| 0.6838 | 6.872e-5 | 0.7215 | 0.5841 |
| 0.6838 | 8.994e-5 | 0.7215 | 0.5858 |
| 0.6838 | 0.0001 | 0.7215 | 0.5874 |
| 0.6838 | 0.0002 | 0.7215 | 0.5891 |
| 0.6838 | 0.0002 | 0.7215 | 0.5907 |
| 0.6838 | 0.0003 | 0.7215 | 0.5924 |
| 0.6838 | 0.0003 | 0.7215 | 0.5941 |
| 0.6838 | 0.0004 | 0.7215 | 0.5957 |
| 0.6838 | 0.0005 | 0.7215 | 0.5974 |
| 0.6838 | 0.0007 | 0.7215 | 0.5991 |
| 0.6838 | 0.0009 | 0.7215 | 0.6007 |
| 0.6838 | 0.0011 | 0.7215 | 0.6024 |
| 0.6838 | 0.0014 | 0.7215 | 0.6041 |
| 0.6838 | 0.0018 | 0.7215 | 0.6057 |
| 0.6838 | 0.0023 | 0.7215 | 0.6074 |
| 0.6838 | 0.0028 | 0.7215 | 0.6090 |
| 0.6838 | 0.0035 | 0.7215 | 0.6107 |
| 0.6838 | 0.0044 | 0.7215 | 0.6124 |
| 0.6838 | 0.0055 | 0.7215 | 0.6140 |
| 0.6838 | 0.0068 | 0.7215 | 0.6157 |
| 0.6838 | 0.0084 | 0.7215 | 0.6174 |
| 0.6838 | 0.0104 | 0.7215 | 0.6190 |
| 0.6838 | 0.0128 | 0.7215 | 0.6207 |
| 0.6838 | 0.0156 | 0.7215 | 0.6224 |
| 0.6838 | 0.0191 | 0.7215 | 0.6240 |
| 0.6838 | 0.0233 | 0.7215 | 0.6257 |
| 0.6838 | 0.0282 | 0.7215 | 0.6273 |
| 0.6838 | 0.0342 | 0.7215 | 0.6290 |
| 0.6838 | 0.0412 | 0.7215 | 0.6307 |
| 0.6838 | 0.0496 | 0.7215 | 0.6323 |
| 0.6838 | 0.0595 | 0.7215 | 0.6340 |
| 0.6838 | 0.0711 | 0.7215 | 0.6357 |
| 0.6838 | 0.0848 | 0.7215 | 0.6373 |
| 0.6838 | 0.1008 | 0.7215 | 0.6390 |
| 0.6838 | 0.1195 | 0.7215 | 0.6407 |
| 0.6838 | 0.1411 | 0.7215 | 0.6423 |
| 0.6838 | 0.1662 | 0.7215 | 0.6440 |
| 0.6838 | 0.1952 | 0.7215 | 0.6456 |
| 0.6838 | 0.2286 | 0.7215 | 0.6473 |
| 0.6838 | 0.2668 | 0.7215 | 0.6490 |
| 0.6838 | 0.3105 | 0.7215 | 0.6506 |
| 0.6838 | 0.3603 | 0.7215 | 0.6523 |
| 0.6838 | 0.4168 | 0.7215 | 0.6540 |
| 0.6838 | 0.4808 | 0.7215 | 0.6556 |
| 0.6838 | 0.5528 | 0.7215 | 0.6573 |
| 0.6838 | 0.6337 | 0.7215 | 0.6590 |
| 0.6838 | 0.7244 | 0.7215 | 0.6606 |
| 0.6838 | 0.8254 | 0.7215 | 0.6623 |
| 0.6838 | 0.9378 | 0.7215 | 0.6640 |
| 0.6838 | 1.062 | 0.7215 | 0.6656 |
| 0.6838 | 1.200 | 0.7215 | 0.6673 |
| 0.6838 | 1.351 | 0.7215 | 0.6689 |
| 0.6838 | 1.516 | 0.7215 | 0.6706 |
| 0.6838 | 1.697 | 0.7215 | 0.6723 |
| 0.6838 | 1.893 | 0.7215 | 0.6739 |
First 60 of 200 rows.
Covariance eigenvalues: data and null
| Component | Data | Null (simulated) |
|---|---|---|
| 1 | 3.409 | 3.409 |
| 2 | 1.487 | 1.487 |
| 3 | 1.158 | 1.257 |
| 4 | 1.102 | 1.257 |
| 5 | 0.7429 | 1.257 |
The best 2-means split has cluster index 0.722 (null mean 0.734); p = 0.33: the split is explained by one Gaussian cloud.
- Cluster index
- 0.7215
- p (simulated)
- .330
- p (Gaussian fit)
- .345
To keep this page light, the plots are shown once, under the R tab.
Covariance eigenvalues: data and null
| Component | Data | Null (simulated) |
|---|---|---|
| 1 | 3.409 | 3.409 |
| 2 | 1.487 | 1.487 |
| 3 | 1.158 | 1.257 |
| 4 | 1.102 | 1.257 |
| 5 | 0.7429 | 1.257 |
Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.
Worked examples in the app
- One cloudclu4_sigclust · features: g1, g2, g3, g4, g5
- Two cloudsclu4_sigclust · features: c1, c2, c3, c4, c5
- Two clouds given split hardclu4_sigclust · features: c1, c2, c3, c4, c5 · split: split
- Iris sample standardizedml_iris · features: sepal_length, sepal_width, petal_length, petal_width
- Degenerate constantclu4_sigclust · features: g1, g2, g3, g4, g5
- Degenerate all naclu4_sigclust · features: g1, g2, g3, g4, g5
- Degenerate infclu4_sigclust · features: g1, g2, g3, g4, g5
- Degenerate n3clu4_sigclust · features: g1, g2, g3, g4, g5
In the guides
Where it sits in the decision guides
- Testing and comparing clusterings (SigClust, selective inference, ARI, CKA) · DS & ML Decision Guide · Discover — find structure without labels
- Discover: cluster quality (silhouette, ARI); coherence (topics); stability and interpretability · DS & ML Decision Guide · How to evaluate — common metrics by question type
What you need
- Variablesnumeric · 1–500 columns
- Numbers that define the clouds (centered; rows with a missing value are left out). SigClust assumes they share units, as in gene expression.
- Split to testcategorical / boolean / numeric · 0–1 column
- Optional: a two-group column (saved cluster labels) to test instead of the best 2-means split.
Choices you make
model
- Simulationsdefault 500
Gaussian data sets simulated under the null; more gives a steadier p-value.
- Null eigenvaluesdefault soft
How the null Gaussian's variances come from the data's covariance eigenvalues and the background noise.
- Soft thresholding (Huang et al. 2015)(default) — Shrinks the large eigenvalues and raises small ones to the noise level, with the sigclust package's choice of shrinkage: the recommended default.
- Hard thresholding (Liu et al. 2008) — Raises eigenvalues below the noise level to it; can be anti-conservative with many variables.
- Sample eigenvalues — Uses the eigenvalues as estimated (negatives set to 0); too few rows for the variables make it conservative.
- Scale variablesdefault none
SigClust pools all values to estimate the background noise, so variables should share units.
- Center only(default) — Keeps the variables' own scales (the method's assumption).
- Standardize — Gives every variable unit SD first; use when units differ.
Advanced
- 2-means startsdefault 3
k-means++ starts per split; the best is kept for the data and for every simulation.
What it reports
- n
- Rows and variables in the test; SigClust was built for many more variables than rows, as in gene expression.
- d
- Rows and variables in the test; SigClust was built for many more variables than rows, as in gene expression.
- ci
- Within-cluster sum of squares of a two-group split divided by the total; smaller = a cleaner split.
- p_empirical
- Tests whether the best two-group split beats what one Gaussian cloud with the data's shape would give.
- p_gaussian
- Cluster indices of Gaussian data simulated with the null eigenvalues; their mean and SD give the Gaussian-fit p-value.
- sim_mean
- Cluster indices of Gaussian data simulated with the null eigenvalues; their mean and SD give the Gaussian-fit p-value.
- sim_sd
- Cluster indices of Gaussian data simulated with the null eigenvalues; their mean and SD give the Gaussian-fit p-value.
- sigma2_background
- Noise level estimated robustly from all values (MAD squared); small eigenvalues are raised to it in the null.
- tau
- Shrinks large covariance eigenvalues by τ and raises small ones to the noise level, so the null isn't too spiky.
- n_floored
- Noise level estimated robustly from all values (MAD squared); small eigenvalues are raised to it in the null.
- size_1
- Within-cluster sum of squares of a two-group split divided by the total; smaller = a cleaner split.
- size_2
- Within-cluster sum of squares of a two-group split divided by the total; smaller = a cleaner split.
- sims
- Tests whether the best two-group split beats what one Gaussian cloud with the data's shape would give.
Python and R
Python and R agree to 6 decimals (relative tolerance 1e-8). Python uses numpy, scipy; R uses codesplashr.
Default traps between the two languages
- Simulated data and k-means++ starts come from the shared Wichmann–Hill stream and both engines run the same written-out Lloyd iterations, so every simulated cluster index matches. The R package sigclust draws with R's own random numbers and k-means starts, so its p-values differ from run to run; its background noise, soft-thresholded eigenvalues and observed cluster index match.
The exact script CodeSplash ran for example “One cloud” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Is the split significant? (SigClust)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method discover.sigclust 1.0.0 · spec 998fdf91be44d712
# Dataset: clu4_sigclust (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
from scipy.stats import norm
import codesplash as cs
from codesplash.errors import check_groups
from codesplash.ml import cluster_checks as ck
from codesplash.ml import cluster_compare as cc
from codesplash.ml import embed as csembed
from codesplash.stats.rng import Rng
# %% Data
FEATURES = ["g1", "g2", "g3", "g4", "g5"]
SPLIT = None # optional two-group column to test
SEED = 42
SIMS = 100
STARTS = 3
METHOD = "soft"
SCALE = "none"
cols = list(dict.fromkeys(FEATURES + ([SPLIT] if SPLIT else [])))
df = pd.read_parquet("tests/parity/fixtures/clu4_sigclust.parquet", columns=cols)
n_input = len(df)
cs.check_finite_columns(df, cols) # ±Inf stops with CS_E_NOT_FINITE in both engines
rows = csembed.complete_rows(df, cols)
warnings = []
if len(rows) < n_input:
warnings.append(f"{n_input - len(rows)} of {n_input} rows were left out because a value was missing.")
cs.check_rows(len(rows), 5, "SigClust")
X = csembed.numeric_matrix(df, FEATURES, rows)
if np.all(np.ptp(X, axis=0) == 0):
cs.cs_error("CS_E_CONSTANT", column=", ".join(FEATURES))
if SCALE == "standardize":
flat = np.ptp(X, axis=0) == 0
X = csembed.standardize(X, ddof=1)
X[:, flat] = 0.0 # constant columns exactly 0 in both engines
split = None
if SPLIT:
lab = cc.label_text(df[SPLIT].iloc[rows].tolist())
check_groups(pd.Series(lab, dtype=object), SPLIT, exactly=2)
levels = sorted(set(lab.tolist()))
split = np.array([levels.index(v) for v in lab], dtype=np.int64)
# %% SigClust
r = ck.sigclust(X, SIMS, STARTS, METHOD, Rng(SEED), split)
lab = np.asarray(r["labels"])
sizes = sorted([int(np.sum(lab == c)) for c in np.unique(lab)], reverse=True) + [0, 0]
values = {
"n": r["n"], "d": r["d"], "ci": r["ci"], "p_empirical": r["p_empirical"], "p_gaussian": r["p_gaussian"],
"sim_mean": r["sim_mean"], "sim_sd": r["sim_sd"], "sigma2_background": r["sigma2_background"], "tau": r["tau"],
"n_floored": r["n_floored"], "size_1": sizes[0], "size_2": sizes[1], "sims": SIMS,
}
if values["tau"] != values["tau"]:
warnings.append("Every eigenvalue is below the background noise level, so the null uses the noise level for all of them.")
eig = r["eigen"]
eig0 = r["eigen_null"]
tables = [{
"key": "eigenvalues",
"title": "Covariance eigenvalues: data and null",
"columns": [{"key": "component", "label": "Component", "type": "integer"},
{"key": "sample", "label": "Data", "type": "number"},
{"key": "null", "label": "Null (simulated)", "type": "number"}],
"rows": [{"component": j + 1, "sample": float(eig[j]), "null": float(eig0[j])} for j in range(min(len(eig), 50))],
}]
# %% Null distribution chart (normal fitted to the simulated cluster indices)
sims = r["sims"]
m, s = values["sim_mean"], values["sim_sd"]
charts = []
if s == s and s > 0:
lo = min(float(np.min(sims)), values["ci"]) - 3 * s
hi = max(float(np.max(sims)), values["ci"]) + 3 * s
grid = np.linspace(lo, hi, 200)
charts.append(cs.chart(
"null", "null-distribution", "Cluster index under one Gaussian cloud",
{
"x": cs.col("Cluster index", list(grid), "numeric"),
"density": cs.col("Null density (normal fit)", list(norm.pdf(grid, m, s)), "numeric"),
"observed": cs.col("Observed cluster index", [values["ci"]] * len(grid), "numeric"),
"critical_low": cs.col("5% critical value", [float(norm.ppf(0.05, m, s))] * len(grid), "numeric"),
},
note=f"Normal curve fitted to {SIMS} simulated cluster indices; a split far to the left of it is stronger than one cloud would give.",
))
# %% Result
p = values["p_empirical"]
verdict = "stronger than one Gaussian cloud would give" if p < 0.05 else "explained by one Gaussian cloud"
cs.publish({
"title": "Is the split significant? (SigClust)",
"engine": cs.engine_info("numpy", "scipy", "pandas"),
"n": values["n"],
"summary": f"{'The given split' if SPLIT else 'The best 2-means split'} has cluster index {values['ci']:.3f} (null mean {m:.3f}); p = {p:.3g}: the split is {verdict}.",
"statistics": [
{"key": "ci", "label": "Cluster index", "value": values["ci"]},
{"key": "p_empirical", "label": "p (simulated)", "value": p, "format": "p"},
{"key": "p_gaussian", "label": "p (Gaussian fit)", "value": values["p_gaussian"], "format": "p"},
],
"tables": tables,
"values": values,
"charts": charts,
"warnings": warnings,
})
The exact script CodeSplash ran for example “One cloud” · R version 4.5.1 (2025-06-13)
# Is the split significant? (SigClust)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method discover.sigclust 1.0.0 · spec 998fdf91be44d712
# Dataset: clu4_sigclust (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
FEATURES <- c("g1", "g2", "g3", "g4", "g5")
SPLIT <- NULL # optional two-group column to test
SEED <- 42
SIMS <- 100
STARTS <- 3
METHOD <- "soft"
SCALE <- "none"
cols <- unique(c(FEATURES, if (!is.null(SPLIT)) SPLIT))
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/clu4_sigclust.parquet", col_select = cols))
n_input <- nrow(df)
cs_check_finite_columns(df, cols) # ±Inf stops with CS_E_NOT_FINITE in both engines
rows <- cs_ml_complete_rows(df, cols)
warnings <- list()
if (length(rows) < n_input) warnings <- c(warnings, sprintf("%d of %d rows were left out because a value was missing.", n_input - length(rows), n_input))
cs_check_rows(length(rows), 5, "SigClust")
X <- cs_ml_numeric_matrix(df, FEATURES, rows)
if (all(apply(X, 2, function(v) max(v) - min(v)) == 0)) cs_error("CS_E_CONSTANT", column = paste(FEATURES, collapse = ", "))
if (SCALE == "standardize") {
flat <- apply(X, 2, function(v) max(v) - min(v)) == 0
s <- apply(X, 2, stats::sd)
s[flat] <- 1
X <- sweep(sweep(X, 2, colMeans(X)), 2, s, "/")
X[, flat] <- 0 # constant columns exactly 0 in both engines
}
split <- NULL
if (!is.null(SPLIT)) {
lab <- cs_ml_label_text(df[[SPLIT]][rows + 1L])
cs_check_groups(lab, SPLIT, exactly = 2)
levels <- sort(unique(lab), method = "radix")
split <- match(lab, levels) - 1L
}
# %% SigClust
r <- cs_ml_sigclust(X, SIMS, STARTS, METHOD, cs_rng(SEED), split)
lab <- r$labels
sizes <- c(sort(as.integer(table(lab)), decreasing = TRUE), 0L, 0L)
values <- list(n = r$n, d = r$d, ci = r$ci, p_empirical = r$p_empirical, p_gaussian = r$p_gaussian,
sim_mean = r$sim_mean, sim_sd = r$sim_sd, sigma2_background = r$sigma2_background, tau = r$tau,
n_floored = r$n_floored, size_1 = sizes[1], size_2 = sizes[2], sims = SIMS)
if (is.nan(values$tau)) warnings <- c(warnings, "Every eigenvalue is below the background noise level, so the null uses the noise level for all of them.")
eig <- r$eigen
eig0 <- r$eigen_null
tables <- list(list(key = "eigenvalues", title = "Covariance eigenvalues: data and null",
columns = list(list(key = "component", label = "Component", type = "integer"),
list(key = "sample", label = "Data", type = "number"),
list(key = "null", label = "Null (simulated)", type = "number")),
rows = lapply(seq_len(min(length(eig), 50)), function(j) list(component = j, sample = eig[j], null = eig0[j]))))
# %% Null distribution chart (normal fitted to the simulated cluster indices)
sims <- r$sims
m <- values$sim_mean
s <- values$sim_sd
charts <- list()
if (is.finite(s) && s > 0) {
lo <- min(min(sims), values$ci) - 3 * s
hi <- max(max(sims), values$ci) + 3 * s
grid <- seq(lo, hi, length.out = 200)
charts[[1]] <- cs_chart("null", "null-distribution", "Cluster index under one Gaussian cloud", list(
x = cs_col("Cluster index", grid, "numeric"),
density = cs_col("Null density (normal fit)", stats::dnorm(grid, m, s), "numeric"),
observed = cs_col("Observed cluster index", rep(values$ci, length(grid)), "numeric"),
critical_low = cs_col("5% critical value", rep(stats::qnorm(0.05, m, s), length(grid)), "numeric")
), note = sprintf("Normal curve fitted to %d simulated cluster indices; a split far to the left of it is stronger than one cloud would give.", SIMS))
}
# %% Result
p <- values$p_empirical
verdict <- if (p < 0.05) "stronger than one Gaussian cloud would give" else "explained by one Gaussian cloud"
cs_publish(list(
title = "Is the split significant? (SigClust)",
engine = cs_engine_info("codesplashr", "nanoparquet"),
n = values$n,
summary = sprintf("%s has cluster index %.3f (null mean %.3f); p = %s: the split is %s.",
if (!is.null(SPLIT)) "The given split" else "The best 2-means split", values$ci, m, format(signif(p, 3)), verdict),
statistics = list(list(key = "ci", label = "Cluster index", value = values$ci),
list(key = "p_empirical", label = "p (simulated)", value = p, format = "p"),
list(key = "p_gaussian", label = "p (Gaussian fit)", value = values$p_gaussian, format = "p")),
tables = tables,
values = values,
charts = charts,
warnings = warnings
))
Sources
- Liu Y, Hayes DN, Nobel A, Marron JS (2008). Statistical significance of clustering for high-dimension, low-sample size data. JASA 103:1281–1293.
- Huang H, Liu Y, Yuan M, Marron JS (2015). Statistical significance of clustering using soft thresholding. Journal of Computational and Graphical Statistics 24:975–993.
From the CodeSplash method registry · discover.sigclust v1.0.0.