Selective Inference for Clustering Under Unknown Covariance
Authors: Yiqun T. Chen, Lucy L. Gao
Organizations: Departments of Biostatistics and Computer Science, Johns Hopkins University · Department of Statistics and Actuarial Science, University of Waterloo
Unsupervised clustering is widely used to discover underlying group structure, after which researchers often seek to validate these groups via post-hoc hypothesis testing on the population means. However, using the same data both to form clusters and to test for a difference in means inflates the Type I error rate. Recent work in selective inference has proposed solutions when the underlying data are drawn from a multivariate Gaussian distribution with a known covariance matrix or an unknown isotropic covariance matrix. We propose a new selective test for the difference in means between two clusters that provably controls the Type I error rate under an arbitrary unknown covariance matrix. Our test statistic does not require estimating the feature covariance matrix; instead, it leverages a Monte Carlo sampling procedure over the set of orthogonal matrices. We show that this new selective test can be computed efficiently, and we derive closed-form solutions when clusters are formed using k-means or hierarchical clustering. In simulations, we demonstrate that our proposed p-value controls the selective Type I error rate and achieves substantial power, and we illustrate its application on gene expression and drug review data sets.
Figures & tables
Figure 1: Estimating the covariance trades Type I error control against power. (a) One data set from ( 1 ) with two true groups (shapes), split into K=3 clusters (colors) by k -means, which divides one true group in two. (b) QQ plots of the Uniform (0,1) distribution against the p -values when all observations come from one Gaussian group: the naive test, the test of Chen and Witten (2023) with three choices of covariance ( pCW , Section 5 ), and our proposals ppolar in ( 13 ), ppolar,1d in ( 19 ), and ppolar,1dtraj of Section 4.4 . (c) Conditional power against the separation δ between the true groups, for the tests that control the Type I error in (b).
Figure 2: The split X=P0X+P1X+P2X for n=36 observations from three bivariate Gaussian groups, clustered into K=3 clusters by k -means; open circles are the cluster that is not tested. (a) The data. (b) The three parts: P0X joins the two tested cluster means, P1X covers the deviations within each tested cluster, and P2X covers the untested observations (it also holds the overall mean of the two tested clusters). (c) A data set with P1X and P2X held fixed, as in Gao et al. (2024) : the two tested clusters keep their shapes and move along the line between their means. (d) A data set with P2X and H held fixed, as in our test: the tested observations are redrawn around the same overall mean with the same sample covariance, and the untested observations do not move. The dashed ellipse in (b)–(d) is the 95% ellipse of the sample covariance matrix H2/(r−1) of the tested observations; it is the same in (b) and (d) and smaller in (c).
Figure 3: Two ways to perturb the data, for n=12 observations from one bivariate Gaussian split into K=3 clusters by k -means; open circles are the cluster that is not tested. (a) The perturbation of Gao et al. (2024) and Chen and Witten (2023) slides the two tested clusters apart along ν , so every perturbed data set lies on a line. (b) Our perturbation Q↦Gij(ω)Q for one pair of rows (i,j) , where Gij(ω) rotates rows i and j of Q by the angle ω (Section 4.1 ): each tested observation moves on an ellipse, purple where k -means still returns the tested clusters. (c) The angles ω on the unit circle, purple where k -means returns the tested clusters, with an accepted proposal (filled triangle) and a rejected proposal (open triangle); the observed data are at ω=0 . (d) The data at the accepted angle, colored by the clusters that k -means returns on them. (e) The same at the rejected angle; the ringed observations have changed cluster.
Figure 4: k -means with K=3 . (a) Quantile-quantile plots of the p -values under ( 1 ) with μ=0n×p , stratified by Σ and pooled over n and p . (b) The conditional power ( 29 ) at α=0.05 under ( 1 ) with μ defined in ( 28 ), n=50 , and Σ=Ip , stratified by p , for the tests that control the selective Type I error. (c) The recovery probability ( 30 ) in the same settings.
Figure 5: Average-linkage hierarchical clustering with K=3 and n=200 . (a) Quantile-quantile plots of the p -values under ( 1 ) with μ=0n×p , stratified by Σ and pooled over p . (b) The recovery probability ( 30 ) under ( 1 ) with μ defined in ( 28 ) and Σ=Ip . (c) The conditional power ( 29 ) at α=0.05 in the same settings, stratified by p , for the tests that control the selective Type I error under every Σ ; at each δ the tests are drawn side by side, with 95% Wilson intervals.
Figure 6: The leukemia data of Section 6.1 . Left: a UMAP embedding, colored by cluster, with the known label as the plotting symbol. Right: naive and selective p -values for each pair of clusters. The row Expected is “alternative” when the two clusters have different majority labels and “null” when they share one.
Figure 7: The drug reviews of Section 6.2 . Top: a UMAP embedding of their principal components, colored by cluster, with the condition as the plotting symbol; left, the “alternative” data set; right, the “null” data set. Bottom: naive and selective p -values for each pair of clusters. The column Expected is “alternative” when the two clusters have different majority labels and “null” when they share one. Majority labels: Dep, depression; BC, birth control; BC-, birth control with a rating of 4 or less.
Figure 8: The mouse brain cells of Section 6.3 . Top: a UMAP embedding, colored by cluster, with the known label as the plotting symbol; left, the “alternative” data set; right, the “null” data set. Bottom: naive and selective p -values for each pair of clusters. The column Expected is “alternative” when the two clusters have different majority labels and “null” when they share one. Majority labels: IN, interneurons; CA1, CA1 pyramidal cells; OL, oligodendrocytes. No existing selective inference test applies to Leiden clustering.
Appendix figures & tables12 assets
Supplementary material from the paper’s appendix.
Appendix
Gao et al. (2024)
Yun and Barber (2023)
ppolar,1d
( Σ known)
( Σ=σ2Ip )
(any Σ )
null
( 2 )
( 5 )
( 5 )
nuisance parameters
(P1+P2)μ
means, σ2
means, Σ
removed by fixing
P1X , P2X
P2X , ∥(P0+P1)X∥F
P2X , H
fixed to reach one dimension
dir(Σ−1/2X⊤ν)
dir(P0X) , dir(P1X)
γ , dir(P1q) , Q(Ip−γγ⊤)
random scalar
∥Σ−1/2X⊤ν∥2
R
T2
Appendix
Table A.1: Nuisance parameters and conditioning in three one-dimensional selective tests. Each test conditions on the selection event, on statistics that remove the nuisance parameters under its null, and on further statistics that leave one scalar random.
Figure C.1: Path length changes power but not the Type I error ( n=45 , p=10 , K=3 ). Left: selective Type I error against the path length M on null data, each replicate evaluated at every M . Right: conditional power against M for five separations δ (one curve each).
Figure C.2: The random Givens kernel and the Cayley random walk with M=5,000 and L=2 , on null data with compound-symmetric Σ . (a) Quantile-quantile plots of the p -values against the Uniform (0,1) distribution. (b) Seconds of computing time per p -value. (c) The fraction of steps at which the chain moves.
Method
isotropic
AR(1)
comp. sym.
spiked
pnaive
1.000 [1.000]
1.000 [1.000]
1.000 [1.000]
1.000 [1.000]
ppolar
0.053 [0.064]
0.048 [0.065]
0.049 [0.070]
0.048 [0.064]
ppolar,1d
0.052 [0.067]
0.048 [0.063]
0.054 [0.068]
0.043 [0.068]
ppolar,1dtraj
0.054 [0.073]
0.053 [0.067]
0.048 [0.072]
0.050 [0.060]
ppolar(Σ)
0.050 [0.073]
0.053 [0.073]
0.051 [0.062]
0.049 [0.073]
pCW(σ^MED2I)
0.058 [0.072]
0.103 [0.170]
0.171 [0.693]
0.122 [0.159]
Appendix
Table D.1: Selective Type I error at α=0.05 after k -means, by covariance: median [maximum] over the cells (n,p) of Section 5.1 .
Figure D.1: Selective Type I error at α=0.05 after k -means, by covariance structure, on a square-root scale. Each box summarizes one test over the cells (n,p) , which are drawn as points; the naive test is omitted. The gray band is the 95% Monte Carlo interval for a test of exact level 0.05 .
Figure D.2: Selective Type I error at α=0.05 after k -means for the tests that we propose, stratified by n (rows) and Σ (columns). Each box summarizes one test over the values of p with p≤n/2 , which are drawn as points. The gray band is as in Figure D.1 .
Figure D.3: Conditional power ( 29 ) at α=0.05 after k -means with Σ=Ip , stratified by n (rows) and p (columns), with 95% Wilson intervals.
Figure D.4: As Figure D.3 , at n=100 and 200 .
Figure D.5: As Figure D.3 , at n=30 under the AR(1), compound-symmetric, and spiked covariances (rows), for the tests that control the selective Type I error under them.
Figure D.6: Leiden community detection in the design of Figure 1 . (a) Quantile-quantile plots of the p -values with one true group ( δ=0 ), stratified by p . (b) The conditional power ( 29 ) of ppolar at α=0.05 against δ , with 95% Wilson intervals.
Figure D.7: Selective Type I error at α=0.05 with rows that are not Gaussian (Section 5.3 ), after k -means (left) and average-linkage hierarchical clustering (right), on a square-root scale. Each box summarizes one test over the values of p (and of q for principal components), which are drawn as points. The gray band is as in Figure D.1 . There is no reference ppolar(Σ) for principal components.
Figure D.8: Median seconds for one p -value after k -means at n=200 , on one core, by p . The vertical axis is on a log scale.
Deep clustering is a powerful approach for discovering meaningful structures in high-dimensional data by learning a low-dimensional latent representation prior to clustering. Despite its empirical success, assessing the statistical reliability of the resulting clusters remains challenging. Testing discovered clusters on the same data induces selection bias and invalidates classical p-values. Selective inference (SI) provides a principled framework for correcting this bias, but existing methods focus on clustering performed directly on the observed features. In this work, we develop an SI framework for deep clustering with a fixed pretrained encoder. The key challenge is that cluster assignments are determined through a nonlinear transformation from the original data space to the latent space, resulting in a substantially more complex selection process than in conventional clustering. Our method provides a computationally tractable way to account for this process and enables valid statistical testing of differences between clusters identified in the latent space. Synthetic experiments demonstrate that the proposed method controls the Type I error rate while achieving higher power than valid but conservative baselines, and genomic applications show that it can identify significant cluster differences while appropriately accounting for selection bias. Our framework provides a principled approach to quantifying the statistical reliability of structures discovered by deep clustering.
Eina Mizui, Tomohiro Shiraishi, Shunichi Nishino +1
Selecting the number of clusters remains a fundamental challenge in unsupervised learning. Existing approaches typically focus on identifying a single "optimal" partition, often overlooking statistically meaningful structure present across multiple resolutions. We introduce ElbowSig, a general inferential framework for assessing clustering structure over a range of resolutions. The method formalizes the elbow heuristic by defining a normalized discrete curvature statistic based on the sequence of within-cluster heterogeneity values, and evaluates its significance relative to a null distribution of unstructured data. This yields hypothesis tests across resolutions, enabling simultaneous inference at multiple clustering scales. We derive the asymptotic behavior of the null statistic in both large-sample and high-dimensional regimes, characterizing its limiting form and variability. Because it depends only on the heterogeneity sequence, ElbowSig is compatible with a wide range of clustering algorithms, including hard, fuzzy, and model-based methods. Experiments on synthetic and real datasets show that the procedure controls Type-I error under unstructured data while providing power to detect multiscale organization, revealing structure that is often missed by single-resolution selection criteria.
Francisco J. Perez-Reche
School of Natural and Computing Sciences, University of Aberdeen, Fraser Noble Building, AB24 3UE, United Kingdom
A data analysis pipeline is a structured sequence of steps that transforms raw data into meaningful insights by integrating multiple analysis algorithms. In many practical applications, analytical findings are obtained only after data pass through several data-dependent procedures within such pipelines. In this study, we address the problem of quantifying the statistical reliability of results produced by data analysis pipelines. As a proof of concept, we focus on clustering pipelines that identify cluster structures from complex and heterogeneous data through procedures such as outlier detection, feature selection, and clustering. We propose a novel statistical testing framework to assess the significance of clustering results obtained through these pipelines. Our framework, based on selective inference, enables the systematic construction of valid statistical tests for clustering pipelines composed of predefined components. We prove that the proposed test controls the type I error rate at any nominal level and demonstrate its validity and effectiveness through experiments on synthetic and real datasets.