Manuscript Offprint

arXiv:2610.17458

Selective Inference for Clustering Under Unknown Covariance

Yiqun T. Chen, Lucy L. Gao

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

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.

1 Introduction

In many analyses, the groups that are compared are not fixed in advance but are estimated from the data. Clinical researchers cluster patients on routine measurements to find subgroups that differ in disease course and in who is most likely to benefit from a treatment (Ahlqvist et al., 2018). Marketers segment customers by their purchases to decide whom to target (Wedel and Kamakura, 2000). It is then tempting to apply a classical two-sample test to ask whether the estimated subgroups, or clusters, truly differ. But the hypothesis is generated from the same data that are used to test it, so classical tests no longer control the Type I error rate. This problem has been studied in a recent line of work known as selective inference or post-selection inference (see Neufeld et al., 2026, for a review).

We illustrate the problem with a toy example. Let X∈Rn×p\mathbf{X} \in \mathbb{R}^{n \times p} follow the matrix normal model

X∼MNn×p(μ,In,Σ),(1)\mathbf{X}\sim\mathcal{M N}_{n\times p}(\boldsymbol{\mu},\mathbf{I}_{n},\boldsymbol{\Sigma}), \tag{1}

that is, the rows Xi∼Np(μi,Σ),i=1,…,n\mathbf{X}_i \sim \mathcal{N}_p(\boldsymbol{\mu}_i, \boldsymbol{\Sigma}), i = 1, \ldots, n, are independent, where μi\boldsymbol{\mu}_i is the ith row of μ∈Rn×p\boldsymbol{\mu} \in \mathbb{R}^{n \times p}. In Figure 1(a), half of the observations share one mean, the other half share another, and the two features are correlated. We cluster the data into three groups with kk-means, so the algorithm must split one of the two true groups in two. It does so cleanly by construction, because it chooses the

Figure

(b)

(c)

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=3K = 3 clusters (colors) by kk-means, which divides one true group in two. (b) QQ plots of the Uniform(0, 1) distribution against the pp-values when all observations come from one Gaussian group: the naive test, the test of Chen and Witten (2023) with three choices of covariance (pCWp_{\mathrm{CW}}, Section 5), and our proposals ppolarp_{\mathrm{polar}} in (13), ppolar,1dp_{\mathrm{polar,1d}} in (19), and ppolar,1dtrajp_{\mathrm{polar,1d}}^{\mathrm{traj}} of Section 4.4. (c) Conditional power against the separation δ\delta between the true groups, for the tests that control the Type I error in (b).

partition that maximizes the between-cluster variation. The two halves of the split group therefore have very different sample means, although they have the same population mean. Let C^1\hat{C}_1 and C^2\hat{C}_2 be two of the estimated clusters and write μˉG=∣G∣−1∑i∈Gμi\bar{\mu}_G = |G|^{-1} \sum_{i \in G} \mu_i for the average mean of a set GG of observations. The question is whether

H0:μˉC^1=μˉC^2versusH1:μˉC^1≠μˉC^2.(2)H_{0}:\bar{\mu}_{\hat{\mathcal{C}}_{1}}=\bar{\mu}_{\hat{\mathcal{C}}_{2}}\quad\mathrm{v e r s u s}\quad H_{1}:\bar{\mu}_{\hat{\mathcal{C}}_{1}}\neq\bar{\mu}_{\hat{\mathcal{C}}_{2}}. \tag{2}

For the two halves of a split group this null is true. A textbook two-sample test, such as Hotelling's T2T^{2} referred to its F distribution, nevertheless rejects it almost always (the red line in Figure 1(b)). The F distribution describes the distance between groups that were fixed before the data were seen, not between groups that the data selected. Across the simulation study of Section 5, the naive test rejects the true null in 85% to 100% of replicates (Section 5.1).

Conditional selective inference repairs the reference distribution by conditioning on the selection event. The goal is a p-value p that controls the selective Type I error (Fithian et al., 2014),

PH0(p≤α∣C^1,C^2∈C(X))≤αfor all α∈(0,1).(3)\mathbb{P}_{H_{0}}\big(p\leq\alpha\mid\hat{\mathcal{C}}_{1},\hat{\mathcal{C}}_{2}\in\mathcal{C}(\mathbf{X})\big)\leq\alpha\quad\mathrm{f o r~a l l~}\alpha\in(0,1). \tag{3}

That is, among the data sets on which the clustering returns the tested clusters, a true null hypothesis is rejected at level α\alpha with probability at most α\alpha. We call such a test valid. Let T(X)T(\mathbf{X}) be a test statistic, such as Hotelling's T2T^2 or the distance ∥XˉC^1−XˉC^2∥2\|\bar{\mathbf{X}}_{\hat{C}_1} - \bar{\mathbf{X}}_{\hat{C}_2}\|_2 between the two cluster means. Instead of asking whether T(X)T(\mathbf{X}) is extreme under its unconditional null law, one asks whether it is extreme given that the clustering procedure returned the observed clusters. Gao et al. (2024) formalized this idea. For a known Σ\Sigma in (1), the selective p-value is

psel=PH0(∥Σ−1/2(XˉC^1−XˉC^2)∥2≥∥Σ−1/2(xˉC^1−xˉC^2)∥2∣C^1,C^2∈C(X)),(4)p_{\mathrm{s e l}}=\mathbb{P}_{H_{0}}\Big(\|\mathbf{\Sigma}^{-1/2}(\bar{\mathbf{X}}_{\hat{\mathcal{C}}_{1}}-\bar{\mathbf{X}}_{\hat{\mathcal{C}}_{2}})\|_{2}\geq\|\mathbf{\Sigma}^{-1/2}(\bar{\mathbf{x}}_{\hat{\mathcal{C}}_{1}}-\bar{\mathbf{x}}_{\hat{\mathcal{C}}_{2}})\|_{2}\Big|\hat{\mathcal{C}}_{1},\hat{\mathcal{C}}_{2}\in\mathcal{C}(\mathbf{X})\Big), \tag{4}

where x\mathbf{x} is the observed data, C(X)\mathcal{C}(\mathbf{X}) is the set of clusters obtained from X\mathbf{X}, and ν\nu is the contrast vector with entries 1{i∈C^1}/∣C^1∣−1{i∈C^2}/∣C^2∣\mathbf{1}\{i \in \hat{\mathcal{C}}_1\} / |\hat{\mathcal{C}}_1| - \mathbf{1}\{i \in \hat{\mathcal{C}}_2\} / |\hat{\mathcal{C}}_2|, so that XˉC^1−XˉC^2=X⊤ν\bar{\mathbf{X}}_{\hat{\mathcal{C}}_1} - \bar{\mathbf{X}}_{\hat{\mathcal{C}}_2} = \mathbf{X}^\top \nu. To compute (4), Gao et al. (2024) also condition on statistics that remove the nuisance parameters and on one further direction, which leaves a single scalar with a truncated χ\chi distribution (Section 2.1), and they show that the truncation set can be computed efficiently for hierarchical clustering with commonly used linkages. Chen and Witten (2023) extended this approach to kk-means by conditioning on the full kk-means clustering trajectory of Lloyd's algorithm. That is, they replace the event C^1,C^2∈C(X)\hat{C}_1, \hat{C}_2 \in \mathcal{C}(\mathbf{X}) in (4) with the event that Lloyd's algorithm repeats every observed assignment.

Both approaches require Σ\Sigma in (1) to be known. Section 2 shows that plugging in an estimate of Σ\Sigma trades Type I error control against power (Figure 1(b) and (c)).

In this work, we give an exactly valid selective test after clustering under model (1) with unknown means and an unknown, unstructured covariance Σ≻0\Sigma \succ 0. To avoid estimating Σ\Sigma, we test a stricter null hypothesis than (2),

H0′:μi=μi′for all i,i′∈C^1∪C^2,(5)H_{0}^{\prime}:\boldsymbol{\mu}_{i}=\boldsymbol{\mu}_{i^{\prime}}\quad\mathrm{f o r~a l l~}i,i^{\prime}\in\hat{\mathcal{C}}_{1}\cup\hat{\mathcal{C}}_{2}, \tag{5}

which postulates that all observations in the two clusters share a common mean (Yun and Barber, 2023) (Remark 2.2 explains why the weaker null is not enough without a known covariance).

Our first insight is that if we stack the r=∣C^1∣+∣C^2∣r = |\hat{C}_1| + |\hat{C}_2| rows from C^1\hat{C}_1 and C^2\hat{C}_2 and center them into a matrix Z∈R(r−1)×p\mathbf{Z} \in \mathbb{R}^{(r-1) \times p}, then under (5), Z\mathbf{Z} has independent Np(0,Σ)\mathcal{N}_p(\mathbf{0}, \mathbf{\Sigma}) rows. We then take the polar decomposition Z=QH\mathbf{Z} = \mathbf{Q} \mathbf{H}, where Q\mathbf{Q} is uniformly distributed on the set St(r−1,p)\mathrm{St}(r-1, p), i.e., all (r−1)×p(r-1) \times p matrices with orthonormal columns. Importantly, the distribution of Q\mathbf{Q} does not involve Σ\mathbf{\Sigma} and is independent of H\mathbf{H}, and therefore Q\mathbf{Q} can be used as a pivotal statistic for (5).

In addition to the novel test statistic construction inspired by classical results in multivariate statistics (Chikuse, 2003), we also make algorithmic contributions to conditional selective inference. Most existing selective inference frameworks reduce the computation of the selective p-value to a one-dimensional truncation problem; however, in our case, we need to sample Q truncated to a set. We propose a reversible Markov-chain-based algorithm for sampling and use the serial construction of Besag and Clifford (1989), which makes the Monte Carlo p-value exactly valid for any number of draws. Finally, for k-means clustering, we show that each proposal can be characterized exactly using analytical solutions. Conditioning on more information gives a simpler alternative: fixing all of Q except the angle that determines Hotelling's T2T^{2} yields a one-dimensional truncated p-value ppolar,1dp_{\text{polar},1d}, which is exact, needs only a one-dimensional Monte Carlo sample for a general clustering algorithm, and needs none for k-means when we condition on the Lloyd trajectory (Sections 3.4 and 4.4). Tests based on our proposal ppolarp_{\text{polar}} control the selective Type I error (3) in finite samples without any knowledge of Σ\Sigma (Figure 1(b)). In Figure 1(c) they even have at least as much power as the test of Chen and Witten (2023) with the true Σ\Sigma, because that test conditions on the whole sequence of k-means assignments and ours only on the returned clusters.

The methods are implemented in the R package selectiveHotelling, available at https://github.com/yiqunchen/selectiveHotelling, and its tutorials are at https://yiqunchen.github.io/selectiveHotelling/. The code that reproduces our results is at https://github.com/yiqunchen/selectiveHotelling-paper.

References (100)

  • A data-driven cluster analysis of six variables
  • A flexible and robust non-parametric test of exchangeability (opens arXiv in a new tab)
  • Selective inference after convex clustering with $\ell_{1}$ penalization
  • Statistical guarantees for the EM algorithm: From population to sample-based analysis
  • Hit-and-run algorithms for generating multivariate distributions
  • Generalized Monte Carlo significance tests
  • Finite mixture models do not reliably learn the number of components
  • Estimating structured high-dimensional covariance and precision matrices: Optimal rates and adaptive estimation
  • CHIME: Clustering of high-dimensional Gaussian mixtures with EM algorithm and its optimality
  • Testing for a finite mixture model with two components
  • Hypothesis test for normal mixture models: The EM approach
  • More powerful selective inference for the graph fused lasso
  • Selective inference for k-means clustering
  • Statistical significance of variables driving systematic variation in high-dimensional data
  • Generalized data thinning using sufficient statistics
  • Decomposing Gaussians with unknown covariance
  • Comparison of discrimination methods for the classification of tumors using gene expression data
  • An overview of the estimation of large covariance and precision matrices
  • Optimal inference after model selection (opens arXiv in a new tab)
  • Selective inference for hierarchical clustering
  • Matrix Computations
  • Molecular classification of cancer: Class discovery and class prediction by gene expression monitoring
  • Post-clustering inference under dependence (opens arXiv in a new tab)
  • Aspect-based sentiment analysis of drug reviews applying cross-domain and cross-data learning (opens the publisher in a new tab)
  • On posterior contraction of parameters and interpretability in Bayesian mixture modeling
  • M. Howes. Markov chain Monte Carlo significance tests. arXiv:2310.04924, 2023. (opens arXiv in a new tab)
  • Testing for a change in mean after changepoint detection
  • Influential features PCA for high dimensional clustering
  • Bootstrapping cluster analysis: Assessing the reliability of conclusions from microarray experiments
  • Statistical significance for hierarchical clustering
  • More powerful conditional selective inference for generalized lasso by parametric programming
  • Analytical nonlinear shrinkage of large-dimensional covariance matrices
  • Exact post-selection inference, with application to the lasso
  • Testing Statistical Hypotheses
  • Data fission: Splitting a single data point
  • Testing the order of a finite mixture
  • UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction
  • Finite mixture models
  • Statistical testing framework for clustering pipelines by selective inference (opens arXiv in a new tab)
  • Selective inference for deep clustering in latent spaces (opens arXiv in a new tab)
  • Data thinning for convolution-closed distributions
  • Inference after latent variable estimation for single-cell RNA sequencing data
  • Inference conditional on selection: A review (opens arXiv in a new tab)
  • The L-test: Increasing the linear model F-test's power under sparsity without sacrificing validity (opens arXiv in a new tab)
  • Splitting strategies for post-selection inference
  • The $\ell$-test: Leveraging sparsity in the Gaussian linear model for improved inference (opens arXiv in a new tab)
  • Pvclust: An R package for assessing the uncertainty in hierarchical clustering
  • From Louvain to Leiden: guaranteeing well-connected communities (opens the publisher in a new tab)
  • High dimensional EM algorithm: Statistical optimization and asymptotic normality
  • Market Segmentation: Conceptual and Methodological Foundations
  • A feasible method for optimization with orthogonality constraints
  • Regularized EM algorithms: A unified framework and statistical guarantees
  • Selective inference for multiple pairs of clusters after K-means clustering (opens arXiv in a new tab)
  • Y.-J. Yun and R. F. Barber. Selective inference for clustering with unknown variance. Electronic Journal of Statistics, 17(2):1923–1946, 2023. doi: 10.1214/23-EJS2143. (opens the publisher in a new tab)
  • Cell types in the mouse cortex and hippocampus revealed by single-cell RNA-seq (opens the publisher in a new tab)
  • Appendix B uses the same notation
  • Fix a matrix $\mathbf{A} \in \mathbb{R}^{n \times (r-1)}$ whose columns are an orthonormal basis of the range of $\mathbf{P}_0 + \mathbf{P}_1$, so that
  • Every matrix in $\mathcal{V}$ is $\mathbf{A}$ times a matrix in $\text{St}(r-1, p)$, and multiplying by $\mathbf{A}$ preserves inner products, so we identify the polar factor with its coordinates $\mathbf{A}^\top \mathbf{Q} \in \text{St}(r-1, p)$ and write $\mathbf{Q}$ for both
  • So (OQ, H) has the same distribution as (Q, H), and
  • This gives (31)
  • Then $\mathbf{Q}^\top \mathbf{a}$ consists of the first p entries of the vector $\mathbf{O}^\top \mathbf{a}$
  • The statement for $T^2$ follows from (12), because $\frac{r-p-1}{(r-2)p}T^2 = \frac{r-1-p}{p} \cdot \frac{U}{V}$ is a ratio of independent $\chi^2$ variables divided by their degrees of freedom
  • 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
  • We write S for the set of polar factors that the test conditions on $(\mathcal{S}_{\mathbf{Q}} \text{ or } \mathcal{S}_{\mathbf{Q},\tau})$
  • Writing $\boldsymbol{\alpha}_i^\top$ for the ith row of $\mathbf{A}$, which is zero for observations outside $\hat{\mathcal{C}}_1 \cup \hat{\mathcal{C}}_2$, and $\mathbf{b}_i^\top$ for the ith row of $\mathbf{P}_2\mathbf{x}$, each observation is an affine function of $\mathbf{Q}$
  • With these assignments held fixed, each centroid is a fixed average of the rows (36), so it is also affine in $\mathbf{Q}$:
  • Each $S_{Q,\tau'}$ is an intersection of quadratic sets, so $S_Q$ is a union of intersections of quadratic sets
  • Fix the current $\mathbf{Q} \in \mathcal{S}_{\mathbf{Q}, \tau}$ and a pair of rows $i < j$
  • and $Q_{i}$, all other rows being zero
  • The difference of the two squared norms is
  • The substitution misses only $\omega = \pi$, where $s = \tan(\omega/2)$ is infinite
  • Take all the zeros of all the constraints together and sort them by increasing angle in $[0,2\pi)$
  • Second, the feasible set can be read off from the zeros of the remaining constraints
  • The proof does not use the quadratic form of S; it holds for any set S with $\int \mathbf{1}_S(\mathbf{Q}) \, d\mathbf{Q} > 0$
  • A power of a reversible kernel is reversible too, so $\mathcal{K}^L$ is
  • We first describe all polar factors with the same coordinates $\Gamma$ (Proposition B.2), then show that $u(\mathbf{Q})$ is independent of $\Gamma$, and finally condition on the clustering
  • Hence the polar factors with the same $\Gamma$ as $\mathbf{Q}$ form the curve
  • Finally, $\mathbf{B}^\top \mathbf{B} = (\mathbf{I}_p - \gamma \gamma^\top) \mathbf{Q}^\top \mathbf{Q}(\mathbf{I}_p - \gamma \gamma^\top) = \mathbf{I}_p - \gamma \gamma^\top$
  • The vector $\mathbf{q}_u$ has length one, because $\mathbf{a}$ and $\mathbf{w}$ are orthogonal unit vectors, and $\mathbf{B}^\top \mathbf{q}_u = \mathbf{0}$
  • By Theorem 3.1, $\mathbf{Q}$ is independent of ( $\mathbf{H}$, $\mathbf{P}_2\mathbf{X}$), and by the independence just proved, $u$ is independent of $\Gamma$
  • Two facts make such kernels reversible with respect to the uniform distribution on S; we state them in the coordinates of this appendix
  • Their sum is the kernel
  • Neither proposition covers a step size tuned on trial moves from $\mathbf{Q}_{\mathrm{obs}}$ (Section 4.2)
  • So $\hat{p}_{\text{polar}}$ is uniform given the path, even when all values are tied
  • Appendix C.1 gives the algorithm for the one-dimensional test, Appendix C.2 explains why a naive Markov chain estimator is not a valid p-value, Appendix C.3 shows how the path length, the number of steps between points of the path, and the step size affect the test, and Appendix C.4 compares kernels
  • It follows Algorithm 1, with the angle $\phi$ in place of the polar factor and a Metropolis step for the density (23) in place of the random Givens kernel
  • Its target distribution, the uniform distribution on $S_{Q}$, is the right conditional reference, but drawing useful Monte Carlo samples from that target is hard unless the proposal is designed around the geometry of the selection event
  • The Besag–Clifford p-value of Section 4.2 does not need mixing: it is exact for any reversible kernel and any path length (Proposition 4.2), and better kernels and longer paths only add power
  • Take the two-point space $\{0,1\}$ with the uniform distribution, $u(x) = x$, and the kernel that always moves to the other point, which is reversible
  • 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 $\delta$ (one curve each)
  • All four kernels are exact by Proposition 4.2, and on a toy problem where $Q_{obs}$ is drawn uniformly from a known set, both the Givens and the Cayley kernels gave rejection rates of 0.050 (Givens) and 0.053 (Cayley) over 2,000 replicates, so we attribute the spread above to Monte Carlo error
  • Both kernels control the selective Type I error (Figure C.2(a)), and both reject $H_0$ for 98% to 100% of the pairs of true clusters at the separations we ran
  • It also gives the results for Leiden community detection, the rows of Section 5.3 that are not Gaussian, and the computing time of each test
  • (a) Quantile-quantile plots of the p-values against the Uniform(0, 1) distribution
  • Two comparators appear only here
  • median [maximum] over the cells $(n, p)$ of Section 5.1
  • Figure D.6(a) shows that the null $p$-values of $p_{\text{polar}}$ are uniform, with selective Type I error 0.043 at $p = 2$ and 0.051 at $p = 5$, and Figure D.6(b) shows that its conditional power is 0.99 at $\delta = 4$ for both dimensions
  • Each box summarizes one test over the cells $(n, p)$, which are drawn as points; the naive test is omitted
  • Each box summarizes one test over the values of $p$ with $p \leq n/2$, which are drawn as points
  • Each box summarizes one test over the values of $p$ (and of $q$ for principal components), which are drawn as points

Couldn't load all references. Reload the page to try again.