Skip to content

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.

Verified in Python and R Python and R agree to 6 decimals Seeded Also called SigClust, significance of clustering, statistical significance of clustering…

A real result

Example “One cloud”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Is the split significant? (SigClust)Recorded · Python and R agreeRecorded 2026-11-21 · 13 values compared
R

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

Cluster index under one Gaussian cloudHow unusual is the observed statistic if the null hypothesis were true?

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 valueNull density (normal fit)Observed cluster indexCluster index
0.68381.710e-50.72150.5758
0.68382.273e-50.72150.5774
0.68383.010e-50.72150.5791
0.68383.976e-50.72150.5808
0.68385.235e-50.72150.5824
0.68386.872e-50.72150.5841
0.68388.994e-50.72150.5858
0.68380.00010.72150.5874
0.68380.00020.72150.5891
0.68380.00020.72150.5907
0.68380.00030.72150.5924
0.68380.00030.72150.5941
0.68380.00040.72150.5957
0.68380.00050.72150.5974
0.68380.00070.72150.5991
0.68380.00090.72150.6007
0.68380.00110.72150.6024
0.68380.00140.72150.6041
0.68380.00180.72150.6057
0.68380.00230.72150.6074
0.68380.00280.72150.6090
0.68380.00350.72150.6107
0.68380.00440.72150.6124
0.68380.00550.72150.6140
0.68380.00680.72150.6157
0.68380.00840.72150.6174
0.68380.01040.72150.6190
0.68380.01280.72150.6207
0.68380.01560.72150.6224
0.68380.01910.72150.6240
0.68380.02330.72150.6257
0.68380.02820.72150.6273
0.68380.03420.72150.6290
0.68380.04120.72150.6307
0.68380.04960.72150.6323
0.68380.05950.72150.6340
0.68380.07110.72150.6357
0.68380.08480.72150.6373
0.68380.10080.72150.6390
0.68380.11950.72150.6407
0.68380.14110.72150.6423
0.68380.16620.72150.6440
0.68380.19520.72150.6456
0.68380.22860.72150.6473
0.68380.26680.72150.6490
0.68380.31050.72150.6506
0.68380.36030.72150.6523
0.68380.41680.72150.6540
0.68380.48080.72150.6556
0.68380.55280.72150.6573
0.68380.63370.72150.6590
0.68380.72440.72150.6606
0.68380.82540.72150.6623
0.68380.93780.72150.6640
0.68381.0620.72150.6656
0.68381.2000.72150.6673
0.68381.3510.72150.6689
0.68381.5160.72150.6706
0.68381.6970.72150.6723
0.68381.8930.72150.6739

First 60 of 200 rows.

Covariance eigenvalues: data and null

ComponentDataNull (simulated)
13.4093.409
21.4871.487
31.1581.257
41.1021.257
50.74291.257
Python

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

ComponentDataNull (simulated)
13.4093.409
21.4871.487
31.1581.257
41.1021.257
50.74291.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.
Python

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,
})
R

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.