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 [1 ] . 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 [51 ] , for a review).
We illustrate the problem with a toy example. Let X ∈ R n × p \mathbf{X} \in\mathbb{R}^{n\times p} X ∈ R n × p follow the matrix normal model
X ∼ M N n × p ( μ , I n , Σ ) , (1) \mathbf{X} \sim\mathcal{MN}_{n\times p}(\boldsymbol{\mu}, \mathbf{I}_n, \boldsymbol{\Sigma}), \tag*{(1)} X ∼ M N n × p ( μ , I n , Σ ) , (1)
that is, the rows X i ∼ N p ( μ i , Σ ) \mathbf{X}_i \sim\mathcal{N}_p(\boldsymbol{\mu}_i,\boldsymbol{\Sigma}) X i ∼ N p ( μ i , Σ ) , i = 1 , … , n i=1,\ldots,n i = 1 , … , n , are independent, where μ i \boldsymbol{\mu}_i μ i is the i i i th row of μ ∈ R n × p \boldsymbol{\mu} \in\mathbb{R}^{n\times p} μ ∈ R n × 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 k k k -means, so the algorithm must split one of the two true groups in two. It does so cleanly by construction, because it chooses the 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 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 be two of the estimated clusters and write μ ˉ G = ∣ G ∣ − 1 ∑ i ∈ G μ i \bar{\boldsymbol{\mu}}_G = |G|^{-1}\sum_{i\in G}\boldsymbol{\mu}_i μ ˉ G = ∣ G ∣ − 1 ∑ i ∈ G μ i for the average mean of a set G G G of observations. The question is whether
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 K = 3 K = 3 clusters (colors) by k k k -means, which divides one true group in two. (b) QQ plots of the Uniform( 0 , 1 ) (0, 1) ( 0 , 1 ) distribution against the p p p -values when all observations come from one Gaussian group: the naive test, the test of Chen and Witten [14 ] with three choices of covariance (p C W p_{\mathrm{CW}} p CW , Section 5), and our proposals p p o l a r p_{\mathrm{polar}} p polar in (13), p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d in (19), and p p o l a r , 1 d t r a j p_{\mathrm{polar,1d}^{\mathrm{traj}}} p polar , 1d 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).
H 0 : μ ˉ C ^ 1 = μ ˉ C ^ 2 versus H 1 : μ ˉ C ^ 1 ≠ μ ˉ C ^ 2 . (2) H_0 : \bar{\boldsymbol{\mu}}_{\widehat{C}_1} = \bar{\boldsymbol{\mu}}_{\widehat{C}_2}
\quad\text{versus}\quad
H_1 : \bar{\boldsymbol{\mu}}_{\widehat{C}_1} \ne\bar{\boldsymbol{\mu}}_{\widehat{C}_2}. \tag*{(2)} H 0 : μ ˉ C 1 = μ ˉ C 2 versus H 1 : μ ˉ C 1 = μ ˉ C 2 . (2)
For the two halves of a split group this null is true. A textbook two-sample test, such as Hotelling’s T 2 T^2 T 2 referred to its F F F distribution, nevertheless rejects it almost always (the red line in Figure 1 (b)). The F F 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 p p -value p p p that controls the selective Type I error (Fithian et al., [23 ] ),
P H 0 ( p ≤ α | C ^ 1 , C ^ 2 ∈ C ( X ) ) ≤ α for all α ∈ ( 0 , 1 ) . (3) \mathbb{P}_{H_0}\left(p \le\alpha\,\middle|\, \widehat{C}_1,\widehat{C}_2 \in\mathcal{C}(\mathbf{X})\right) \le\alpha
\quad\text{for all }\alpha\in(0,1). \tag*{(3)} P H 0 ( p ≤ α C 1 , C 2 ∈ C ( X ) ) ≤ α for all α ∈ ( 0 , 1 ) . (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}) T ( X ) be a test statistic, such as Hotelling’s T 2 T^2 T 2 or the distance ∥ X ˉ C ^ 1 − X ˉ C ^ 2 ∥ 2 \lVert\bar{\mathbf{X}}_{\widehat{C}_1} - \bar{\mathbf{X}}_{\widehat{C}_2}\rVert_2 ∥ X ˉ C 1 − X ˉ C 2 ∥ 2 between the two cluster means. Instead of asking whether T ( X ) T(\mathbf{X}) T ( 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. [24 ] formalized this idea. For a known Σ \boldsymbol{\Sigma} Σ in (1), the selective p p p -value is
p s e l = P H 0 ( ∥ Σ − 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{sel}} = \mathbb{P}_{H_0}\left(\left\lVert\boldsymbol{\Sigma}^{-1/2}(\bar{\mathbf{X}}_{\widehat{C}_1} - \bar{\mathbf{X}}_{\widehat{C}_2})\right\rVert_2 \ge\left\lVert\boldsymbol{\Sigma}^{-1/2}(\bar{\mathbf{x}}_{\widehat{C}_1} - \bar{\mathbf{x}}_{\widehat{C}_2})\right\rVert_2 \,\middle|\, \widehat{C}_1,\widehat{C}_2 \in\mathcal{C}(\mathbf{X})\right), \tag*{(4)} p sel = P H 0 ( Σ − 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)
where x \mathbf{x} x is the observed data, C ( X ) \mathcal{C}(\mathbf{X}) C ( X ) is the set of clusters obtained from X \mathbf{X} X , and ν \boldsymbol{\nu} ν is the contrast vector with entries 1 { i ∈ C ^ 1 } / ∣ C ^ 1 ∣ − 1 { i ∈ C ^ 2 } / ∣ C ^ 2 ∣ 1\{i \in\widehat{C}_1\}/|\widehat{C}_1| - 1\{i \in\widehat{C}_2\}/|\widehat{C}_2| 1 { i ∈ C 1 } /∣ C 1 ∣ − 1 { i ∈ C 2 } /∣ C 2 ∣ , so that X ˉ C ^ 1 − X ˉ C ^ 2 = X T ν \bar{\mathbf{X}}_{\widehat{C}_1} - \bar{\mathbf{X}}_{\widehat{C}_2} = \mathbf{X}^{\mathsf{T}}\boldsymbol{\nu} X ˉ C 1 − X ˉ C 2 = X T ν . 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 (§ 2.1 ), and they show that the truncation set can be computed efficiently for hierarchical clustering with commonly used linkages. Chen and Witten [14 ] extended this approach to k k k -means by conditioning on the full k k k -means clustering trajectory of Lloyd’s algorithm. That is, they replace the event C ^ 1 , C ^ 2 ∈ C ( X ) \widehat{C}_1, \widehat{C}_2 \in\mathcal{C}(X) C 1 , C 2 ∈ C ( X ) in (4) with the event that Lloyd’s algorithm repeats every observed assignment.
Both approaches require Σ \boldsymbol{\Sigma} Σ in (1) to be known. § 2 shows that plugging in an estimate of Σ \boldsymbol{\Sigma} Σ trades Type I error control against power (Figure 1 (b) and (Figure 1 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 \boldsymbol{\Sigma} \succ0 Σ ≻ 0 . To avoid estimating Σ \boldsymbol{\Sigma} Σ , we test a stricter null hypothesis than (2) ,
H 0 ′ : μ i = μ i ′ for all i , i ′ ∈ C ^ 1 ∪ C ^ 2 , (5) H_0^\prime: \boldsymbol{\mu}_i = \boldsymbol{\mu}_{i^\prime} \quad\text{for all } i,i^\prime\in\widehat{C}_1 \cup\widehat{C}_2, \tag*{(5)} H 0 ′ : μ i = μ i ′ for all i , i ′ ∈ C 1 ∪ C 2 , (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 = \lvert\widehat{C}_1\rvert+ \lvert\widehat{C}_2\rvert r = ∣ C 1 ∣ + ∣ C 2 ∣ rows from C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 and center them into a matrix Z ∈ R ( r − 1 ) × p \boldsymbol{Z} \in\mathbb{R}^{(r-1)\times p} Z ∈ R ( r − 1 ) × p , then under (5) , Z \boldsymbol{Z} Z has independent N p ( 0 , Σ ) \mathcal{N}_p(0,\boldsymbol{\Sigma}) N p ( 0 , Σ ) rows. We then take the polar decomposition Z = Q H \boldsymbol{Z} = \boldsymbol{Q}\boldsymbol{H} Z = Q H , where Q \boldsymbol{Q} Q is uniformly distributed on the set St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) , i.e., all ( r − 1 ) × p (r-1)\times p ( r − 1 ) × p matrices with orthonormal columns. Importantly, the distribution of Q \boldsymbol{Q} Q does not involve Σ \boldsymbol{\Sigma} Σ and is independent of H \boldsymbol{H} H , and therefore Q \boldsymbol{Q} 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, [15 ] ), we also make algorithmic contributions to conditional selective inference. Most existing selective inference frameworks reduce the computation of the selective p p p -value to a one-dimensional truncation problem; however, in our case, we need to sample Q \boldsymbol{Q} Q truncated to a set. We propose a reversible Markov-chain-based algorithm for sampling and use the serial construction of Besag and Clifford [7 ] , which makes the Monte Carlo p p p -value exactly valid for any number of draws. Finally, for k k 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 \boldsymbol{Q} Q except the angle that determines Hotelling’s T 2 T^2 T 2 yields a one-dimensional truncated p p p -value p p o l a r , 1 d p_{\mathrm{polar},1\mathrm{d}} p polar , 1 d , which is exact, needs only a one-dimensional Monte Carlo sample for a general clustering algorithm, and needs none for k k k -means when we condition on the Lloyd trajectory (§ 3.4 and § 4.4 ). Tests based on our proposal p p o l a r p_{\mathrm{polar}} p polar control the selective Type I error (3) in finite samples without any knowledge of Σ \boldsymbol{\Sigma} Σ (Figure 1 (b)). In Figure 1 (c) they even have at least as much power as the test of Chen and Witten [14 ] with the true Σ \boldsymbol{\Sigma} Σ , because that test conditions on the whole sequence of k k 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.
Related work
The methodological origin of this work, and the argument behind its validity, go back to the general framework for conditional selective inference of Lee et al. [38 ] and Fithian et al. [23 ] . Beyond the three works above, selective inference for clustering has been extended to testing several pairs of clusters at once (Yun and He, 2024) and to dependent observations (González-Delgado et al., [27 ] ). It has also been extended to other procedures: convex clustering (Bachoc et al., [4 ] ), deep clustering in a learned latent space (Mizui et al., [45 ] ), and multi-step clustering pipelines (Miyata et al., 2026). All of these works either assume a known covariance or plug in an estimate computed about the sample mean. Such an estimate is conservative when the true means differ, because the between-cluster spread inflates it [24 , 27 ] .
One way to extend the conditional framework to an unknown covariance is to plug in an estimate of it. González-Delgado et al. [27 ] show that plugging the sample covariance into the tests of Gao et al. [24 ] and Chen and Witten (2023) gives an asymptotically conservative test that controls the selective Type I error, because the sample covariance overestimates Σ \boldsymbol{\Sigma} Σ asymptotically. The guarantee, however, needs the estimate to come from data independent of the clustered sample, such as an independent copy. It also needs at least two well-separated true clusters. Moreover, when there is a true clustering structure, i.e., when the μ i \boldsymbol{\mu}_i μ i are not all equal, the sample covariance can lead to a substantial loss of power (Figure 1 (c)). An estimator that is universally consistent for Σ \boldsymbol{\Sigma} Σ without knowledge of μ \boldsymbol{\mu} μ is a hard problem and remains an active area of research, especially when p p p is close to n n n [9 , 22 , 37 ] .
Another line of work avoids conditioning by adding auxiliary randomness. It splits one data set into two independent parts, one to choose the hypothesis and the other to test it [54 ] . Data fission [40 ] and data thinning [49 , 18 , 50 ] construct such a split systematically for a single realization from many parametric families, including the multivariate Gaussian with unknown mean but known Σ \boldsymbol{\Sigma} Σ . Without Σ \boldsymbol{\Sigma} Σ , Dharamshi et al. [19 ] prove that a single multivariate Gaussian cannot be split into independent parts. With n > 1 n > 1 n > 1 observations they do construct independent parts, but these mix the rows of X \mathbf{X} X , so an observation clustered in one part has no counterpart to test in the other. We refer to Neufeld et al. [51 ] for a comparison of the conditioning and splitting approaches.
Clustering has also been studied from angles other than testing a selected pair. One question is how many clusters there are, addressed by tests for the order of a finite mixture [11 , 12 , 41 ] , by permutation methods for the number of factors [20 ] , and by the mixture-model literature reviewed in McLachlan et al. [43 ] . Another is whether a cluster, or the variables that drive it, are reproducible, assessed by resampling [34 , 57 ] , by significance tests for hierarchical clustering and for cluster membership [35 , 16 ] , and by related tests of systematic variation and exchangeability [17 , 33 ] (Aw et al. 2021). Bayesian work studies the posterior of the number of components and of the mixture parameters [52 , 29 , 8 ] , and since k k k -means is a limiting case of the expectation-maximization algorithm, statistical guarantees for that algorithm are also relevant [5 , 10 ] (Wang et al. 2015; Yi and Caramanis 2015). Many of these results rely on a consistent estimate of the cluster memberships, or at least on the correct number of clusters. By contrast, we follow the conditional selective inference framework and give a test that is valid whether or not the estimated clusters correspond to true ones.
Notation and organization
The data are X ∈ R n × p \mathbf{X} \in\mathbb{R}^{n \times p} X ∈ R n × p with rows X 1 , … , X n \mathbf{X}_1,\ldots,\mathbf{X}_n X 1 , … , X n , and x \mathbf{x} x denotes a realization of X \mathbf{X} X ; for any matrix, the subscript i i i denotes its i i i th row, and ∥ ⋅ ∥ F \lVert\cdot\rVert_F ∥ ⋅ ∥ F is the Frobenius norm. We write M N n × p ( μ , U , V ) \mathcal{MN}_{n \times p}(\boldsymbol{\mu},\mathbf{U},\mathbf{V}) M N n × p ( μ , U , V ) for the matrix normal distribution with mean μ \boldsymbol{\mu} μ , row covariance U \mathbf{U} U , and column covariance V \mathbf{V} V ; 1 k \mathbf{1}_k 1 k , I k \mathbf{I}_k I k , and 0 \mathbf{0} 0 for the k k k -vector of ones, the k × k k \times k k × k identity, and a zero vector or matrix; dir ( ⋅ ) \operatorname{dir}(\cdot) dir ( ⋅ ) for a nonzero vector or matrix divided by its ℓ 2 \ell_2 ℓ 2 or Frobenius norm; and 1 { ⋅ } \mathbf{1}\{\cdot\} 1 { ⋅ } for the indicator function. The clustering rule applied to x \mathbf{x} x returns the partition C ( x ) = { C ^ 1 , … , C ^ K } \mathcal{C}(\mathbf{x}) = \{\widehat{C}_1,\ldots,\widehat{C}_K\} C ( x ) = { C 1 , … , C K } of { 1 , … , n } \{1,\ldots,n\} { 1 , … , n } . Finally, St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) is the set of ( r − 1 ) × p (r-1) \times p ( r − 1 ) × p matrices with orthonormal columns.
The remainder of the paper is organized as follows. Section 2 reviews the test of Gao et al. [24 ] for a known covariance, shows why estimating the covariance trades Type I error control against power, and writes the test of Yun and Barber (2023) as a polar decomposition of the centered tested rows. Section 3 replaces that decomposition by the matrix polar decomposition, writes Hotelling’s T 2 T^2 T 2 as an angle, and gives two exact tests for any clustering algorithm: the one-dimensional test p p o l a r , 1 d p_{\mathrm{polar},1\mathrm{d}} p polar , 1 d and the test p p o l a r p_{\mathrm{polar}} p polar . Section 4 computes both for any clustering algorithm by combining a Markov chain with the construction of Besag and Clifford [7 ] , and then discusses closed forms for k k k -means and hierarchical clustering. Section 5 reports the simulation study, including the comparison with plug-in covariance estimates and data thinning, and Section 6 applies the test to leukemia, single-cell RNA sequencing, and drug review data. Section 7 concludes, and proofs and additional results are in the appendices.
Testing for a difference in means between two estimated clusters
This section reviews selective inference for clustering when the covariance is known (§ 2.1 ) and explains why estimating the covariance does not work (§ 2.2 ). We then end with the intuition behind our approach (§ 2.3 ).
Throughout, we work under data model (1) .
Selective inference for clustering with a known covariance
We first review the test of Gao et al. [24 ] in the setting where Σ \boldsymbol{\Sigma} Σ in (1) is known. If the clusters C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 had been chosen before the data were seen, we would test (2) with the difference in sample means X T ν = X ‾ C ^ 1 − X ‾ C ^ 2 \mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}=\overline{\mathbf{X}}_{\widehat{C}_1}-\overline{\mathbf{X}}_{\widehat{C}_2} X T ν = X C 1 − X C 2 , where ν \boldsymbol{\nu} ν is the contrast vector defined in § 1 . Under (2) , X T ν ∼ N p ( 0 , ∥ ν ∥ 2 2 Σ ) \mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}\sim N_p(0,\lVert\boldsymbol{\nu}\rVert_2^2\boldsymbol{\Sigma}) X T ν ∼ N p ( 0 , ∥ ν ∥ 2 2 Σ ) , so the whitened norm ∥ Σ − 1 / 2 X T ν ∥ 2 \lVert\boldsymbol{\Sigma}^{-1/2}\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}\rVert_2 ∥ Σ − 1/2 X T ν ∥ 2 follows the scaled distribution ∥ ν ∥ 2 ⋅ χ p \lVert\boldsymbol{\nu}\rVert_2\cdot\chi_p ∥ ν ∥ 2 ⋅ χ p .
Because the clusters were chosen from the data, this is not the right null distribution, and the selective p p p -value p s e l p_{\mathrm{sel}} p sel in (4) conditions on the event that the clustering returns C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 . That probability still depends on the unknown means. It helps to split the data with three projections that we use throughout the paper, X = P 0 X + P 1 X + P 2 X \mathbf{X}=\mathbf{P}_0\mathbf{X}+\mathbf{P}_1\mathbf{X}+\mathbf{P}_2\mathbf{X} X = P 0 X + P 1 X + P 2 X . Here P 0 = ν ν T / ∥ ν ∥ 2 2 \mathbf{P}_0=\boldsymbol{\nu}\boldsymbol{\nu}^{\mathsf{T}}/\lVert\boldsymbol{\nu}\rVert_2^2 P 0 = ν ν T / ∥ ν ∥ 2 2 projects onto the difference of the two cluster means; P 1 = ( I C ^ 1 − 1 C ^ 1 1 C ^ 1 T / ∣ C ^ 1 ∣ ) + ( I C ^ 2 − 1 C ^ 2 1 C ^ 2 T / ∣ C ^ 2 ∣ ) \mathbf{P}_1=(\mathbf{I}_{\widehat{C}_1}-\mathbf{1}_{\widehat{C}_1}\mathbf{1}_{\widehat{C}_1}^{\mathsf{T}}/|\widehat{C}_1|)+(\mathbf{I}_{\widehat{C}_2}-\mathbf{1}_{\widehat{C}_2}\mathbf{1}_{\widehat{C}_2}^{\mathsf{T}}/|\widehat{C}_2|) P 1 = ( I C 1 − 1 C 1 1 C 1 T /∣ C 1 ∣ ) + ( I C 2 − 1 C 2 1 C 2 T /∣ C 2 ∣ ) projects onto the deviations of each observation from the mean of its own cluster, with I G \mathbf{I}_G I G the diagonal matrix with ones in the positions of G G G and 1 G \mathbf{1}_G 1 G the indicator vector of G G G ; and P 2 = I n − P 0 − P 1 \mathbf{P}_2=\mathbf{I}_n-\mathbf{P}_0-\mathbf{P}_1 P 2 = I n − P 0 − P 1 projects onto the rest, namely the overall mean of C ^ 1 ∪ C ^ 2 \widehat{C}_1\cup\widehat{C}_2 C 1 ∪ C 2 and the observations outside the two clusters. In words, P 0 X \mathbf{P}_0\mathbf{X} P 0 X is the variation between the two tested clusters, P 1 X \mathbf{P}_1\mathbf{X} P 1 X the variation within them, and P 2 X \mathbf{P}_2\mathbf{X} P 2 X everything else; Figure 2 (a) shows a clustering and Figure 2 (b) its three parts. We write every test in this paper, theirs and ours, in terms of this split, so that the tests differ only in which parts they hold fixed and which part they let vary. Gao et al. [24 ] decompose the data into the part along ν \boldsymbol{\nu} ν and the part orthogonal to it,
Figure 2. The split X = P 0 X + P 1 X + P 2 X \mathbf{X} = \mathbf{P}_0\mathbf{X} + \mathbf{P}_1\mathbf{X} + \mathbf{P}_2\mathbf{X} X = P 0 X + P 1 X + P 2 X for n = 36 n = 36 n = 36 observations from three bivariate Gaussian groups, clustered into K = 3 K = 3 K = 3 clusters by k k k -means; open circles are the cluster that is not tested. (a) The data. (b) The three parts: P 0 X \mathbf{P}_0\mathbf{X} P 0 X joins the two tested cluster means, P 1 X \mathbf{P}_1\mathbf{X} P 1 X covers the deviations within each tested cluster, and P 2 X \mathbf{P}_2\mathbf{X} P 2 X covers the untested observations (it also holds the overall mean of the two tested clusters). (c) A data set with P 1 X \mathbf{P}_1\mathbf{X} P 1 X and P 2 X \mathbf{P}_2\mathbf{X} P 2 X held fixed, as in Gao et al. [24 ] : the two tested clusters keep their shapes and move along the line between their means. (d) A data set with P 2 X \mathbf{P}_2\mathbf{X} P 2 X and H \mathbf{H} 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 H 2 / ( r − 1 ) \mathbf{H}^2/(r - 1) H 2 / ( r − 1 ) of the tested observations; it is the same in (b) and (d) and smaller in (c).
X = P 1 X + P 2 X + ∥ Σ − 1 / 2 X T ν ∥ 2 ∥ ν ∥ 2 ν dir ( Σ − 1 / 2 X T ν ) Σ 1 / 2 , \mathbf{X}=\mathbf{P}_1\mathbf{X}+\mathbf{P}_2\mathbf{X}+\frac{\lVert\boldsymbol{\Sigma}^{-1/2}\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}\rVert_2}{\lVert\boldsymbol{\nu}\rVert_2}\boldsymbol{\nu}\,\operatorname{dir}\left(\boldsymbol{\Sigma}^{-1/2}\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}\right)\boldsymbol{\Sigma}^{1/2}, X = P 1 X + P 2 X + ∥ ν ∥ 2 ∥ Σ − 1/2 X T ν ∥ 2 ν dir ( Σ − 1/2 X T ν ) Σ 1/2 ,
where the last term is P 0 X \mathbf{P}_0\mathbf{X} P 0 X and P 1 + P 2 = I n − P 0 \mathbf{P}_1+\mathbf{P}_2=\mathbf{I}_n-\mathbf{P}_0 P 1 + P 2 = I n − P 0 is the projection orthogonal to ν \boldsymbol{\nu} ν . They compute instead
\begin{aligned}
p_{\boldsymbol{\Sigma}}&=\mathbb{P}_{H_0}\left(\lVert\boldsymbol{\Sigma}^{-1/2}\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}\rVert_2\geq\lVert\boldsymbol{\Sigma}^{-1/2}\mathbf{x}^{\mathsf{T}}\boldsymbol{\nu}\rVert_2\mid\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X}),\\
&\qquad\mathbf{P}_1\mathbf{X}=\mathbf{P}_1\mathbf{x},\ \mathbf{P}_2\mathbf{X}=\mathbf{P}_2\mathbf{x},\ \operatorname{dir}(\boldsymbol{\Sigma}^{-1/2}\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu})=\operatorname{dir}(\boldsymbol{\Sigma}^{-1/2}\mathbf{x}^{\mathsf{T}}\boldsymbol{\nu})\right). \tag*{(6)}
\end{aligned}
The conditions on P 1 X \mathbf{P}_1\mathbf{X} P 1 X and P 2 X \mathbf{P}_2\mathbf{X} P 2 X remove the unknown means ( P 1 + P 2 ) μ (\mathbf{P}_1 + \mathbf{P}_2)\boldsymbol{\mu} ( P 1 + P 2 ) μ , which are nuisance parameters under H 0 H_0 H 0 , and the condition on dir ( ⋅ ) \operatorname{dir}(\cdot) dir ( ⋅ ) is additional conditioning used to enable efficient computation of the p p p -value. Only the scalar ∥ Σ − 1 / 2 X T ν ∥ 2 \lVert\boldsymbol{\Sigma}^{-1/2}\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}\rVert_2 ∥ Σ − 1/2 X T ν ∥ 2 then remains random. Because p Σ p_{\boldsymbol{\Sigma}} p Σ is uniform under H 0 H_0 H 0 given more information than the clustering, it also controls the selective Type I error in the sense of (3) (Proposition 2.1). To compute p Σ p_{\boldsymbol{\Sigma}} p Σ , replace the observed value of the statistic by ϕ ≥ 0 \phi\ge0 ϕ ≥ 0 and define the perturbed data and the values of ϕ \phi ϕ that reproduce the clustering,
x ′ ( ϕ ) = ( P 1 + P 2 ) x + ϕ ∥ ν ∥ 2 2 ν dir ( Σ − 1 / 2 x T ν ) T Σ 1 / 2 , S Σ = { ϕ ≥ 0 : C ^ 1 , C ^ 2 ∈ C ( x ′ ( ϕ ) ) } . (7) \mathbf{x}'(\phi) = (\mathbf{P}_1 + \mathbf{P}_2)\mathbf{x} + \frac{\phi}{\lVert\boldsymbol{\nu}\rVert_2^2}\boldsymbol{\nu}\operatorname{dir}(\boldsymbol{\Sigma}^{-1/2}\mathbf{x}^{\mathsf{T}}\boldsymbol{\nu})^{\mathsf{T}}\boldsymbol{\Sigma}^{1/2}, \qquad S_{\boldsymbol{\Sigma}} = \{\phi\ge0 : \widehat{C}_1,\widehat{C}_2 \in\mathcal{C}(\mathbf{x}'(\phi))\}. \tag*{(7)} x ′ ( ϕ ) = ( P 1 + P 2 ) x + ∥ ν ∥ 2 2 ϕ ν dir ( Σ − 1/2 x T ν ) T Σ 1/2 , S Σ = { ϕ ≥ 0 : C 1 , C 2 ∈ C ( x ′ ( ϕ ))} . (7)
Proposition 2.1 (Gao et al., 2024, Theorem 1, applied to X Σ − 1 / 2 \mathbf{X}\boldsymbol{\Sigma}^{-1/2} X Σ − 1/2 ). Let X \mathbf{X} X follow (1) with Σ \boldsymbol{\Sigma} Σ known. For any realization x \mathbf{x} x and any two non-overlapping groups C ^ 1 , C ^ 2 \widehat{C}_1,\widehat{C}_2 C 1 , C 2 ,
p Σ = 1 − F ( ∥ Σ − 1 / 2 x T ν ∥ 2 ; ∥ ν ∥ 2 , S Σ ) , p_{\boldsymbol{\Sigma}} = 1 - F(\lVert\boldsymbol{\Sigma}^{-1/2}\mathbf{x}^{\mathsf{T}}\boldsymbol{\nu}\rVert_2; \lVert\boldsymbol{\nu}\rVert_2, S_{\boldsymbol{\Sigma}}), p Σ = 1 − F (∥ Σ − 1/2 x T ν ∥ 2 ; ∥ ν ∥ 2 , S Σ ) , where F ( ⋅ ; c , S ) F(\cdot\,; c,S) F ( ⋅ ; c , S ) is the distribution function of c ⋅ χ p c \cdot\chi_p c ⋅ χ p truncated to S S S . If (2) holds, then P H 0 ( p Σ ≤ α ∣ C ^ 1 , C ^ 2 ∈ C ( X ) ) = α \mathbb{P}_{H_0}(p_{\boldsymbol{\Sigma}} \le\alpha\mid\widehat{C}_1,\widehat{C}_2 \in\mathcal{C}(\mathbf{X})) = \alpha P H 0 ( p Σ ≤ α ∣ C 1 , C 2 ∈ C ( X )) = α for every α ∈ [ 0 , 1 ] \alpha\in[0,1] α ∈ [ 0 , 1 ] .
The perturbed data set x ′ ( ϕ ) \mathbf{x}'(\phi) x ′ ( ϕ ) keeps P 1 x \mathbf{P}_1\mathbf{x} P 1 x and P 2 x \mathbf{P}_2\mathbf{x} P 2 x and rescales only P 0 x \mathbf{P}_0\mathbf{x} P 0 x , so it leaves every observation outside C ^ 1 ∪ C ^ 2 \widehat{C}_1 \cup\widehat{C}_2 C 1 ∪ C 2 in place and keeps the deviations within each tested cluster. It moves the two clusters apart when ϕ \phi ϕ exceeds the observed statistic and together when ϕ \phi ϕ is below it, along the direction of x ˉ C ^ 1 − x ˉ C ^ 2 \bar{\mathbf{x}}_{\widehat{C}_1} - \bar{\mathbf{x}}_{\widehat{C}_2} x ˉ C 1 − x ˉ C 2 (Figure 2 (c)). The set S Σ S_{\boldsymbol{\Sigma}} S Σ therefore collects every value of the statistic that would have produced the same clusters had it been observed instead. Proposition 2.1 says that the scaled χ p \chi_p χ p distribution remains the right null distribution once it is truncated to this set. For hierarchical clustering with common linkages, S Σ S_{\boldsymbol{\Sigma}} S Σ is available in closed form [24 ] . For k k k -means, Chen and Witten (2023) condition on the full k k k -means clustering trajectory of Lloyd’s algorithm instead of on C ^ 1 , C ^ 2 ∈ C ( X ) \widehat{C}_1,\widehat{C}_2 \in\mathcal{C}(\mathbf{X}) C 1 , C 2 ∈ C ( X ) , and the corresponding set is a finite union of intervals whose endpoints solve quadratic equations. With Σ \boldsymbol{\Sigma} Σ known, the weaker null (2) suffices, because the nuisance ( P 1 + P 2 ) μ (\mathbf{P}_1 + \mathbf{P}_2)\boldsymbol{\mu} ( P 1 + P 2 ) μ is removed by conditioning on ( P 1 + P 2 ) X (\mathbf{P}_1 + \mathbf{P}_2)\mathbf{X} ( P 1 + P 2 ) X .
Challenges in estimating the covariance
In practice Σ \boldsymbol{\Sigma} Σ is unknown and must be estimated from the same data. Two natural estimates both fail, in ways that the clustering explains (Figure 1 ).
Σ ^ c l u s t e r = 1 n − K ∑ k = 1 K ∑ i ∈ C ^ k ( x i − x ˉ C ^ k ) ( x i − x ˉ C ^ k ) T \widehat{\boldsymbol{\Sigma}}_{\mathrm{cluster}} = \frac{1}{n-K} \sum_{k=1}^{K} \sum_{i \in\widehat{C}_k} (\mathbf{x}_i-\bar{\mathbf{x}}_{\widehat{C}_k})(\mathbf{x}_i-\bar{\mathbf{x}}_{\widehat{C}_k})^{\mathsf{T}} Σ cluster = n − K 1 k = 1 ∑ K i ∈ C k ∑ ( x i − x ˉ C k ) ( x i − x ˉ C k ) T
is consistent when the clusters are fixed in advance. But k k k -means minimizes the within-cluster sum of squares, so when it splits a true group, Σ ^ c l u s t e r \widehat{\boldsymbol{\Sigma}}_{\mathrm{cluster}} Σ cluster is too small along the tested direction x ˉ C ^ 1 − x ˉ C ^ 2 \bar{\mathbf{x}}_{\widehat{C}_1}-\bar{\mathbf{x}}_{\widehat{C}_2} x ˉ C 1 − x ˉ C 2 . With a single Gaussian group, the test of Chen and Witten (2023) with Σ ^ c l u s t e r \widehat{\boldsymbol{\Sigma}}_{\mathrm{cluster}} Σ cluster , which we write p C W ( Σ ^ c l u s t e r ) p_{\mathrm{CW}}(\widehat{\boldsymbol{\Sigma}}_{\mathrm{cluster}}) p CW ( Σ cluster ) , rejects 16.1% of true null hypotheses at level 0.05 (Figure 1 (b)).
Σ ^ s a m p l e = 1 n − 1 ∑ i = 1 n ( x i − x ˉ ) ( x i − x ˉ ) T \widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}} = \frac{1}{n-1} \sum_{i=1}^{n} (\mathbf{x}_i-\bar{\mathbf{x}})(\mathbf{x}_i-\bar{\mathbf{x}})^{\mathsf{T}} Σ sample = n − 1 1 i = 1 ∑ n ( x i − x ˉ ) ( x i − x ˉ ) T
[27 ] overestimates Σ \boldsymbol{\Sigma} Σ when there are separated groups. This protects the Type I error but costs power, because the separation between the tested clusters inflates Σ ^ s a m p l e \widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}} Σ sample along the tested direction. At the separation δ = 5 \delta=5 δ = 5 of Figure 1 (a), p C W ( Σ ^ s a m p l e ) p_{\mathrm{CW}}(\widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}}) p CW ( Σ sample ) rejects 18% of the pairs from different true groups, against 78% with the true Σ \boldsymbol{\Sigma} Σ (Figure 1 (c)).
Our test does not estimate Σ \boldsymbol{\Sigma} Σ (§ 3 ) and avoids this trade-off: it rejects 5.7% of 900 true null hypotheses at level 0.05, and 99% of the pairs from different groups at δ = 5 \delta=5 δ = 5 (Figure 1 (b) and (Figure 1 c)).
Extension to an unknown variance
When Σ \boldsymbol{\Sigma} Σ is unknown, the length ∥ Σ − 1 / 2 X T ν ∥ \lVert\boldsymbol{\Sigma}^{-1/2}\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}\rVert ∥ Σ − 1/2 X T ν ∥ in § 2.1 has an unknown distribution, so we need a test statistic whose null distribution does not depend on the covariance. Two-sample tests have this property, because they depend on the data only through an angle. We explain the angle with the decomposition of Yun and Barber (2023) for Σ = σ 2 I p \boldsymbol{\Sigma}=\sigma^2\mathbf{I}_p Σ = σ 2 I p , and then describe how we move to an arbitrary Σ \boldsymbol{\Sigma} Σ .
Yun and Barber (2023) use the same decomposition X = P 0 X + P 1 X + P 2 X \mathbf{X}=\mathbf{P}_0\mathbf{X}+\mathbf{P}_1\mathbf{X}+\mathbf{P}_2\mathbf{X} X = P 0 X + P 1 X + P 2 X of § 2.1 . Their test statistic is
R = ( r − 2 ) ∥ P 0 X ∥ F 2 ∥ P 1 X ∥ F 2 , r = ∣ C ^ 1 ∣ + ∣ C ^ 2 ∣ , (8) R=(r-2)\frac{\lVert\mathbf{P}_0\mathbf{X}\rVert_F^2}{\lVert\mathbf{P}_1\mathbf{X}\rVert_F^2}, \qquad r=\lvert\widehat{C}_1\rvert+\lvert\widehat{C}_2\rvert, \tag*{(8)} R = ( r − 2 ) ∥ P 1 X ∥ F 2 ∥ P 0 X ∥ F 2 , r = ∣ C 1 ∣ + ∣ C 2 ∣ , (8)
which compares the spread between the two clusters with the spread within them.
To see why the distribution of R R R does not involve σ 2 \sigma^2 σ 2 , consider ( P 0 + P 1 ) X (\mathbf{P}_0+\mathbf{P}_1)\mathbf{X} ( P 0 + P 1 ) X , the deviations of the tested observations from their common mean. The matrix P 0 + P 1 \mathbf{P}_0+\mathbf{P}_1 P 0 + P 1 is the projection onto an ( r − 1 ) (r-1) ( r − 1 ) -dimensional subspace of R n \mathbb{R}^n R n , so under null (5), ( P 0 + P 1 ) X ∼ M N n × p ( 0 , P 0 + P 1 , σ 2 I p ) (\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\sim\mathcal{MN}_{n\times p}(0,\mathbf{P}_0+\mathbf{P}_1,\sigma^2\mathbf{I}_p) ( P 0 + P 1 ) X ∼ M N n × p ( 0 , P 0 + P 1 , σ 2 I p ) ; that is, vec ( ( P 0 + P 1 ) X ) \operatorname{vec}((\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}) vec (( P 0 + P 1 ) X ) has independent N ( 0 , σ 2 ) \mathcal{N}(0,\sigma^2) N ( 0 , σ 2 ) coordinates in an ( r − 1 ) p (r-1)p ( r − 1 ) p -dimensional subspace of R n p \mathbb{R}^{np} R n p . Such a Gaussian vector splits into its length and its direction. The squared length, ∥ ( P 0 + P 1 ) X ∥ F 2 ∼ σ 2 χ ( r − 1 ) p 2 \lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F^2\sim\sigma^2\chi^2_{(r-1)p} ∥( P 0 + P 1 ) X ∥ F 2 ∼ σ 2 χ ( r − 1 ) p 2 , is a sufficient statistic for σ 2 \sigma^2 σ 2 . The direction ( P 0 + P 1 ) X / ∥ ( P 0 + P 1 ) X ∥ F (\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}/\lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F ( P 0 + P 1 ) X / ∥( P 0 + P 1 ) X ∥ F is uniformly distributed on the unit sphere of that subspace, whatever σ 2 \sigma^2 σ 2 is. Moreover, the length and the direction are independent [46 , 15 ] .
The statistic R R R is a function of the direction only. Write w = ∥ P 0 X ∥ F 2 / ∥ ( P 0 + P 1 ) X ∥ F 2 w=\lVert\mathbf{P}_0\mathbf{X}\rVert_F^2/\lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F^2 w = ∥ P 0 X ∥ F 2 / ∥( P 0 + P 1 ) X ∥ F 2 for the fraction of the squared length of ( P 0 + P 1 ) X (\mathbf{P}_0+\mathbf{P}_1)\mathbf{X} ( P 0 + P 1 ) X that comes from the difference between the two cluster means. The remaining fraction, 1 − w = ∥ P 1 X ∥ F 2 / ∥ ( P 0 + P 1 ) X ∥ F 2 1-w=\lVert\mathbf{P}_1\mathbf{X}\rVert_F^2/\lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F^2 1 − w = ∥ P 1 X ∥ F 2 / ∥( P 0 + P 1 ) X ∥ F 2 , comes from the deviations of the observations from their own cluster means, and R = ( r − 2 ) w / ( 1 − w ) R=(r-2)w/(1-w) R = ( r − 2 ) w / ( 1 − w ) . A value of w w w close to one means that the observations sit close to their own cluster means and the two means are far apart relative to that spread, so the clusters look well separated and R R R is large. In that case most of the variation of the tested observations is between the two clusters rather than within them, which we do not expect when (5) holds. A value of w w w close to zero means that the spread within the clusters dominates the difference between their means. Because the direction is uniformly distributed on the sphere and the range of P 0 \mathbf{P}_0 P 0 is a p p p -dimensional part of the ( r − 1 ) p (r-1)p ( r − 1 ) p -dimensional subspace, w ∼ Beta ( p / 2 , ( r − 2 ) p / 2 ) w\sim\operatorname{Beta}(p/2,(r-2)p/2) w ∼ Beta ( p /2 , ( r − 2 ) p /2 ) for every σ 2 \sigma^2 σ 2 , and therefore R ∼ F p , ( r − 2 ) p R\sim F_{p,(r-2)p} R ∼ F p , ( r − 2 ) p . It turns out that R R R is just one such choice. Any other ratio of ∥ P 0 X ∥ F 2 \lVert\mathbf{P}_0\mathbf{X}\rVert_F^2 ∥ P 0 X ∥ F 2 , ∥ P 1 X ∥ F 2 \lVert\mathbf{P}_1\mathbf{X}\rVert_F^2 ∥ P 1 X ∥ F 2 , and ∥ ( P 0 + P 1 ) X ∥ F 2 \lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F^2 ∥( P 0 + P 1 ) X ∥ F 2 , such as w w w , is a monotone function of R R R and gives an equivalent test.
The construction rests on two ingredients, which § 3 reuses for an arbitrary Σ \boldsymbol{\Sigma} Σ . First, we condition on statistics that are sufficient for the nuisance parameters under the null, here the length for σ 2 \sigma^2 σ 2 and P 2 X \mathbf{P}_2\mathbf{X} P 2 X for the means, so that the conditional distribution of the data does not involve them [39 Chapter 4] . Second, the test statistic is a function of the remaining part, here the direction, which is independent of the sufficient statistics; its conditional distribution is therefore its known unconditional one. The direction also splits further: w w w and the two directions dir ( P 0 X ) \operatorname{dir}(\mathbf{P}_0\mathbf{X}) dir ( P 0 X ) and dir ( P 1 X ) \operatorname{dir}(\mathbf{P}_1\mathbf{X}) dir ( P 1 X ) are independent. Testing with a direction that is uniformly distributed on a sphere has also been applied to testing in sparse linear models [55 , 53 ] .
After clustering, R R R no longer has an F F F distribution, and conditioning on the clustering alone is not enough to compute its distribution. The event C ^ 1 , C ^ 2 ∈ C ( X ) \widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X}) C 1 , C 2 ∈ C ( X ) depends on the data through P 2 X \mathbf{P}_2\mathbf{X} P 2 X , the length, and the whole direction, not only through R R R , so the conditional distribution of R R R given the event would require an integral over all directions that reproduce the clusters, which has no closed form. Yun and Barber (2023) therefore condition on every part of the data other than R R R :
p Y B = P H 0 ′ ( R ( X ) ≥ R ( x ) | C ^ 1 , C ^ 2 ∈ C ( X ) , P 2 X = P 2 x , ∥ ( P 0 + P 1 ) X ∥ F = ∥ ( P 0 + P 1 ) x ∥ F , dir ( P 0 X ) = dir ( P 0 x ) , dir ( P 1 X ) = dir ( P 1 x ) ) . (9) p_{\mathrm{YB}}=\mathbb{P}_{H'_0}\left(R(\mathbf{X})\ge R(\mathbf{x})\ \middle|\ \widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X}),\ \mathbf{P}_2\mathbf{X}=\mathbf{P}_2\mathbf{x},\ \lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F=\lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{x}\rVert_F,\ \operatorname{dir}(\mathbf{P}_0\mathbf{X})=\operatorname{dir}(\mathbf{P}_0\mathbf{x}),\ \operatorname{dir}(\mathbf{P}_1\mathbf{X})=\operatorname{dir}(\mathbf{P}_1\mathbf{x})\right). \tag*{(9)} p YB = P H 0 ′ ( R ( X ) ≥ R ( x ) C 1 , C 2 ∈ C ( X ) , P 2 X = P 2 x , ∥( P 0 + P 1 ) X ∥ F = ∥( P 0 + P 1 ) x ∥ F , dir ( P 0 X ) = dir ( P 0 x ) , dir ( P 1 X ) = dir ( P 1 x ) ) . (9)
The conditions on P 2 X \mathbf{P}_2\mathbf{X} P 2 X and on the length remove the nuisance parameters, which are the means and σ 2 \sigma^2 σ 2 ; this uses the first ingredient. The conditions on the two directions are additional conditioning, as is the condition on dir ( ⋅ ) \operatorname{dir}(\cdot) dir ( ⋅ ) in (6) . Given all four, the data are a function of R R R alone: replacing the observed R R R by ρ ≥ 0 \rho\ge0 ρ ≥ 0 gives the perturbed data set
x ′ ( ρ ) = P 2 x + ∥ ( P 0 + P 1 ) x ∥ F ( ρ ρ + r − 2 dir ( P 0 x ) + r − 2 ρ + r − 2 dir ( P 1 x ) ) , (10) \mathbf{x}'(\rho)=\mathbf{P}_2\mathbf{x}+\lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{x}\rVert_F\left(\sqrt{\frac{\rho}{\rho+r-2}}\operatorname{dir}(\mathbf{P}_0\mathbf{x})+\sqrt{\frac{r-2}{\rho+r-2}}\operatorname{dir}(\mathbf{P}_1\mathbf{x})\right), \tag*{(10)} x ′ ( ρ ) = P 2 x + ∥( P 0 + P 1 ) x ∥ F ( ρ + r − 2 ρ dir ( P 0 x ) + ρ + r − 2 r − 2 dir ( P 1 x ) ) , (10)
as x ′ ( ϕ ) \mathbf{x}'(\phi) x ′ ( ϕ ) in (7) , and by the second ingredient R R R keeps its F p , ( r − 2 ) p F_{p,(r-2)p} F p , ( r − 2 ) p distribution given the length and the two directions. So p Y B p_{\mathrm{YB}} p YB is the upper tail of the F p , ( r − 2 ) p F_{p,(r-2)p} F p , ( r − 2 ) p distribution truncated to the set S Y B = { ρ ≥ 0 : C ^ 1 , C ^ 2 ∈ C ( x ′ ( ρ ) ) } \mathcal{S}_{\mathrm{YB}}=\{\rho\ge0:\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{x}'(\rho))\} S YB = { ρ ≥ 0 : C 1 , C 2 ∈ C ( x ′ ( ρ ))} . § 4 takes the other route in our setting: it drops the additional conditioning and computes the integral over directions by Monte Carlo.
What does it take to extend this argument to a general Σ \boldsymbol{\Sigma} Σ ? Both ingredients rely on vec ( ( P 0 + P 1 ) X ) \operatorname{vec}((\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}) vec (( P 0 + P 1 ) X ) being an isotropic Gaussian vector. For a general Σ \boldsymbol{\Sigma} Σ , the entries within each row are correlated, so the direction is not uniformly distributed and the distribution of R R R depends on Σ \boldsymbol{\Sigma} Σ . The intuition still applies. In § 3 , the polar decomposition of a matrix splits the distribution of ( P 0 + P 1 ) X (\mathbf{P}_0+\mathbf{P}_1)\mathbf{X} ( P 0 + P 1 ) X into a part whose distribution involves Σ \boldsymbol{\Sigma} Σ and an independent part whose distribution does not depend on Σ \boldsymbol{\Sigma} Σ , and an analogue of R R R in (8) leads to the familiar Hotelling’s T 2 T^2 T 2 statistic.
Remark 2.2 (The null hypothesis we test). Both Yun and Barber (2023) and our work test (5) rather than (2). The reason is that both tests use the distribution of ( P 0 + P 1 ) X (P_0 + P_1)X ( P 0 + P 1 ) X , which has mean zero exactly when all r r r tested observations share one mean, because the only vectors on the tested observations that P 0 + P 1 P_0 + P_1 P 0 + P 1 maps to zero are the constant ones. Under (2), P 1 X P_1X P 1 X has a nonzero mean whenever the observations within a cluster have different means.
Selective p p p -value under an unknown covariance
This section builds on the decomposition in § 2.3 and proposes a selective test for an arbitrary clustering algorithm under an unknown covariance matrix. Section 3.1 replaces the length ∥ ( P 0 + P 1 ) X ∥ F \lVert(P_0 + P_1)X\rVert_F ∥( P 0 + P 1 ) X ∥ F by a matrix and shows that the remaining factor Q \mathbf{Q} Q is uniformly distributed for every Σ \boldsymbol{\Sigma} Σ . Section 3.2 shows that Hotelling’s T 2 T^2 T 2 is a function of one angle of Q \mathbf{Q} Q , which is the angle of Section 2.3 when p = 1 p = 1 p = 1 . Section 3.3 conditions on the clustering and obtains the selective p p p -value p p o l a r p_{\mathrm{polar}} p polar , and Section 3.4 conditions on more to obtain the one-dimensional test p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d . Section 4 explains how to compute both.
Throughout, the tested clusters have sizes n 1 = ∣ C ^ 1 ∣ n_1 = |\widehat{C}_1| n 1 = ∣ C 1 ∣ and n 2 = ∣ C ^ 2 ∣ n_2 = |\widehat{C}_2| n 2 = ∣ C 2 ∣ , with r = n 1 + n 2 ≥ p + 2 r = n_1 + n_2 \ge p + 2 r = n 1 + n 2 ≥ p + 2 , which the pooled covariance in Hotelling’s T 2 T^2 T 2 requires even without clustering. Theorem 3.1 and Proposition 3.2 hold for any two fixed groups of observations. From Section 3.3 on, C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 are clusters returned by a clustering algorithm that is a deterministic function of the data (for example, k k k -means from fixed initial centroids), and the tested pair is fixed in advance or every pair is tested.
The polar decomposition of ( P 0 + P 1 ) X (P_0 + P_1)X ( P 0 + P 1 ) X
Section 2.3 split ( P 0 + P 1 ) X (P_0 + P_1)X ( P 0 + P 1 ) X , the deviations of the tested observations from their common mean, into a length and a direction. The polar decomposition makes the same split with a matrix in place of the scalar length. When ( P 0 + P 1 ) X (P_0 + P_1)X ( P 0 + P 1 ) X has rank p p p , which holds with probability one when r − 1 ≥ p r - 1 \ge p r − 1 ≥ p ,
( P 0 + P 1 ) X = Q H , (11) (P_0 + P_1)X = \mathbf{Q}\mathbf{H}, \tag*{(11)} ( P 0 + P 1 ) X = QH , (11)
where H \mathbf{H} H is symmetric positive definite and the polar factor Q \mathbf{Q} Q is an n × p n \times p n × p matrix with orthonormal columns. The columns of Q \mathbf{Q} Q lie in the ( r − 1 ) (r - 1) ( r − 1 ) -dimensional range of P 0 + P 1 P_0 + P_1 P 0 + P 1 , so Q \mathbf{Q} Q belongs to the set V \mathcal{V} V of n × p n \times p n × p matrices with orthonormal columns in that range, which is a copy of the Stiefel manifold St ( r − 1 , p ) \operatorname{St}(r - 1,p) St ( r − 1 , p ) . The matrix H \mathbf{H} H is the matrix square root of r − 1 r - 1 r − 1 times the sample covariance matrix of the tested observations. The polar factor Q \mathbf{Q} Q plays the role of the direction, and H \mathbf{H} H plays the role of the length; when p = 1 p = 1 p = 1 the two decompositions are the same (Appendix § 9 ).
Theorem 3.1 (Distribution of the polar factor). Under data model (1) and null (5), Q \mathbf{Q} Q is uniformly distributed on V \mathcal{V} V and is independent of ( H , P 2 X ) (\mathbf{H}, P_2X) ( H , P 2 X ) .
This follows from a classical result on the polar decomposition of a Gaussian matrix ([46 , 15 ] ); Appendix § 9 gives a proof in our notation. The two ingredients of Section 2.3 therefore hold for every Σ \boldsymbol{\Sigma} Σ : the means and Σ \boldsymbol{\Sigma} Σ enter only through ( P 2 X , H ) (P_2X, \mathbf{H}) ( P 2 X , H ) , and Q \mathbf{Q} Q is independent of them with a distribution that involves no unknown parameter. Figure 2 (d) shows a data set with P 2 X P_2X P 2 X and H \mathbf{H} H held fixed and Q \mathbf{Q} Q drawn from its uniform distribution. This suggests that we can construct a pivotal statistic based on Q \mathbf{Q} Q .
Hotelling’s T 2 T^2 T 2 as a function of Q \mathbf{Q} Q
Which function of Q \mathbf{Q} Q should we use? In Section 2.3, R R R compares the part of the direction of ( P 0 + P 1 ) X (P_0 + P_1)X ( P 0 + P 1 ) X that lies along P 0 P_0 P 0 , the between-cluster part, with the part along P 1 P_1 P 1 , the withincluster part. The matrix P 0 \mathbf{P}_0 P 0 projects onto the one-dimensional column space of P 0 X \mathbf{P}_0\mathbf{X} P 0 X , the direction of between-cluster variation. The analogue of w w w for the polar factor is the squared length of the projection of Q \mathbf{Q} Q onto that direction, u ( Q ) = ∥ P 0 Q ∥ F 2 ∈ [ 0 , 1 ] u(\mathbf{Q}) = \lVert\mathbf{P}_0\mathbf{Q}\rVert_{\mathrm{F}}^2 \in[0,1] u ( Q ) = ∥ P 0 Q ∥ F 2 ∈ [ 0 , 1 ] . As with R R R , a large value of u ( Q ) / { 1 − u ( Q ) } u(\mathbf{Q})/\{1-u(\mathbf{Q})\} u ( Q ) / { 1 − u ( Q )} means that the polar factor is dominated by between-cluster variation, which is unlikely under the null. This ratio is a scaled version of the usual two-sample Hotelling statistic.
Proposition 3.2 (Hotelling’s T 2 T^2 T 2 as a function of u ( Q ) u(\mathbf{Q}) u ( Q ) ). The two-sample Hotelling statistic,
T 2 = n 1 n 2 r ( X ˉ C ^ 1 − X ˉ C ^ 2 ) T S p o o l − 1 ( X ˉ C ^ 1 − X ˉ C ^ 2 ) , S p o o l = X T P 1 X r − 2 , T^2 = \frac{n_1n_2}{r}(\bar{\mathbf{X}}_{\hat{C}_1}-\bar{\mathbf{X}}_{\hat{C}_2})^{\mathsf{T}}\mathbf{S}_{\mathrm{pool}}^{-1}(\bar{\mathbf{X}}_{\hat{C}_1}-\bar{\mathbf{X}}_{\hat{C}_2}), \qquad\mathbf{S}_{\mathrm{pool}} = \frac{\mathbf{X}^{\mathsf{T}}\mathbf{P}_1\mathbf{X}}{r-2}, T 2 = r n 1 n 2 ( X ˉ C ^ 1 − X ˉ C ^ 2 ) T S pool − 1 ( X ˉ C ^ 1 − X ˉ C ^ 2 ) , S pool = r − 2 X T P 1 X , where S p o o l \mathbf{S}_{\mathrm{pool}} S pool is the pooled within-cluster covariance matrix, satisfies
T 2 = ( r − 2 ) u ( Q ) 1 − u ( Q ) . (12) T^2 = (r-2)\frac{u(\mathbf{Q})}{1-u(\mathbf{Q})}. \tag*{(12)} T 2 = ( r − 2 ) 1 − u ( Q ) u ( Q ) . (12) When p = 1 p=1 p = 1 , T 2 = R T^2=R T 2 = R in (8) . Under data model (1) and null (5) , u ( Q ) ∼ Beta ( p 2 , r − 1 − p 2 ) u(\mathbf{Q}) \sim\operatorname{Beta}\left(\frac{p}{2},\frac{r-1-p}{2}\right) u ( Q ) ∼ Beta ( 2 p , 2 r − 1 − p ) ; equivalently, r − p − 1 ( r − 2 ) p T 2 ∼ F p , r − p − 1 \frac{r-p-1}{(r-2)p}T^2 \sim F_{p,r-p-1} ( r − 2 ) p r − p − 1 T 2 ∼ F p , r − p − 1 . The proof is in Appendix A. The connection is classical: T 2 T^2 T 2 is the largest squared two-sample t t t -statistic over all one-dimensional projections of the data, attained at the Fisher discriminant direction [30 , 2 ] .
The selective p p p -value
Proposition 3.2 describes T 2 T^2 T 2 before clustering. After clustering, as in (6) and (9) , we condition on the clustering and on the sufficient statistics for the nuisance parameters, and propose the selective p p p -value
p p o l a r = P H 0 ′ ( T 2 ( X ) ≥ T 2 ( x ) ∣ C ^ 1 , C ^ 2 ∈ C ( X ) , P 2 X = P 2 x , H ( X ) = H ( x ) ) . (13) p_{\mathrm{polar}} = \mathbb{P}_{H'_0}\left(T^2(\mathbf{X}) \ge T^2(\mathbf{x}) \mathrel{\big|} \hat{C}_1,\hat{C}_2 \in\mathcal{C}(\mathbf{X}),\ \mathbf{P}_2\mathbf{X}=\mathbf{P}_2\mathbf{x},\ \mathbf{H}(\mathbf{X})=\mathbf{H}(\mathbf{x})\right). \tag*{(13)} p polar = P H 0 ′ ( T 2 ( X ) ≥ T 2 ( x ) C ^ 1 , C ^ 2 ∈ C ( X ) , P 2 X = P 2 x , H ( X ) = H ( x ) ) . (13)
The conditioning fixes C ^ 1 \hat{C}_1 C ^ 1 and C ^ 2 \hat{C}_2 C ^ 2 , and with them P 0 \mathbf{P}_0 P 0 , P 1 \mathbf{P}_1 P 1 , and P 2 \mathbf{P}_2 P 2 . As in (7) and (10) , replacing the observed polar factor by Q ∈ V \mathbf{Q}\in\mathcal{V} Q ∈ V gives the perturbed data set
x ′ ( Q ) = P 2 x + Q H ( x ) , S Q = { Q ∈ V : C ^ 1 , C ^ 2 ∈ C ( x ′ ( Q ) ) } , \mathbf{x}'(\mathbf{Q})=\mathbf{P}_2\mathbf{x}+\mathbf{Q}\mathbf{H}(\mathbf{x}), \qquad S_{\mathbf{Q}}=\{\mathbf{Q}\in\mathcal{V}:\hat{C}_1,\hat{C}_2\in\mathcal{C}(\mathbf{x}'(\mathbf{Q}))\}, x ′ ( Q ) = P 2 x + QH ( x ) , S Q = { Q ∈ V : C ^ 1 , C ^ 2 ∈ C ( x ′ ( Q ))} ,
where S Q S_{\mathbf{Q}} S Q is the set of polar factors that reproduce the tested clusters.
Proposition 3.3 (The selective p p p -value). Under data model (1) and null (5) , conditional on P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and C ^ 1 , C ^ 2 ∈ C ( X ) \hat{C}_1,\hat{C}_2\in\mathcal{C}(\mathbf{X}) C ^ 1 , C ^ 2 ∈ C ( X ) , the polar factor Q \mathbf{Q} Q is uniformly distributed on S Q S_{\mathbf{Q}} S Q . Consequently, with Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs the observed polar factor and d Q d\mathbf{Q} d Q integration against the uniform distribution on V \mathcal{V} V ,
p p o l a r = ∫ S Q ∩ { u ( Q ) ≥ u ( Q o b s ) } d Q ∫ S Q d Q , P H 0 ′ ( p p o l a r ≤ α ∣ C ^ 1 , C ^ 2 ∈ C ( X ) ) = α for all α ∈ [ 0 , 1 ] . (14) p_{\mathrm{polar}}=\frac{\int_{S_{\mathbf{Q}}\cap\{u(\mathbf{Q})\ge u(\mathbf{Q}_{\mathrm{obs}})\}}d\mathbf{Q}}{\int_{S_{\mathbf{Q}}}d\mathbf{Q}}, \qquad\mathbb{P}_{H'_0}\left(p_{\mathrm{polar}}\le\alpha\mathrel{\big|}\hat{C}_1,\hat{C}_2\in\mathcal{C}(\mathbf{X})\right)=\alpha\quad\text{for all }\alpha\in[0,1]. \tag*{(14)} p polar = ∫ S Q d Q ∫ S Q ∩ { u ( Q ) ≥ u ( Q obs )} d Q , P H 0 ′ ( p polar ≤ α C ^ 1 , C ^ 2 ∈ C ( X ) ) = α for all α ∈ [ 0 , 1 ] . (14) The proof is in Appendix A. The second part of (14) says that p p o l a r p_{\mathrm{polar}} p polar controls the selective Type I error in the sense of (3) , with equality and with H 0 ′ H'_0 H 0 ′ in place of H 0 H_0 H 0 . In words, among all data sets with the same P 2 X \mathbf{P}_2\mathbf{X} P 2 X and H \mathbf{H} H on which the clustering returns C ^ 1 \hat{C}_1 C ^ 1 and C ^ 2 \hat{C}_2 C ^ 2 , p p o l a r p_{\mathrm{polar}} p polar is the fraction on which the two clusters look at least as separated, as measured by T 2 T^2 T 2 , as in the observed data.
Given (6) and (9) , it is tempting to expect p p o l a r p_{\mathrm{polar}} p polar to be the tail of an F F F distribution truncated to the values of T 2 T^2 T 2 that reproduce the clusters. It is not, because whether the clustering returns C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 depends on all of Q \mathbf{Q} Q , not only on T 2 T^2 T 2 : polar factors with the same T 2 T^2 T 2 arrange the tested observations differently in the other directions, so some of them reproduce the clusters and some do not. The clustering therefore reweights the null distribution of T 2 T^2 T 2 by the fraction of polar factors with each value of T 2 T^2 T 2 that reproduce the clusters, and this fraction has no closed form. In contrast, (6) and (9) condition on everything except one scalar. Each value of that scalar corresponds to a single data set, which either reproduces the clusters or does not. Computing p p o l a r p_{\mathrm{polar}} p polar in (13) therefore needs Monte Carlo sampling, and Section 4 gives sampling methods whose p p p -values are exact for any number of draws.
Conditioning on more to obtain a one-dimensional pivot
We now work toward a p p p -value that, as in (6) and (9), is the survival function of a known one-dimensional distribution truncated to a set. The high-level strategy is to identify a one-dimensional function of Q \mathbf{Q} Q and condition on all the rest. By Proposition 3.2, T 2 T^2 T 2 depends on Q \mathbf{Q} Q only through u ( Q ) u(\mathbf{Q}) u ( Q ) , so u ( Q ) u(\mathbf{Q}) u ( Q ) is the function we keep random. To say what the rest of Q \mathbf{Q} Q is, we use the Fisher discriminant direction of Section 3.2.
Since P 0 = ν ˉ ν ˉ T \mathbf{P}_0=\bar{\nu}\bar{\nu}^{\mathsf{T}} P 0 = ν ˉ ν ˉ T with ν ˉ = ν / ∥ ν ∥ 2 \bar{\nu}=\nu/\|\nu\|_2 ν ˉ = ν /∥ ν ∥ 2 , the between-cluster part of Q \mathbf{Q} Q is the rank-one matrix
P 0 Q = u ( Q ) ν ˉ γ T , γ = dir ( Q T ν ) = dir ( H − 1 X T ν ) . (15) \mathbf{P}_0\mathbf{Q}=\sqrt{u(\mathbf{Q})}\,\bar{\nu}\,\gamma^{\mathsf{T}},\qquad\gamma=\operatorname{dir}(\mathbf{Q}^{\mathsf{T}}\nu)=\operatorname{dir}(\mathbf{H}^{-1}\mathbf{X}^{\mathsf{T}}\nu). \tag*{(15)} P 0 Q = u ( Q ) ν ˉ γ T , γ = dir ( Q T ν ) = dir ( H − 1 X T ν ) . (15)
The vector q = Q γ = ( P 0 + P 1 ) X H − 1 γ \mathbf{q}=\mathbf{Q}\gamma=(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\mathbf{H}^{-1}\gamma q = Q γ = ( P 0 + P 1 ) X H − 1 γ is the tested data projected onto the direction H − 1 γ \mathbf{H}^{-1}\gamma H − 1 γ , which is proportional to { X T ( P 0 + P 1 ) X } − 1 X T ν \{\mathbf{X}^{\mathsf{T}}(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\}^{-1}\mathbf{X}^{\mathsf{T}}\nu { X T ( P 0 + P 1 ) X } − 1 X T ν , the Fisher discriminant direction, and scaled so that ∥ q ∥ 2 = 1 \|\mathbf{q}\|_2=1 ∥ q ∥ 2 = 1 . So q \mathbf{q} q is a data set with one feature. By (15), its between-cluster part is P 0 q = u ( Q ) ν ˉ \mathbf{P}_0\mathbf{q}=\sqrt{u(\mathbf{Q})}\,\bar{\nu} P 0 q = u ( Q ) ν ˉ , so u ( Q ) u(\mathbf{Q}) u ( Q ) is the fraction w w w of § 2.3 computed on q \mathbf{q} q , and T 2 = ( r − 2 ) ∥ P 0 q ∥ 2 2 / ∥ P 1 q ∥ 2 2 T^2=(r-2)\|\mathbf{P}_0\mathbf{q}\|_2^2/\|\mathbf{P}_1\mathbf{q}\|_2^2 T 2 = ( r − 2 ) ∥ P 0 q ∥ 2 2 /∥ P 1 q ∥ 2 2 is the statistic R R R in (8) computed on q \mathbf{q} q .
This suggests applying the conditioning of Yun and Barber (2023) to q \mathbf{q} q and holding the rest of Q \mathbf{Q} Q fixed. Yun and Barber (2023) fix the directions of the between-cluster and within-cluster parts and keep only their relative size random. The between-cluster part of q \mathbf{q} q always points along ν ˉ \bar{\nu} ν ˉ , so we fix the following three quantities:
the direction γ \gamma γ , which fixes the direction onto which the data are projected;
the direction dir ( P 1 q ) \operatorname{dir}(\mathbf{P}_1\mathbf{q}) dir ( P 1 q ) of the within-cluster part of q \mathbf{q} q ;
the part of Q \mathbf{Q} Q orthogonal to γ \gamma γ , Q ( I p − γ γ T ) \mathbf{Q}(\mathbf{I}_p-\gamma\gamma^{\mathsf{T}}) Q ( I p − γ γ T ) , which describes the tested data in the directions orthogonal to the Fisher direction.
We write Γ = ( γ , dir ( P 1 q ) , Q ( I p − γ γ T ) ) \boldsymbol{\Gamma}=(\gamma,\operatorname{dir}(\mathbf{P}_1\mathbf{q}),\mathbf{Q}(\mathbf{I}_p-\gamma\gamma^{\mathsf{T}})) Γ = ( γ , dir ( P 1 q ) , Q ( I p − γ γ T )) . Since q \mathbf{q} q has unit length, ∥ P 1 q ∥ 2 = 1 − u ( Q ) \|\mathbf{P}_1\mathbf{q}\|_2=\sqrt{1-u(\mathbf{Q})} ∥ P 1 q ∥ 2 = 1 − u ( Q ) , and writing Q = q γ T + Q ( I p − γ γ T ) \mathbf{Q}=\mathbf{q}\gamma^{\mathsf{T}}+\mathbf{Q}(\mathbf{I}_p-\gamma\gamma^{\mathsf{T}}) Q = q γ T + Q ( I p − γ γ T ) gives
Q = ( u ( Q ) ν ˉ + 1 − u ( Q ) dir ( P 1 q ) ) γ T + Q ( I p − γ γ T ) . (16) \mathbf{Q}=\left(\sqrt{u(\mathbf{Q})}\,\bar{\nu}+\sqrt{1-u(\mathbf{Q})}\operatorname{dir}(\mathbf{P}_1\mathbf{q})\right)\gamma^{\mathsf{T}}+\mathbf{Q}(\mathbf{I}_p-\gamma\gamma^{\mathsf{T}}). \tag*{(16)} Q = ( u ( Q ) ν ˉ + 1 − u ( Q ) dir ( P 1 q ) ) γ T + Q ( I p − γ γ T ) . (16)
So Q \mathbf{Q} Q is determined by u ( Q ) u(\mathbf{Q}) u ( Q ) and Γ \boldsymbol{\Gamma} Γ , and conditioning on Γ \boldsymbol{\Gamma} Γ leaves u ( Q ) u(\mathbf{Q}) u ( Q ) as the only random quantity. It is convenient to write this quantity as an angle. For ϕ ∈ ( 0 , π / 2 ) \phi\in(0,\pi/2) ϕ ∈ ( 0 , π /2 ) , replacing u ( Q ) \sqrt{u(\mathbf{Q})} u ( Q ) by cos ϕ \cos\phi cos ϕ and 1 − u ( Q ) \sqrt{1-u(\mathbf{Q})} 1 − u ( Q ) by sin ϕ \sin\phi sin ϕ in (16) gives
Q Γ ( ϕ ) = ( cos ϕ ν ˉ + sin ϕ dir ( P 1 q ) ) γ T + Q ( I p − γ γ T ) . (17) \mathbf{Q}_{\boldsymbol{\Gamma}}(\phi)=\left(\cos\phi\,\bar{\nu}+\sin\phi\operatorname{dir}(\mathbf{P}_1\mathbf{q})\right)\gamma^{\mathsf{T}}+\mathbf{Q}(\mathbf{I}_p-\gamma\gamma^{\mathsf{T}}). \tag*{(17)} Q Γ ( ϕ ) = ( cos ϕ ν ˉ + sin ϕ dir ( P 1 q ) ) γ T + Q ( I p − γ γ T ) . (17)
the polar factor that has the same Γ \boldsymbol{\Gamma} Γ as Q \mathbf{Q} Q and whose projected data have between-cluster fraction cos 2 ϕ \cos^2\phi cos 2 ϕ . It lies in V \mathcal{V} V for every ϕ \phi ϕ (Proposition B.2). We write θ \theta θ for the observed angle, u ( Q ) = cos 2 θ u(\mathbf{Q})=\cos^2\theta u ( Q ) = cos 2 θ ; along the path, T 2 = ( r − 2 ) cot 2 ϕ T^2=(r-2)\cot^2\phi T 2 = ( r − 2 ) cot 2 ϕ . As ϕ \phi ϕ varies, the unit vector cos ϕ ν ˉ + sin ϕ dir ( P 1 q ) \cos\phi\,\bar{\nu}+\sin\phi\operatorname{dir}(\mathbf{P}_1\mathbf{q}) cos ϕ ν ˉ + sin ϕ dir ( P 1 q ) in (17) turns at constant speed in the plane spanned by ν ˉ \bar{\nu} ν ˉ and dir ( P 1 q ) \operatorname{dir}(\mathbf{P}_1\mathbf{q}) dir ( P 1 q ) . The path is therefore a rotation of Q \mathbf{Q} Q , the form used in § 4 . We write
S θ = { ϕ ∈ ( 0 , π / 2 ) : C ^ 1 , C ^ 2 ∈ C ( P 2 x + Q Γ ( ϕ ) H ( x ) ) } (18) S_{\theta} = \left\{ \phi\in(0,\pi/2) : \widehat{C}_1,\widehat{C}_2 \in\mathcal{C}\left(\mathbf{P}_2\mathbf{x} + \mathbf{Q}\boldsymbol{\Gamma}(\phi)\mathbf{H}(\mathbf{x})\right) \right\} \tag*{(18)} S θ = { ϕ ∈ ( 0 , π /2 ) : C 1 , C 2 ∈ C ( P 2 x + Q Γ ( ϕ ) H ( x ) ) } (18)
for the set of angles at which the clustering returns the tested clusters. The one-dimensional selective p p p -value conditions on Γ \boldsymbol{\Gamma} Γ in addition to the clustering and the nuisance statistics,
p p o l a r , 1 d = P H 0 ′ ( T 2 ( X ) ≥ T 2 ( x ) ∣ C ^ 1 , C ^ 2 ∈ C ( X ) , P 2 X = P 2 x , H ( X ) = H ( x ) , Γ ( X ) = Γ ( x ) ) . (19) p_{\mathrm{polar},1\mathrm{d}} = \mathbb{P}_{H'_0}\left(T^2(\mathbf{X}) \ge T^2(\mathbf{x}) \mathrel{\Big|} \widehat{C}_1,\widehat{C}_2 \in\mathcal{C}(\mathbf{X}),\ \mathbf{P}_2\mathbf{X} = \mathbf{P}_2\mathbf{x},\ \mathbf{H}(\mathbf{X}) = \mathbf{H}(\mathbf{x}),\ \boldsymbol{\Gamma}(\mathbf{X}) = \boldsymbol{\Gamma}(\mathbf{x})\right). \tag*{(19)} p polar , 1 d = P H 0 ′ ( T 2 ( X ) ≥ T 2 ( x ) C 1 , C 2 ∈ C ( X ) , P 2 X = P 2 x , H ( X ) = H ( x ) , Γ ( X ) = Γ ( x ) ) . (19)
Proposition 3.4 (The one-dimensional selective p p p -value). Under data model (1) and null (5), u ( Q ) u(\mathbf{Q}) u ( Q ) is independent of ( Γ , H , P 2 X ) (\boldsymbol{\Gamma},\mathbf{H},\mathbf{P}_2\mathbf{X}) ( Γ , H , P 2 X ) . Consequently, given Γ \boldsymbol{\Gamma} Γ , P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and the clustering, the scaled statistic F = r − p − 1 ( r − 2 ) p r − p − 1 p u ( Q ) 1 − u ( Q ) F = \frac{r-p-1}{(r-2)p}\frac{r-p-1}{p}\frac{u(\mathbf{Q})}{1-u(\mathbf{Q})} F = ( r − 2 ) p r − p − 1 p r − p − 1 1 − u ( Q ) u ( Q ) has the F p , r − p − 1 F_{p,r-p-1} F p , r − p − 1 distribution truncated to the set S Γ = { r − p − 1 p cot 2 ϕ : ϕ ∈ S θ } S_{\boldsymbol{\Gamma}} = \left\{\frac{r-p-1}{p}\cot^2\phi: \phi\in S_{\theta}\right\} S Γ = { p r − p − 1 cot 2 ϕ : ϕ ∈ S θ } of values that reproduce the clusters, and p p o l a r , 1 d p_{\mathrm{polar},1\mathrm{d}} p polar , 1 d is the survival function of this truncated distribution evaluated at the observed value of F F F . Under the null, p p o l a r , 1 d p_{\mathrm{polar},1\mathrm{d}} p polar , 1 d is uniformly distributed conditional on the clustering.
The proof is in Appendix § 10 .§ 4 . Fixing Γ \boldsymbol{\Gamma} Γ is additional conditioning, like the direction in (6) and the two directions in (9): its distribution involves no unknown parameter, and we fix it only so that the resulting distribution is easy to characterize computationally. In terms of the data, moving along the path (17) keeps P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and the data in the directions orthogonal to the Fisher direction, and moves each tested observation along a line in the direction of the difference in cluster means. So p p o l a r , 1 d p_{\mathrm{polar},1\mathrm{d}} p polar , 1 d is the test of Yun and Barber (2023) applied to the projected data q \mathbf{q} q , with the rest of the data held fixed. Figure 3 (a) and Table A.1 in Appendix § 9 .§ 4 compare the three one-dimensional tests. Because it fixes Γ \boldsymbol{\Gamma} Γ , p p o l a r , 1 d p_{\mathrm{polar},1\mathrm{d}} p polar , 1 d uses less of the data than p p o l a r p_{\mathrm{polar}} p polar and has less power (§ 5 ).
Figure 3. Two ways to perturb the data, for n = 12 n = 12 n = 12 observations from one bivariate Gaussian split into K = 3 K = 3 K = 3 clusters by k k k -means; open circles are the cluster that is not tested. (a) The perturbation of Gao et al. [24 ] and Chen and Witten [14 ] slides the two tested clusters apart along ν \nu ν , so every perturbed data set lies on a line. (b) Our perturbation Q ↦ G i j ( ω ) Q \mathbf{Q} \mapsto G_{ij}(\omega)\mathbf{Q} Q ↦ G ij ( ω ) Q for one pair of rows ( i , j ) (i,j) ( i , j ) , where G i j ( ω ) G_{ij}(\omega) G ij ( ω ) rotates rows i i i and j j j of Q \mathbf{Q} Q by the angle ω \omega ω (§ 4.1 ): each tested observation moves on an ellipse, purple where k k k -means still returns the tested clusters. (c) The angles ω \omega ω on the unit circle, purple where k k k -means returns the tested clusters, with an accepted proposal (filled triangle) and a rejected proposal (open triangle); the observed data are at ω = 0 \omega= 0 ω = 0 . (d) The data at the accepted angle, colored by the clusters that k k k -means returns on them. (e) The same at the rejected angle; the ringed observations have changed cluster.
Computing the selective p p p -values
Both selective p p p -values, p p o l a r p_{\mathrm{polar}} p polar in (13) and p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d in (19) , are ratios of integrals over sets that the clustering algorithm defines. By Proposition 3.3 , p p o l a r p_{\mathrm{polar}} p polar is the fraction of the volume of S Q \mathcal{S}_{Q} S Q on which u ( Q ) ≥ u ( Q o b s ) u(\mathbf{Q}) \ge u(\mathbf{Q}_{\mathrm{obs}}) u ( Q ) ≥ u ( Q obs ) , and by Proposition 3.4 , p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d is a ratio of two masses of a truncated F F F distribution over S Γ \mathcal{S}_{\Gamma} S Γ . For a general clustering algorithm, neither set has a closed form, but we can check whether a given point belongs to it by running the algorithm once: Q ∈ S Q \mathbf{Q} \in\mathcal{S}_{Q} Q ∈ S Q exactly when the algorithm, applied to x ′ ( Q ) \mathbf{x}'(\mathbf{Q}) x ′ ( Q ) , returns C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 . Sections 4.1 to 4.3 use only this check, and so apply to any algorithm. Section 4.4 shows what more can be done for k k k -means and hierarchical clustering.
Monte Carlo sampling for any clustering algorithm
A direct approach, following Gao et al. [24 ] , is to estimate the two integrals in (14) by importance sampling. We draw Q 1 , … , Q B \mathbf{Q}_1,\ldots,\mathbf{Q}_B Q 1 , … , Q B independently from a proposal distribution on V \mathcal{V} V with density η \eta η relative to the uniform distribution, run the clustering algorithm on each perturbed data set x ′ ( Q b ) \mathbf{x}'(\mathbf{Q}_b) x ′ ( Q b ) , and estimate
p ^ I S = ∑ b = 1 B w b 1 { Q b ∈ S Q } 1 { u ( Q b ) ≥ u ( Q o b s ) } ∑ b = 1 B w b 1 { Q b ∈ S Q } , w b = 1 η ( Q b ) . (20) \widehat{p}_{\mathrm{IS}} =
\frac{\sum_{b=1}^{B} w_b \mathbf{1}\{\mathbf{Q}_b \in\mathcal{S}_{Q}\}\mathbf{1}\{u(\mathbf{Q}_b) \ge u(\mathbf{Q}_{\mathrm{obs}})\}}
{\sum_{b=1}^{B} w_b \mathbf{1}\{\mathbf{Q}_b \in\mathcal{S}_{Q}\}},
\qquad
w_b = \frac{1}{\eta(\mathbf{Q}_b)}. \tag*{(20)} p IS = ∑ b = 1 B w b 1 { Q b ∈ S Q } ∑ b = 1 B w b 1 { Q b ∈ S Q } 1 { u ( Q b ) ≥ u ( Q obs )} , w b = η ( Q b ) 1 . (20)
For p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d the random quantity is one angle and this approach is workable (Section 4.3). For p p o l a r p_{\mathrm{polar}} p polar the random quantity is the whole polar factor Q \mathbf{Q} Q , which has ( r − 1 ) p − p ( p + 1 ) / 2 (r-1)p-p(p+1)/2 ( r − 1 ) p − p ( p + 1 ) /2 free coordinates, and S Q \mathcal{S}_{Q} S Q is typically a small region around Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs . Points drawn uniformly from V \mathcal{V} V (η = 1 \eta=1 η = 1 ) rarely land in S Q \mathcal{S}_{Q} S Q , so both sums in (20) are usually zero. A proposal concentrated near Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs has the opposite problem. Its density is small away from Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs , so the few draws that land in S Q \mathcal{S}_{Q} S Q far from Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs get much larger weights than the others, and p ^ I S \widehat{p}_{\mathrm{IS}} p IS is close to the indicator 1 { u ( Q b ) ≥ u ( Q o b s ) } \mathbf{1}\{u(\mathbf{Q}_b) \ge u(\mathbf{Q}_{\mathrm{obs}})\} 1 { u ( Q b ) ≥ u ( Q obs )} of one or two draws. It is then close to 0 or to 1 depending on which side of u ( Q o b s ) u(\mathbf{Q}_{\mathrm{obs}}) u ( Q obs ) those draws happen to fall, and the values close to 0 are false rejections.
An alternative is to draw Q 1 , … , Q B \mathbf{Q}_1,\ldots,\mathbf{Q}_B Q 1 , … , Q B from a Markov chain whose stationary distribution is the uniform distribution on S Q \mathcal{S}_{Q} S Q , such as a random-walk Metropolis chain or Hamiltonian Monte Carlo (Neal [48 ] ). Every draw then lies in S Q \mathcal{S}_{Q} S Q , and the proposal is the target itself, so all weights in (20) are equal and the estimate becomes the fraction of draws with u ( Q b ) ≥ u ( Q o b s ) u(\mathbf{Q}_b) \ge u(\mathbf{Q}_{\mathrm{obs}}) u ( Q b ) ≥ u ( Q obs ) . Used naively, however, this estimate is valid only as B → ∞ B \to\infty B → ∞ , and that limit is far away here. The chain moves slowly through S Q \mathcal{S}_{Q} S Q , and its draws are strongly correlated with Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs and with each other, so the resulting p p p -values are anticonservative in our experiments. For example, the selective Type I error at level 0.05 reaches 0.19 at n = 200 n=200 n = 200 and p = 10 p=10 p = 10 (Appendix C.2).
We therefore combine a Markov chain with the construction of Besag and Clifford [7 ] , which turns a chain into an exact p p p -value however slowly it mixes (Section 4.2). The construction needs a Markov kernel that is reversible with respect to the uniform distribution on S Q \mathcal{S}_{Q} S Q . Since each new point must again have orthonormal columns, we propose moves by Givens rotations (Golub and Van Loan [25 ] , Section 5.1.8). Let a 1 , … , a r − 1 \mathbf{a}_1,\ldots,\mathbf{a}_{r-1} a 1 , … , a r − 1 be a fixed orthonormal basis of the range of P 0 + P 1 \mathbf{P}_0+\mathbf{P}_1 P 0 + P 1 . For 1 ≤ i < j ≤ r − 1 1 \le i < j \le r-1 1 ≤ i < j ≤ r − 1 and an angle ω \omega ω , the Givens rotation
G i j ( ω ) = I n + ( cos ω − 1 ) ( a i a i T + a j a j T ) + sin ω ( a j a i T − a i a j T ) (21) \mathbf{G}_{ij}(\omega) = \mathbf{I}_n + (\cos\omega- 1)(\mathbf{a}_i\mathbf{a}_i^{\mathsf{T}} + \mathbf{a}_j\mathbf{a}_j^{\mathsf{T}}) + \sin\omega(\mathbf{a}_j\mathbf{a}_i^{\mathsf{T}} - \mathbf{a}_i\mathbf{a}_j^{\mathsf{T}}) \tag*{(21)} G ij ( ω ) = I n + ( cos ω − 1 ) ( a i a i T + a j a j T ) + sin ω ( a j a i T − a i a j T ) (21)
rotates the plane spanned by a i \mathbf{a}_i a i and a j \mathbf{a}_j a j by the angle ω \omega ω and leaves every vector orthogonal to that plane unchanged. Since G i j ( ω ) \mathbf{G}_{ij}(\omega) G ij ( ω ) is orthogonal and maps the range of P 0 + P 1 \mathbf{P}_0+\mathbf{P}_1 P 0 + P 1 to itself, G i j ( ω ) Q ∈ V \mathbf{G}_{ij}(\omega)\mathbf{Q} \in\mathcal{V} G ij ( ω ) Q ∈ V whenever Q ∈ V \mathbf{Q} \in\mathcal{V} Q ∈ V . In the coordinates A T Q \mathbf{A}^{\mathsf{T}}\mathbf{Q} A T Q , with A = ( a 1 , … , a r − 1 ) \mathbf{A}=(\mathbf{a}_1,\ldots,\mathbf{a}_{r-1}) A = ( a 1 , … , a r − 1 ) , the rotation changes only rows i i i and j j j . As ω \omega ω varies, each tested observation moves along an ellipse and the untested observations do not move (Figure 3 (b) and (c)). We call the following kernel K \mathcal{K} K the random Givens kernel . Given the current point Q \mathbf{Q} Q and a number of steps L L L :
draw a step size ϵ \epsilon ϵ with log ϵ \log\epsilon log ϵ uniform on [ log 10 − 3 , 0 ] [\log10^{-3},0] [ log 1 0 − 3 , 0 ] , independently of Q \mathbf{Q} Q ;
repeat L L L times: (a) draw a pair i < j i<j i < j uniformly at random and an angle ω ∼ N ( 0 , ( π ϵ ) 2 ) \omega\sim\mathcal{N}(0,(\pi\epsilon)^2) ω ∼ N ( 0 , ( π ϵ ) 2 ) ; (b) set Q ′ = G i j ( ω ) Q \mathbf{Q}'=\mathbf{G}_{ij}(\omega)\mathbf{Q} Q ′ = G ij ( ω ) Q and run the clustering algorithm on x ′ ( Q ′ ) = P 2 x + Q ′ H ( x ) \mathbf{x}'(\mathbf{Q}')=\mathbf{P}_2\mathbf{x}+\mathbf{Q}'\mathbf{H}(\mathbf{x}) x ′ ( Q ′ ) = P 2 x + Q ′ H ( x ) ; (c) if the algorithm returns C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 , set Q = Q ′ \mathbf{Q}=\mathbf{Q}' Q = Q ′ ; otherwise keep Q \mathbf{Q} Q .
Drawing ϵ \epsilon ϵ from a range of scales lets the chain take short steps where S Q \mathcal{S}_{\mathbf{Q}} S Q is narrow and long steps where it is wide, without tuning ϵ \epsilon ϵ on the observed data, which the construction of § 4.2 does not allow. One application of K \mathcal{K} K runs the clustering algorithm L L L times. Figure 3 (d) and (e) show an accepted and a rejected proposal on a small example.
Proposition 4.1 (The random Givens kernel is reversible). For every L ≥ 1 L\geq1 L ≥ 1 , the random Givens kernel is reversible with respect to the uniform distribution on S Q \mathcal{S}_{\mathbf{Q}} S Q .
The proof is in Appendix § 10 .§ 5 . The reason is that the proposal Q ↦ G i j ( ω ) Q \mathbf{Q}\mapsto\mathbf{G}_{ij}(\omega)\mathbf{Q} Q ↦ G ij ( ω ) Q is a random rotation that is as likely as its inverse, because G i j ( ω ) − 1 = G i j ( − ω ) \mathbf{G}_{ij}(\omega)^{-1}=\mathbf{G}_{ij}(-\omega) G ij ( ω ) − 1 = G ij ( − ω ) and ω \omega ω is symmetric about zero. Such a proposal does not change the uniform distribution on V \mathcal{V} V , and keeping only the proposals that reproduce the clusters restricts it to S Q \mathcal{S}_{\mathbf{Q}} S Q . The same argument applies to any random rotation with this symmetry. One example is the Cayley random walk, which rotates all r − 1 r-1 r − 1 coordinates at once by the Cayley transform of a random skew-symmetric matrix (Wen and Yin (2013)); it is described in Appendix § 10 .§ 5 . Both kernels give exact p p p -values, and in a pilot comparison (Appendix § 11 .§ 4 ) the random Givens kernel had at least the power of the Cayley random walk at a lower cost per p p p -value.
An exact p p p -value from a Markov chain
Besag and Clifford [7 ] showed how to obtain an exact p p p -value from a reversible Markov chain without waiting for it to mix: place the observed point at a uniformly random position along a path of the chain and use its rank on that path. Let K \mathcal{K} K be the random Givens kernel of § 4.1 . Build a path of length M + 1 M+1 M + 1 as follows.
Draw J J J uniformly from { 0 , 1 , … , M } \{0,1,\ldots,M\} { 0 , 1 , … , M } and set Q J = Q o b s \mathbf{Q}_J=\mathbf{Q}_{\mathrm{obs}} Q J = Q obs .
Run the chain forward from Q J \mathbf{Q}_J Q J : Q j + 1 = K ( Q j ) \mathbf{Q}_{j+1}=\mathcal{K}(\mathbf{Q}_j) Q j + 1 = K ( Q j ) for j = J , … , M − 1 j=J,\ldots,M-1 j = J , … , M − 1 .
Run the chain backward from Q J \mathbf{Q}_J Q J : Q j − 1 = K ( Q j ) \mathbf{Q}_{j-1}=\mathcal{K}(\mathbf{Q}_j) Q j − 1 = K ( Q j ) for j = J , … , 1 j=J,\ldots,1 j = J , … , 1 .
The backward run uses the same kernel as the forward run because K \mathcal{K} K is reversible. With u j = u ( Q j ) u_j=u(\mathbf{Q}_j) u j = u ( Q j ) , the Monte Carlo version of p p o l a r p_{\mathrm{polar}} p polar is the randomized rank of u J u_J u J among u 0 , … , u M u_0,\ldots,u_M u 0 , … , u M ,
p ^ p o l a r = 1 M + 1 ( ∑ j = 0 M 1 { u j > u J } + ξ ∑ j = 0 M 1 { u j = u J } ) , ξ ∼ Uniform ( 0 , 1 ) , (22) \widehat{p}_{\mathrm{polar}}=\frac{1}{M+1}\left(\sum_{j=0}^{M}\mathbf{1}\{u_j>u_J\}+\xi\sum_{j=0}^{M}\mathbf{1}\{u_j=u_J\}\right),\qquad\xi\sim\operatorname{Uniform}(0,1), \tag*{(22)} p polar = M + 1 1 ( j = 0 ∑ M 1 { u j > u J } + ξ j = 0 ∑ M 1 { u j = u J } ) , ξ ∼ Uniform ( 0 , 1 ) , (22)
with ξ \xi ξ drawn independently of the path to break ties.
Algorithm 1 The selective test $\hat{p}_{\mathrm{polar}}$ for any clustering algorithm
Require: data $\mathbf{x} \in \mathbb{R}^{n \times p}$, clustering algorithm $\mathcal{C}$, tested clusters $\widehat{C}_1,\widehat{C}_2 \in \mathcal{C}(\mathbf{x})$ (fixed in advance, or each pair tested in turn), path length $M$, number of steps $L$
1: Form $\mathbf{P}_0,\mathbf{P}_1,\mathbf{P}_2$ from $\widehat{C}_1$ and $\widehat{C}_2$, and an orthonormal basis $\mathbf{a}_1,\ldots,\mathbf{a}_{r-1}$ of the range of $\mathbf{P}_0+\mathbf{P}_1$
2: $\mathbf{H} \leftarrow (\mathbf{x}^{\mathsf{T}}(\mathbf{P}_0+\mathbf{P}_1)\mathbf{x})^{1/2}$ and $\mathbf{Q}_{\mathrm{obs}} \leftarrow (\mathbf{P}_0+\mathbf{P}_1)\mathbf{x}\mathbf{H}^{-1}$ $\triangleright$ polar decomposition, {xref}`Section 3.1`
3: Draw $J$ uniformly from $\{0,1,\ldots,M\}$ and set $\mathbf{Q}_J \leftarrow \mathbf{Q}_{\mathrm{obs}}$
4: for $j=J,J+1,\ldots,M-1$ do
5: $\mathbf{Q}_{j+1} \leftarrow \operatorname{RandomGivens}(\mathbf{Q}_j)$ $\triangleright$ forward
6: end for
7: for $j=J,J-1,\ldots,1$ do
8: $\mathbf{Q}_{j-1} \leftarrow \operatorname{RandomGivens}(\mathbf{Q}_j)$ $\triangleright$ backward
9: end for
10: $u_j \leftarrow \lVert\mathbf{P}_0\mathbf{Q}_j\rVert_{\mathrm{F}}^2$ for $j=0,\ldots,M$, and draw $\xi \sim \operatorname{Uniform}(0,1)$
Ensure: $\hat{p}_{\mathrm{polar}}=\frac{1}{M+1}\left(\sum_{j=0}^{M}1\{u_j>u_J\}+\xi\sum_{j=0}^{M}1\{u_j=u_J\}\right)$
11: function $\operatorname{RandomGivens}(\mathbf{Q})$ $\triangleright$ the random Givens kernel $\mathcal{K}$
12: Draw $\log\epsilon$ uniformly on $[\log 10^{-3},0]$
13: for $\ell=1,\ldots,L$ do
14: Draw $i<j$ uniformly from $\{1,\ldots,r-1\}$ and $\omega\sim\mathcal{N}(0,(\pi\epsilon)^2)$
15: $\mathbf{Q}'\leftarrow\mathbf{G}_{ij}(\omega)\mathbf{Q}$ $\triangleright$ Givens rotation {xref}`(21)`
16: if $\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{P}_2\mathbf{x}+\mathbf{Q}'\mathbf{H})$ then
17: $\mathbf{Q}\leftarrow\mathbf{Q}'$
18: end if
19: end for
20: return $\mathbf{Q}$
21: end function
Proposition 4.2 (The Monte Carlo p p p -value is exact). Suppose that the kernel K \mathcal{K} K is reversible with respect to the uniform distribution on S Q \mathcal{S}_{\mathbf{Q}} S Q , and that K \mathcal{K} K and M M M depend on the data only through P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and the clustering. Under data model (1) and null (5) ,
P H 0 ′ ( p ^ p o l a r ≤ α ∣ C ^ 1 , C ^ 2 ∈ C ( X ) , P 2 X , H ) = α \mathbb{P}_{H'_0}\left(\hat{p}_{\mathrm{polar}}\leq\alpha\mid\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X}),\mathbf{P}_2\mathbf{X},\mathbf{H}\right)=\alpha P H 0 ′ ( p ^ polar ≤ α ∣ C 1 , C 2 ∈ C ( X ) , P 2 X , H ) = α for all α ∈ [ 0 , 1 ] \alpha\in[0,1] α ∈ [ 0 , 1 ] , for every M ≥ 1 M\geq1 M ≥ 1 , however slowly the chain mixes.
The proof is in Appendix § 10 .§ 6 . Proposition 4.2 says that (22) gives a valid test for any M M M , any L L L , and any reversible kernel, in the sense that it controls the selective Type I error (3) . Different choices, however, lead to different power when H 0 ′ H'_0 H 0 ′ does not hold. Power grows with the path length M M M and levels off (Appendix § 11 .§ 3 ), and it grows with how far the chain moves between consecutive points of the path, which increases with L L L and with the size of the accepted steps. The path then spreads u 0 , … , u M u_0,\ldots,u_M u 0 , … , u M over a wider range, so that under the alternative the observed u J u_J u J can stand out at the top of that range. At the other extreme, a kernel that never moves gives p ^ p o l a r = ξ \hat{p}_{\mathrm{polar}}=\xi p ^ polar = ξ , which is exact and has no power. The one restriction is that these choices may not depend on Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs : tuning ϵ \epsilon ϵ on trial moves from Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs can break exactness (Appendix § 11 .§ 3 ), whereas drawing ϵ \epsilon ϵ from a fixed distribution, as in § 4.1 , does not. We summarize the test based on p ^ p o l a r \hat{p}_{\mathrm{polar}} p ^ polar in Algorithm 1, which runs the clustering algorithm L L L times at each of the M M M steps of the path.
The one-dimensional test for any clustering algorithm
Recall that for p p o l a r , 1 d p_{\mathrm{polar},1\mathrm{d}} p polar , 1 d only the angle is random, and recall the set S θ S_\theta S θ in (18) of angles at which the clustering returns the tested clusters. Under the null, the angle has density f ( ϕ ) ∝ cos p − 1 ϕ sin r − p − 2 ϕ f(\phi) \propto\cos^{p-1}\phi\sin^{r-p-2}\phi f ( ϕ ) ∝ cos p − 1 ϕ sin r − p − 2 ϕ on ( 0 , π / 2 ) (0,\pi/2) ( 0 , π /2 ) , which is the Beta( p / 2 , ( r − 1 − p ) / 2 ) (p/2,(r-1-p)/2) ( p /2 , ( r − 1 − p ) /2 ) distribution of u ( Q ) = cos 2 ϕ u(\mathbf{Q})=\cos^2\phi u ( Q ) = cos 2 ϕ (Proposition 3.2 ). Given Γ \boldsymbol{\Gamma} Γ , P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and the clustering, the angle therefore has density
f ( ϕ ) 1 { ϕ ∈ S θ } ∫ S θ f ( ψ ) d ψ (23) \frac{f(\phi)\mathbf{1}\{\phi\in S_\theta\}}{\int_{S_\theta}f(\psi)\,\mathrm{d}\psi} \tag*{(23)} ∫ S θ f ( ψ ) d ψ f ( ϕ ) 1 { ϕ ∈ S θ } (23)
and since a smaller angle means a larger T 2 T^2 T 2 , Proposition 3.4 says
p p o l a r , 1 d = ∫ S θ ∩ ( 0 , θ ] f ( ϕ ) d ϕ ∫ S θ f ( ϕ ) d ϕ . (24) p_{\mathrm{polar},1\mathrm{d}}=\frac{\int_{S_\theta\cap(0,\theta]}f(\phi)\,\mathrm{d}\phi}{\int_{S_\theta}f(\phi)\,\mathrm{d}\phi}. \tag*{(24)} p polar , 1 d = ∫ S θ f ( ϕ ) d ϕ ∫ S θ ∩ ( 0 , θ ] f ( ϕ ) d ϕ . (24)
We compute (24) with the construction of § 4.2 . Algorithm C.1 in Appendix § 11 .§ 1 is Algorithm 1 with two changes. First, the path moves the angle ϕ \phi ϕ in ( 0 , π / 2 ) (0,\pi/2) ( 0 , π /2 ) instead of the polar factor Q \mathbf{Q} Q . Second, each step is a Metropolis step for the density (23) : it proposes a nearby angle, accepts it with the usual density ratio, and keeps it only if the clustering returns the tested clusters. This step is reversible with respect to (23) , so the resulting p p p -value is exactly uniform under the null by the argument of Proposition 4.2 . Each step runs the clustering only if the proposed angle passes the density check.
Alternatives exist, such as a slice sampler with shrinkage (Neal [47 ] ), which is also reversible with respect to (23) , and importance sampling as in Gao et al. [24 ] , with the angle drawn from a mixture of f f f and a normal distribution centered at θ \theta θ . In our preliminary experiments, the slice sampler gave similar p p p -values at about ten times the number of clustering runs. Importance sampling agreed with the exact test in Figure 1 , but it is consistent rather than exact, and it was unreliable when θ \theta θ was far in the tail of f f f : with well-separated clusters, 2,000 draws had an effective sample size of 2 to 5.
Extensions to k k k -means and hierarchical clustering
k k k -means: closed-form constraints from the trajectory. Algorithms 1 and C.1 apply to selective inference after any clustering algorithm. For hierarchical and k k k -means clustering, Gao et al. [24 ] and Chen and Witten [14 ] also gave closed-form descriptions of their truncation sets. For k k k -means, S Q S_{\mathbf{Q}} S Q has no closed form, because many sequences of intermediate assignments end in the same final clusters (Appendix § 10 ). Following Chen and Witten [14 ] , however, we can condition on the whole sequence of assignments made by Lloyd’s algorithm. The set of polar factors that reproduce this sequence then has a closed form, and so does its intersection with any rotation of Q \mathbf{Q} Q , which gives a kernel that needs no rejections and no step size.
Lloyd’s algorithm starts from the centroids m ℓ ( 0 ) = x ℓ ′ \mathbf{m}_{\ell}^{(0)}=\mathbf{x}_{\ell'} m ℓ ( 0 ) = x ℓ ′ , ℓ = 1 , … , K \ell=1,\ldots,K ℓ = 1 , … , K , for fixed indices ℓ = ( ℓ 1 , … , ℓ K ) \ell=(\ell_1,\ldots,\ell_K) ℓ = ( ℓ 1 , … , ℓ K ) , and alternates two steps until the assignments stop changing: assign each observation to its nearest centroid, giving labels c i ( t ) c_i^{(t)} c i ( t ) , and recompute each centroid as the mean of the observations assigned to it. Write τ = ( c ( 0 ) , … , c ( t max ) ) \tau=(c^{(0)},\ldots,c^{(t_{\max})}) τ = ( c ( 0 ) , … , c ( t m a x ) ) for the observed sequence of assignments. For a polar factor Q \mathbf{Q} Q , let m ℓ ( t ) ( Q ) \mathbf{m}_{\ell}^{(t)}(\mathbf{Q}) m ℓ ( t ) ( Q ) be the centroids of x ′ ( Q ) \mathbf{x}'(\mathbf{Q}) x ′ ( Q ) under the observed labels,
m ℓ ( 0 ) ( Q ) = x ℓ ′ ( Q ) , m ℓ ( t ) ( Q ) = 1 ∣ { a : c a ( t − 1 ) = ℓ } ∣ ∑ a : c a ( t − 1 ) = ℓ x a ′ ( Q ) , t ≥ 1. \mathbf{m}_{\ell}^{(0)}(\mathbf{Q})=\mathbf{x}'_{\ell}(\mathbf{Q}),\qquad
\mathbf{m}_{\ell}^{(t)}(\mathbf{Q})=
\frac{1}{\lvert\{a:c_a^{(t-1)}=\ell\}\rvert}
\sum_{a:c_a^{(t-1)}=\ell}\mathbf{x}'_a(\mathbf{Q}),\quad t\geq1. m ℓ ( 0 ) ( Q ) = x ℓ ′ ( Q ) , m ℓ ( t ) ( Q ) = ∣{ a : c a ( t − 1 ) = ℓ }∣ 1 a : c a ( t − 1 ) = ℓ ∑ x a ′ ( Q ) , t ≥ 1.
Lloyd’s algorithm applied to x ′ ( Q ) \mathbf{x}'(\mathbf{Q}) x ′ ( Q ) produces the same sequence τ \tau τ exactly when, at every iteration, every observation is closer to its observed centroid than to the others:
∥ x i ′ ( Q ) − m c i ( t ) ( t ) ( Q ) ∥ 2 2 ≤ ∥ x i ′ ( Q ) − m ℓ ( t ) ( Q ) ∥ 2 2 for all t ≤ t max , i ≤ n , ℓ ≠ c i ( t ) . (25) \left\|\mathbf{x}'_i(\mathbf{Q})-\mathbf{m}^{(t)}_{c_i^{(t)}}(\mathbf{Q})\right\|_2^2 \le\left\|\mathbf{x}'_i(\mathbf{Q})-\mathbf{m}^{(t)}_{\ell}(\mathbf{Q})\right\|_2^2 \quad\text{for all } t \le t_{\max},\ i \le n,\ \ell\ne c_i^{(t)}. \tag*{(25)} x i ′ ( Q ) − m c i ( t ) ( t ) ( Q ) 2 2 ≤ x i ′ ( Q ) − m ℓ ( t ) ( Q ) 2 2 for all t ≤ t m a x , i ≤ n , ℓ = c i ( t ) . (25)
Let S Q , τ S_{\mathbf{Q},\tau} S Q , τ be the set of Q ∈ V \mathbf{Q} \in\mathcal{V} Q ∈ V that satisfy (25) . It is contained in S Q S_{\mathbf{Q}} S Q , because the same sequence of assignments ends in the same clusters, and § 3.3 to § 4.2 hold with S Q , τ S_{\mathbf{Q},\tau} S Q , τ in place of S Q S_{\mathbf{Q}} S Q .
Proposition 4.3 (The trajectory event is quadratic in Q \mathbf{Q} Q ). For each t t t , i i i , and ℓ ≠ c i ( t ) \ell\ne c_i^{(t)} ℓ = c i ( t ) , the difference
g t , i , ℓ ( Q ) = ∥ x i ′ ( Q ) − m c i ( t ) ( t ) ( Q ) ∥ 2 2 − ∥ x i ′ ( Q ) − m ℓ ( t ) ( Q ) ∥ 2 2 (26) g_{t,i,\ell}(\mathbf{Q})=\left\|\mathbf{x}'_i(\mathbf{Q})-\mathbf{m}^{(t)}_{c_i^{(t)}}(\mathbf{Q})\right\|_2^2-\left\|\mathbf{x}'_i(\mathbf{Q})-\mathbf{m}^{(t)}_{\ell}(\mathbf{Q})\right\|_2^2 \tag*{(26)} g t , i , ℓ ( Q ) = x i ′ ( Q ) − m c i ( t ) ( t ) ( Q ) 2 2 − x i ′ ( Q ) − m ℓ ( t ) ( Q ) 2 2 (26) is a quadratic polynomial in the entries of Q \mathbf{Q} Q , with coefficients determined by P 2 x \mathbf{P}_{2\mathbf{x}} P 2 x , H \mathbf{H} H , and τ \tau τ . Hence
S Q , τ = { Q ∈ V : g t , i , ℓ ( Q ) ≤ 0 for all t , i , ℓ ≠ c i ( t ) } S_{\mathbf{Q},\tau}=\{\mathbf{Q}\in\mathcal{V}:g_{t,i,\ell}(\mathbf{Q})\le0\text{ for all }t,i,\ell\ne c_i^{(t)}\} S Q , τ = { Q ∈ V : g t , i , ℓ ( Q ) ≤ 0 for all t , i , ℓ = c i ( t ) } is defined by the ( t max + 1 ) n ( K − 1 ) (t_{\max}+1)n(K-1) ( t m a x + 1 ) n ( K − 1 ) quadratic inequalities g t , i , ℓ ( Q ) ≤ 0 g_{t,i,\ell}(\mathbf{Q})\le0 g t , i , ℓ ( Q ) ≤ 0 .
The reason is that x ′ ( Q ) = P 2 x + Q H \mathbf{x}'(\mathbf{Q})=\mathbf{P}_{2\mathbf{x}}+\mathbf{Q}\mathbf{H} x ′ ( Q ) = P 2 x + QH is linear in Q \mathbf{Q} Q apart from a constant, and with the labels fixed by τ \tau τ each centroid is a fixed average of rows of x ′ ( Q ) \mathbf{x}'(\mathbf{Q}) x ′ ( Q ) , so each squared distance is quadratic (Appendix § 10 ). The quadratic structure also describes S Q , τ S_{\mathbf{Q},\tau} S Q , τ along any curve on which Q \mathbf{Q} Q rotates.
Proposition 4.4 (The trajectory event along a rotation). Let Q ( ω ) = D 0 + cos ω D 1 + sin ω D 2 \mathbf{Q}(\omega)=\mathbf{D}_0+\cos\omega\mathbf{D}_1+\sin\omega\mathbf{D}_2 Q ( ω ) = D 0 + cos ω D 1 + sin ω D 2 be a curve in V \mathcal{V} V with fixed n × p n\times p n × p matrices D 0 , D 1 , D 2 \mathbf{D}_0,\mathbf{D}_1,\mathbf{D}_2 D 0 , D 1 , D 2 . Then along the curve each g t , i , ℓ g_{t,i,\ell} g t , i , ℓ in (26) has the form
g t , i , ℓ ( Q ( ω ) ) = β 1 cos 2 ω + β 2 sin 2 ω + β 3 cos ω + β 4 sin ω + β 5 , (27) g_{t,i,\ell}(\mathbf{Q}(\omega))=\beta_1\cos2\omega+\beta_2\sin2\omega+\beta_3\cos\omega+\beta_4\sin\omega+\beta_5, \tag*{(27)} g t , i , ℓ ( Q ( ω )) = β 1 cos 2 ω + β 2 sin 2 ω + β 3 cos ω + β 4 sin ω + β 5 , (27) with constants β 1 , … , β 5 \beta_1,\ldots,\beta_5 β 1 , … , β 5 that have closed forms. Unless it is constant, such a function has at most four zeros in [ 0 , 2 π ) [0,2\pi) [ 0 , 2 π ) , which are the roots of a quartic polynomial. Hence the set of ω \omega ω with Q ( ω ) ∈ S Q , τ \mathbf{Q}(\omega)\in S_{\mathbf{Q},\tau} Q ( ω ) ∈ S Q , τ is a finite union of intervals whose endpoints have closed forms.
Two curves of this form are the ones we need. The path of § 3.4 is one, with D 0 = Q ( I p − γ γ ⊤ ) \mathbf{D}_0=\mathbf{Q}(\mathbf{I}_p-\gamma\gamma^\top) D 0 = Q ( I p − γ γ ⊤ ) , D 1 = ν ˉ γ ⊤ \mathbf{D}_1=\bar{\nu}\gamma^\top D 1 = ν ˉ γ ⊤ , D 2 = dir ( P 1 q ) γ ⊤ \mathbf{D}_2=\operatorname{dir}(\mathbf{P}_1\mathbf{q})\gamma^\top D 2 = dir ( P 1 q ) γ ⊤ , and ω = ϕ \omega=\phi ω = ϕ . The Givens circle ω ↦ G i j ( ω ) Q \omega\mapsto\mathbf{G}_{ij}(\omega)\mathbf{Q} ω ↦ G ij ( ω ) Q of (21) is another. The proofs and the formulas for β 1 , … , β 5 \beta_1,\ldots,\beta_5 β 1 , … , β 5 are in Appendix § 10 .§ 2 . Proposition 4.4 has two consequences for computation.
The one-dimensional test needs no Monte Carlo. Conditioning on τ \tau τ , the set S θ S_\theta S θ in (24) is a finite union of intervals with known endpoints, so both integrals in (24) are differences of the Beta ( p / 2 , ( r − 1 − p ) / 2 ) \operatorname{Beta}(p/2,(r-1-p)/2) Beta ( p /2 , ( r − 1 − p ) /2 ) distribution function at cos 2 \cos^2 cos 2 of those endpoints.
A kernel without rejections or step sizes. On the Givens circle through the current Q \mathbf{Q} Q , we can compute the whole set S ω = { ω : G i j ( ω ) Q ∈ S Q , τ } S_\omega=\{\omega:\mathbf{G}_{ij}(\omega)\mathbf{Q}\in S_{\mathbf{Q},\tau}\} S ω = { ω : G ij ( ω ) Q ∈ S Q , τ } and draw ω \omega ω uniformly from it, instead of proposing one angle and checking it. This is a hit-and-run step ([56 , 6 ] ). It is reversible with respect to the uniform distribution on S Q , τ S_{\mathbf{Q},\tau} S Q , τ (Proposition B.1 in Appendix § 10 .§ 3 ), it moves at every step, and it never runs Lloyd’s algorithm.
Conditioning on τ \tau τ is conditioning on more than the event that the clusters are returned, and it costs power (Figure 1 (c) and § 5 ).
Extension to hierarchical clustering. We sought to follow Gao et al. [24 ] to obtain a more efficient computation for agglomerative hierarchical clustering cut at K K K clusters. Recall that Gao et al. [24 ] characterized the set S Σ \mathcal{S}_{\boldsymbol{\Sigma}} S Σ in (7) , defined through the perturbation X ′ ( ϕ ) \mathbf{X}'(\phi) X ′ ( ϕ ) , as the solution set of O ( n 2 ) O(n^2) O ( n 2 ) inequalities, each quadratic in ϕ \phi ϕ , obtained by conditioning on the order of all merges down to K K K clusters. A remarkable consequence is that, because conditioning on P 1 X \mathbf{P}_1\mathbf{X} P 1 X and P 2 X \mathbf{P}_2\mathbf{X} P 2 X fixes the distances between observations within the same cluster (Gao et al., [24 ] ), conditioning on the order of all merges is equivalent to conditioning on C ^ 1 , C ^ 2 ∈ C ( X ) \widehat{C}_1,\widehat{C}_2 \in\mathcal{C}(\mathbf{X}) C 1 , C 2 ∈ C ( X ) alone. The extra conditioning therefore costs no power, unlike in other problems where conditioning on more than the selection event does ([32 , 36 ] (Chen et al. 2023)).
This is no longer the case for our perturbation X ′ ( Q ) \mathbf{X}'(\mathbf{Q}) X ′ ( Q ) , even for the one-dimensional path X ′ ( Q Γ ( ϕ ) ) \mathbf{X}'(\mathbf{Q}_{\Gamma}(\phi)) X ′ ( Q Γ ( ϕ )) of § 3.4 . To preserve the sample covariance, X ′ ( Q ) \mathbf{X}'(\mathbf{Q}) X ′ ( Q ) and X ′ ( Q Γ ( ϕ ) ) \mathbf{X}'(\mathbf{Q}_{\Gamma}(\phi)) X ′ ( Q Γ ( ϕ )) rotate the observations within each cluster, so the distances between observations in the same cluster change, and many different merge orders end in the same tested clusters. Each merge of hierarchical clustering with a commonly used linkage, such as average linkage on squared Euclidean distances, can still be characterized by quadratic inequalities in Q \mathbf{Q} Q (or in ϕ \phi ϕ ), because it compares averages of squared distances between rows of X ′ ( Q ) \mathbf{X}'(\mathbf{Q}) X ′ ( Q ) . But conditioning on the merge order is now conditioning on more than the event that the clustering returns the tested clusters, and so it costs power. In fact, in a pilot study, the resulting test had almost no power. We therefore do not present that alternative, and we compute p p o l a r p_{\mathrm{polar}} p polar and p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d for hierarchical clustering with Algorithms 1 and C.1.
Simulation study
We simulate data from (1) , cluster them by k k k -means or by average-linkage hierarchical clustering with K = 3 K=3 K = 3 , and test the null hypothesis H 0 ′ H'_0 H 0 ′ in (5) for two of the estimated clusters at level α = 0.05 \alpha=0.05 α = 0.05 ; H 0 ′ H'_0 H 0 ′ implies the null H 0 H_0 H 0 in (2) , which the comparators test. We compare these p p p -values:
the naive p p p -value p n a i v e p_{\mathrm{naive}} p naive ;
our proposals p p o l a r p_{\mathrm{polar}} p polar (Algorithm 1) and p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d (Algorithm C.1), with M = 5,000 M=5{,}000 M = 5 , 000 and L = 2 L=2 L = 2 , and, for k k k -means, p p o l a r , 1 d t r a j p^{\mathrm{traj}}_{\mathrm{polar,1d}} p polar , 1d traj , which conditions on the sequence of assignments of Lloyd’s algorithm (§ 4.4 );
for k k k -means, the test of Chen and Witten [14 ] with σ ^ M E D I p 2 \widehat{\sigma}^{2}_{\mathrm{MEDI}p} σ MEDI p 2 (their median-based estimate), with the sample covariance Σ ^ s a m p l e \widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}} Σ sample of X \mathbf{X} X about its overall mean, or with the true Σ \boldsymbol{\Sigma} Σ : p C W ( σ ^ M E D I 2 I ) p_{\mathrm{CW}}(\widehat{\sigma}^{2}_{\mathrm{MEDI}}\mathbf{I}) p CW ( σ MEDI 2 I ) , p C W ( Σ ^ s a m p l e ) p_{\mathrm{CW}}(\widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}}) p CW ( Σ sample ) , and p C W ( Σ ) p_{\mathrm{CW}}(\boldsymbol{\Sigma}) p CW ( Σ ) ;
for hierarchical clustering, the test of Gao et al. [24 ] with σ ^ s a m p l e 2 I \widehat{\sigma}^{2}_{\mathrm{sample}}\mathbf{I} σ sample 2 I (with σ ^ s a m p l e 2 \widehat{\sigma}^{2}_{\mathrm{sample}} σ sample 2 estimated from the residuals of X \mathbf{X} X about its overall mean), Σ ^ s a m p l e \widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}} Σ sample , or Σ \boldsymbol{\Sigma} Σ : p G B W ( σ ^ s a m p l e 2 I ) p_{\mathrm{GBW}}(\widehat{\sigma}^{2}_{\mathrm{sample}}\mathbf{I}) p GBW ( σ sample 2 I ) , p G B W ( Σ ^ s a m p l e ) p_{\mathrm{GBW}}(\widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}}) p GBW ( Σ sample ) , and p G B W ( Σ ) p_{\mathrm{GBW}}(\boldsymbol{\Sigma}) p GBW ( Σ ) .
Appendix D reports every cell, two more comparators, and Leiden community detection.
Selective Type I error under the global null
Under the global null, every row of X \mathbf{X} X has mean zero in (1) , so H 0 H_0 H 0 is true whichever pair the clustering returns. The covariance Σ \boldsymbol{\Sigma} Σ is isotropic (Σ = I p \boldsymbol{\Sigma}=\mathbf{I}_p Σ = I p ), first-order autoregressive (Σ i j = 0.6 ∣ i − j ∣ \Sigma_{ij}=0.6^{|i-j|} Σ ij = 0. 6 ∣ i − j ∣ ), compound symmetric (Σ = 0.5 I p + 0.51 p 1 p T \boldsymbol{\Sigma}=0.5\mathbf{I}_p+0.5\mathbf{1}_p\mathbf{1}_p^{\mathsf{T}} Σ = 0.5 I p + 0.5 1 p 1 p T ), or spiked (Σ = I p + 5 v v T \boldsymbol{\Sigma}=\mathbf{I}_p+5\mathbf{v}\mathbf{v}^{\mathsf{T}} Σ = I p + 5 v v T with v = p − 1 / 2 1 p \mathbf{v}=p^{-1/2}\mathbf{1}_p v = p − 1/2 1 p ). For k k k -means, we simulate 600 data sets for each n ∈ { 30 , 50 , 100 , 200 } n\in\{30,50,100,200\} n ∈ { 30 , 50 , 100 , 200 } and p ∈ { 2 , 5 , 10 , 20 , 50 , 100 } p\in\{2,5,10,20,50,100\} p ∈ { 2 , 5 , 10 , 20 , 50 , 100 } with p ≤ n / 2 p\le n/2 p ≤ n /2 , apply k k k -means with K = 3 K=3 K = 3 from one fixed random initialization (§ 4.4 ), and compute the p p p -values for a randomly chosen pair of clusters with ∣ C ^ 1 ∣ + ∣ C ^ 2 ∣ ≥ p + 2 |\hat{C}_1| + |\hat{C}_2| \ge p + 2 ∣ C ^ 1 ∣ + ∣ C ^ 2 ∣ ≥ p + 2 , so that the pooled sample covariance in Hotelling’s T 2 T^2 T 2 is invertible. For hierarchical clustering, we simulate 600 data sets for n = 200 n = 200 n = 200 and p ∈ { 2 , 10 , 20 , 50 } p \in\{2, 10, 20, 50\} p ∈ { 2 , 10 , 20 , 50 } under the first three covariances, cut the average-linkage tree on squared Euclidean distances at K = 3 K = 3 K = 3 , and test every pair of clusters with at least three members and ∣ C ^ 1 ∣ + ∣ C ^ 2 ∣ ≥ p + 2 |\hat{C}_1| + |\hat{C}_2| \ge p + 2 ∣ C ^ 1 ∣ + ∣ C ^ 2 ∣ ≥ p + 2 .
Figure 4 (a) and Figure 5 (a) plot the quantiles of the null p p p -values, pooled over n n n and p p p , against those of the Uniform( 0 , 1 ) (0, 1) ( 0 , 1 ) distribution. Three patterns hold for both clustering algorithms and every Σ \boldsymbol{\Sigma} Σ : (i) the curve of p n a i v e p_{\mathrm{naive}} p naive lies far below the diagonal, so the naive test rejects true null hypotheses almost always; (ii) p C W ( σ ^ M E D 2 I ) p_{\mathrm{CW}}(\hat{\sigma}_{\mathrm{MED}}^2 I) p CW ( σ ^ MED 2 I ) and p G B W ( σ ^ s a m p l e 2 I ) p_{\mathrm{GBW}}(\hat{\sigma}_{\mathrm{sample}}^2 I) p GBW ( σ ^ sample 2 I ) are uniform under isotropic noise and stochastically smaller otherwise, because they assume Σ = σ 2 I p \boldsymbol{\Sigma} = \sigma^2 I_p Σ = σ 2 I p ; (iii) p p o l a r p_{\mathrm{polar}} p polar , p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d , and p p o l a r , 1 d t r a j p_{\mathrm{polar,1d}}^{\mathrm{traj}} p polar , 1d traj control the selective Type I error (3), as do p C W ( Σ ) p_{\mathrm{CW}}(\boldsymbol{\Sigma}) p CW ( Σ ) , p G B W ( Σ ) p_{\mathrm{GBW}}(\boldsymbol{\Sigma}) p GBW ( Σ ) , p C W ( Σ ^ s a m p l e ) p_{\mathrm{CW}}(\hat{\boldsymbol{\Sigma}}_{\mathrm{sample}}) p CW ( Σ ^ sample ) , and p G B W ( Σ ^ s a m p l e ) p_{\mathrm{GBW}}(\hat{\boldsymbol{\Sigma}}_{\mathrm{sample}}) p GBW ( Σ ^ sample ) ; the last two lead to conservative tests. In Appendix D, the unknown-scale test of Yun and Barber (2023) behaves like p C W ( σ ^ M E D 2 I ) p_{\mathrm{CW}}(\hat{\sigma}_{\mathrm{MED}}^2 I) p CW ( σ ^ MED 2 I ) , and data thinning (Neufeld et al. [49 ] ) with the sample covariance controls the selective Type I error but is conservative, rejecting about 2% of true null hypotheses at level 0.05.
Figure 4. k k k -means with K = 3 K = 3 K = 3 . (a) Quantile-quantile plots of the p p p -values under (1) with μ = 0 n × p \boldsymbol{\mu} = \mathbf{0}_{n \times p} μ = 0 n × p , stratified by Σ \boldsymbol{\Sigma} Σ and pooled over n n n and p p p . (b) The conditional power (29) at α = 0.05 \alpha= 0.05 α = 0.05 under (1) with μ \boldsymbol{\mu} μ defined in (28), n = 50 n = 50 n = 50 , and Σ = I p \boldsymbol{\Sigma} = I_p Σ = I p , stratified by p p 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 K = 3 K = 3 and n = 200 n = 200 n = 200 . (a) Quantile-quantile plots of the p p p -values under (1) with μ = 0 n × p \boldsymbol{\mu} = \mathbf{0}_{n \times p} μ = 0 n × p , stratified by Σ \boldsymbol{\Sigma} Σ and pooled over p p p . (b) The recovery probability (30) under (1) with μ \boldsymbol{\mu} μ defined in (28) and Σ = I p \boldsymbol{\Sigma} = \mathbf{I}_p Σ = I p . (c) The conditional power (29) at α = 0.05 \alpha= 0.05 α = 0.05 in the same settings, stratified by p p p , for the tests that control the selective Type I error under every Σ \boldsymbol{\Sigma} Σ ; at each δ \delta δ the tests are drawn side by side, with 95% Wilson intervals.
Conditional power and recovery probability
We generate data from (1) with three true clusters of equal size,
μ 1 = ⋯ = μ n / 3 = − δ e 1 , μ n / 3 + 1 = ⋯ = μ 2 n / 3 = 0 p , μ 2 n / 3 + 1 = ⋯ = μ n = δ e 1 , (28) \boldsymbol{\mu}_1 = \cdots= \boldsymbol{\mu}_{n/3} = -\delta\mathbf{e}_1,\qquad\boldsymbol{\mu}_{n/3+1} = \cdots= \boldsymbol{\mu}_{2n/3} = \mathbf{0}_p,\qquad\boldsymbol{\mu}_{2n/3+1} = \cdots= \boldsymbol{\mu}_n = \delta\mathbf{e}_1, \tag*{(28)} μ 1 = ⋯ = μ n /3 = − δ e 1 , μ n /3 + 1 = ⋯ = μ 2 n /3 = 0 p , μ 2 n /3 + 1 = ⋯ = μ n = δ e 1 , (28)
where e 1 \mathbf{e}_1 e 1 is the first standard basis vector. The clusters that the algorithm returns need not be true clusters, and a rejection is informative only when they are. Following Gao et al. [24 ] and Chen and Witten [14 ] , we therefore report two quantities over B B B simulated data sets with true clusters C 1 , C 2 , C 3 C_1,C_2,C_3 C 1 , C 2 , C 3 : the conditional power, the rejection rate among the data sets in which both tested clusters are true clusters, and the recovery probability, the fraction of data sets in which the two tested clusters are true clusters:
Conditional power = ∑ b = 1 B 1 { { C ^ 1 ( b ) , C ^ 2 ( b ) } ⊆ { C 1 , C 2 , C 3 } , p ( b ) ≤ α } ∑ b = 1 B 1 { { C ^ 1 ( b ) , C ^ 2 ( b ) } ⊆ { C 1 , C 2 , C 3 } } , (29) \text{Conditional power} =
\frac{\sum_{b=1}^{B} 1\left\{\{\widehat{C}^{(b)}_1,\widehat{C}^{(b)}_2\}\subseteq\{C_1,C_2,C_3\},\ p^{(b)}\leq\alpha\right\}}
{\sum_{b=1}^{B} 1\left\{\{\widehat{C}^{(b)}_1,\widehat{C}^{(b)}_2\}\subseteq\{C_1,C_2,C_3\}\right\}}, \tag*{(29)} Conditional power = ∑ b = 1 B 1 { { C 1 ( b ) , C 2 ( b ) } ⊆ { C 1 , C 2 , C 3 } } ∑ b = 1 B 1 { { C 1 ( b ) , C 2 ( b ) } ⊆ { C 1 , C 2 , C 3 } , p ( b ) ≤ α } , (29)
Recovery probability = 1 B ∑ b = 1 B 1 { { C ^ 1 ( b ) , C ^ 2 ( b ) } ⊆ { C 1 , C 2 , C 3 } } , (30) \text{Recovery probability}=\frac{1}{B}\sum_{b=1}^{B}1\left\{\{\widehat{C}^{(b)}_1,\widehat{C}^{(b)}_2\}\subseteq\{C_1,C_2,C_3\}\right\}, \tag*{(30)} Recovery probability = B 1 b = 1 ∑ B 1 { { C 1 ( b ) , C 2 ( b ) } ⊆ { C 1 , C 2 , C 3 } } , (30)
where p ( b ) p^{(b)} p ( b ) , C ^ 1 ( b ) \widehat{C}^{(b)}_1 C 1 ( b ) , and C ^ 2 ( b ) \widehat{C}^{(b)}_2 C 2 ( b ) are the p p p -value and the clusters tested in the b b b th data set. We show power only for the tests and covariances under which the test controls the selective Type I error in § 5.1 . For k k k -means, we simulate B = 1,000 B=1{,}000 B = 1 , 000 data sets for each cell of the null design and each δ ∈ { 3 , 4 , 5 , 6 , 7 , 8 , 10 , 12 } \delta\in\{3,4,5,6,7,8,10,12\} δ ∈ { 3 , 4 , 5 , 6 , 7 , 8 , 10 , 12 } ; for hierarchical clustering, B = 300 B=300 B = 300 for each δ ∈ { 4 , 6 , 8 , 10 , 12 } \delta\in\{4,6,8,10,12\} δ ∈ { 4 , 6 , 8 , 10 , 12 } .
Figure 4 (b) displays the conditional power of k k k -means at n = 50 n=50 n = 50 and Figure 4 (c) its recovery probability. The conditional power of every test increases with δ \delta δ . In every panel, p p o l a r p_{\mathrm{polar}} p polar has the highest conditional power among the tests that do not use Σ \boldsymbol{\Sigma} Σ (tied with p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d at p = 20 p=20 p = 20 and δ = 4 \delta=4 δ = 4 ), and it is also at least as powerful as p C W ( Σ ) p_{\mathrm{CW}}(\boldsymbol{\Sigma}) p CW ( Σ ) , which uses the true Σ \boldsymbol{\Sigma} Σ . This is possible because p C W ( Σ ) p_{\mathrm{CW}}(\boldsymbol{\Sigma}) p CW ( Σ ) conditions on more: on the whole sequence of assignments of Lloyd’s algorithm rather than only on the event that the clustering returns the tested pair, and on all of the data except one scalar. Each extra condition costs power, as the gaps from p p o l a r p_{\mathrm{polar}} p polar to p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d and from p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d to p p o l a r , 1 d t r a j p^{\mathrm{traj}}_{\mathrm{polar},1d} p polar , 1 d traj show. Using Σ ^ s a m p l e \widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}} Σ sample in p C W p_{\mathrm{CW}} p CW leads to the least powerful test, because the sample covariance about the overall mean includes the spread between the true cluster means, which grows with δ \delta δ , and so overstates Σ \boldsymbol{\Sigma} Σ along the direction that separates them. The recovery probability increases up to δ ≈ 7 \delta\approx7 δ ≈ 7 and then decreases slightly, because with collinear means some initializations converge to a partition that merges the middle cluster with an end cluster. At n = 100 n=100 n = 100 and 200 200 200 , the conditional power of p p o l a r p_{\mathrm{polar}} p polar exceeds 0.98 0.98 0.98 in every cell (Appendix § 12 ).
Figure 5 (b) and (c) display the recovery probability and the conditional power for hierarchical clustering under isotropic noise. Average linkage rarely returns two true clusters at δ = 4 \delta=4 δ = 4 . From δ = 6 \delta=6 δ = 6 on, p p o l a r p_{\mathrm{polar}} p polar rejects H 0 H_0 H 0 for every pair of true clusters, and p G B W ( Σ ) p_{\mathrm{GBW}}(\boldsymbol{\Sigma}) p GBW ( Σ ) , which knows Σ \boldsymbol{\Sigma} Σ , for almost every pair, while p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d and p G B W ( Σ ^ s a m p l e ) p_{\mathrm{GBW}}(\widehat{\boldsymbol{\Sigma}}_{\mathrm{sample}}) p GBW ( Σ sample ) are less powerful at δ = 6 \delta=6 δ = 6 , increasingly so as p p p grows.
Computing time. At n = 200 n=200 n = 200 , one value of p p o l a r p_{\mathrm{polar}} p polar takes a median of 2.1 seconds on one core of an Apple M4 Max processor at p = 2 p=2 p = 2 and 5.4 seconds at p = 100 p=100 p = 100 , and one value of p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d takes 1.0 to 2.3 seconds. The closed-form p p o l a r , 1 d t r a j p^{\mathrm{traj}}_{\mathrm{polar},1d} p polar , 1 d traj and the tests of Chen and Witten [14 ] take about 0.1 seconds (Figure D.8 in Appendix § 12 ). Each of the M = 5,000 M=5{,}000 M = 5 , 000 steps of the path reruns the clustering L = 2 L=2 L = 2 times.
Sensitivity to the Gaussian assumption
The validity of our proposals in § 3 depends on the rows of X \mathbf{X} X being Gaussian. We study the sensitivity to moderate deviations from this assumption in Appendix § 12 . The null data have n = 200 n = 200 n = 200 and compound-symmetric Σ \boldsymbol{\Sigma} Σ , and their rows are drawn from a multivariate t t t distribution, drawn as Gaussian and censored at zero, or drawn as Gaussian with p ≥ r p \ge r p ≥ r and reduced to their leading principal components before clustering, a common step in the analysis of high-dimensional data. The tests are less sensitive after k k k -means than after average linkage. After k k k -means, p p o l a r p_{\mathrm{polar}} p polar and p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d control the selective Type I error with t t t rows (5 or 10 degrees of freedom) and after the reduction to principal components, and reject at most 7.1% of true null hypotheses with 5% of the entries censored. After average linkage, they reject at most 7.4% with 5% censoring but are anticonservative with t t t rows.
Data application
We apply the proposed tests to three data sets spanning gene expression microarrays, text embeddings, and single-cell RNA sequencing: leukemia samples (§ 6.1 ) and drug reviews (§ 6.2 …
Table 6. The leukemia data of § 6.1 . Left: a UMAP embedding, colored by cluster, with the known label as the plotting symbol. Right: naive and selective p p 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.
tion 6.2), both clustered by k k k -means, and cells of the mouse brain, clustered by Leiden community detection (§ 6.3 ). We use the known labels in each data set to construct “alternative” data sets, whose observations come from several labeled groups, and, where possible, “null” data sets, whose observations come from a single group, and we evaluate the proposed tests against existing ones on them. We compute p p o l a r p_{\mathrm{polar}} p polar and p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d with M = 5,000 M = 5{,}000 M = 5 , 000 and L = 2 L = 2 L = 2 for every pair of estimated clusters, together with the naive test and, after k k k -means, the test of Chen and Witten [14 ] with Σ ^ s a m p l e \widehat{\Sigma}_{\mathrm{sample}} Σ sample . Because the tests require ∣ C ^ 1 ∣ + ∣ C ^ 2 ∣ ≥ p + 2 |\widehat{C}_1| + |\widehat{C}_2| \ge p + 2 ∣ C 1 ∣ + ∣ C 2 ∣ ≥ p + 2 , we reduce each data set to its leading principal components before clustering: ten for the leukemia data and twenty for the drug reviews and the mouse brain. The figures display each data set with UMAP (McInnes et al. [42 ] ).
Leukemia microarray data
Golub et al. [26 ] measured gene expression in 72 bone-marrow and blood samples from patients with acute lymphoblastic leukemia (ALL, 47 samples: 38 B-cell acute lymphoblastic leukemia and 9 T-cell acute lymphoblastic leukemia) or acute myeloid leukemia (AML, 25 samples). We preprocess the data as in Dudoit et al. [21 ] and keep the first ten principal components.
We apply k k k -means with K = 3 K = 3 K = 3 and obtain clusters of 24, 15, and 33 samples: cluster 1 is 96% AML, cluster 2 is 67% B-cell ALL, and cluster 3 is 85% B-cell ALL (Figure 6, left). The naive test rejects all three null hypotheses, with p p p -values below 10 − 8 10^{-8} 1 0 − 8 (Figure 6, right). The test p p o l a r p_{\mathrm{polar}} p polar rejects the two contrasts between the AML cluster and a B-cell ALL cluster (p = 0.005 p = 0.005 p = 0.005 and 0.015 0.015 0.015 ), but not the contrast between the two B-cell ALL clusters (p = 0.32 p = 0.32 p = 0.32 ), which we expect not to differ much biologically. Neither p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d nor the test of Chen and Witten [14 ] with Σ ^ s a m p l e \widehat{\Sigma}_{\mathrm{sample}} Σ sample rejects any of the three, including the two contrasts between the AML cluster and a B-cell ALL cluster. This reflects the power lost to extra conditioning and to a conservative covariance estimate, respectively.
Drug reviews
We apply clustering to group patients by their reviews of the drugs they take, in data collected by Gräßer et al. [28 ] on Drugs.com. Each review is labeled with the condition that the drug was taken for and with a rating from 1 to 10. We use a random sample of 3,000 reviews of at least 20 words and represent each review by its 384-dimensional text embedding from the pretrained model. bge-small-en-v1.5 (Xiao et al., 2024). For each data set below, the features are the first twenty principal components of the embeddings, computed from the reviews that are not in that data set. We construct an “alternative” data set by drawing 100 reviews each of drugs taken for birth control, depression, and acne, so n = 300 n = 300 n = 300 . We apply k k k -means with K = 3 K = 3 K = 3 and obtain clusters of 107, 106, and 87 reviews: cluster 1 is 93% depression, cluster 2 is 91% birth control, and cluster 3 is 98% acne (Figure 7 , top left). The naive test gives p p p -values below 10 − 66 10^{-66} 1 0 − 66 for all three pairs (Figure 7 , bottom). The test p p o l a r p_{\mathrm{polar}} p polar also rejects all three null hypotheses (p p p between 4.8 × 10 − 4 4.8 \times10^{-4} 4.8 × 1 0 − 4 and 0.005), as it should for drugs taken for three different conditions, and p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d rejects two of them. The test of Chen and Witten [14 ] with Σ ^ s a m p l e \hat{\boldsymbol{\Sigma}}_{\mathrm{sample}} Σ ^ sample rejects none (p p p between 0.15 and 0.97).
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 p 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.
We construct a “null” data set by drawing 75 reviews of drugs taken for birth control with a rating of 4 or less. We apply k k k -means with K = 2 K = 2 K = 2 and obtain clusters of 41 and 34 reviews. The naive test rejects (p = 8.7 × 10 − 14 p = 8.7 \times10^{-14} p = 8.7 × 1 0 − 14 ), but p p o l a r p_{\mathrm{polar}} p polar and p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d do not (p = 0.14 p = 0.14 p = 0.14 and 0.22$).
Single-cell RNA sequencing of the mouse brain
In single-cell RNA sequencing, biologists routinely cluster cells to find putative cell types and then test the clusters for differences in gene expression. Zeisel et al. (2015) sequenced cells from the mouse cortex and hippocampus and labeled each cell with a cell type and a finer subclass. For each data set below, we choose the 2,000 most variable genes and the first twenty principal components from the cells that are not in that data set and project the analyzed cells onto them. We cluster with Leiden community detection (Traag et al., [58 ] ) on the graph that joins each cell to its 15 nearest neighbors, with the resolution fixed at 0.5. No other selective test applies to this clustering, so we compare our tests with the naive test only.
We construct an “alternative” data set by drawing 60 cells each of interneurons, CA1 pyramidal cells, and oligodendrocytes, so n = 180 n = 180 n = 180 . Leiden community detection returns clusters of 58, 63, and 59 cells: cluster 1 is 100% interneurons, cluster 2 is 95% CA1 pyramidal cells, and cluster 3 is 100% oligodendrocytes (Figure 8 , top left). The naive test gives p p p -values below 10 − 54 10^{-54} 1 0 − 54 , and p p o l a r p_{\mathrm{polar}} p polar rejects all three null hypotheses (p p p between 2.9 × 10 − 4 2.9 \times10^{-4} 2.9 × 1 0 − 4 and 0.003), as it should for three distinct cell types. The test p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d rejects only the contrast between interneurons and oligodendrocytes.
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 p 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.
We construct a “null” data set by drawing 60 cells of the single subclass CA1Pyr2. Leiden community detection splits them into clusters of 20 and 40 cells. The naive test rejects the null hypothesis (p = 3.4 × 10 − 8 p = 3.4 \times10^{-8} p = 3.4 × 1 0 − 8 ), while p p o l a r p_{\mathrm{polar}} p polar and p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d do not (p = 0.76 p = 0.76 p = 0.76 and 0.46). With 180 CA1Pyr2 cells instead of 60, Leiden community detection returns three clusters, the naive test again rejects all three null hypotheses (p < 10 − 20 p < 10^{-20} p < 1 0 − 20 ), and p p o l a r p_{\mathrm{polar}} p polar rejects none (p p p between 0.29 and 0.79).
Discussion
In this paper, we proposed a selective test for a difference in means between two estimated clusters when the covariance matrix Σ \Sigma Σ in (1) is unknown and unstructured . The test does not estimate Σ \Sigma Σ ; instead, it uses the polar decomposition of the tested observations, which splits their distribution into a part whose distribution depends on Σ \Sigma Σ and an independent part whose distribution is known. As a result, the test avoids the trade-off between Type I error control and power that comes with a plug-in estimate of Σ \Sigma Σ (§ 2.2 ), and it is exact in finite samples for any clustering algorithm. We gave two versions of the test. The test p p o l a r p_{\mathrm{polar}} p polar conditions on less, has higher power, and is computed by an exact Monte Carlo construction that takes longer to run. The one-dimensional test p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d conditions on more information, is faster to compute, and has a closed form for k k k -means when we also condition on the sequence of assignments of Lloyd’s algorithm.
These results suggest a number of extensions and open questions. First, we test the null hypothesis (5) that all observations in the two clusters share a mean, which is stronger than the null hypothesis (2) that the two cluster means are equal (Remark 2.2). Testing (2) without knowledge of Σ \boldsymbol{\Sigma} Σ remains open. Second, we have taken the tested pair as given; when the pair is chosen from the data, for example as the two clusters that look most separated, the conditional distribution of Q \mathbf{Q} Q must be reweighted by the probability of that choice in the Monte Carlo simulation. Third, any reversible kernel gives a p p p -value that controls the selective Type I error, but different kernels and different values of their parameters lead to different power, and the best choice for a given n n n , p p p , and Σ \boldsymbol{\Sigma} Σ remains an open question. Fourth, we assumed that the rows of X \mathbf{X} X are independent; testing data with correlated observations could build on the techniques of González-Delgado et al. [27 ] . Fifth, we would like to extend the test to non-Gaussian data, such as the counts that arise in single-cell RNA sequencing, using techniques from data fission (Leiner et al. [40 ] ) and data thinning (Neufeld et al. [49 ] ; Dharamshi et al. [18 ] ).
AI assistance statement
During manuscript development, the authors used AI assistants, including GPT-5.5 and coding agents, as interactive tools for mathematical brainstorming, software development, and editorial review. This assistance included proposing and stress-testing proof strategies, checking notation and edge cases, drafting code scaffolds for simulations and manuscript packaging, and suggesting revisions to the exposition. Several proof directions that shaped the final presentation were developed through this workflow: the covariance-free polar-factor formulation, the conditioning argument on the Stiefel feasible set, the Besag–Clifford random-index validity proof, the algorithm-agnostic extension to hierarchical clustering, and the oracle-geometry statement separating validity from power. AI outputs were treated as suggestions rather than evidence: all mathematical derivations, code, simulation outputs, citations, and prose were checked, revised, and verified by the authors, who take full responsibility for the final content.
Proofs for Sections 3.1 to 3.3
This appendix proves Theorem 3.1 and Propositions 3.2 and 3.3, one per subsection, and Appendix A.4 compares the three one-dimensional tests. Appendix B uses the same notation.
Preliminaries and notation. Fix a matrix A ∈ R n × ( r − 1 ) \mathbf{A} \in\mathbb{R}^{n \times(r-1)} A ∈ R n × ( r − 1 ) whose columns are an orthonormal basis of the range of P 0 + P 1 \mathbf{P}_0+\mathbf{P}_1 P 0 + P 1 , so that
A A ⊤ = P 0 + P 1 , A ⊤ A = I r − 1 . \mathbf{A}\mathbf{A}^{\top}=\mathbf{P}_0+\mathbf{P}_1,\qquad\mathbf{A}^{\top}\mathbf{A}=\mathbf{I}_{r-1}. A A ⊤ = P 0 + P 1 , A ⊤ A = I r − 1 .
The matrix Z = A ⊤ X ∈ R ( r − 1 ) × p \mathbf{Z}=\mathbf{A}^{\top}\mathbf{X}\in\mathbb{R}^{(r-1)\times p} Z = A ⊤ X ∈ R ( r − 1 ) × p holds the coordinates of ( P 0 + P 1 ) X (\mathbf{P}_0+\mathbf{P}_1)\mathbf{X} ( P 0 + P 1 ) X in this basis: ( P 0 + P 1 ) X = A Z (\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}=\mathbf{A}\mathbf{Z} ( P 0 + P 1 ) X = AZ and H 2 = X ⊤ ( P 0 + P 1 ) X = Z ⊤ Z \mathbf{H}^2=\mathbf{X}^{\top}(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}=\mathbf{Z}^{\top}\mathbf{Z} H 2 = X ⊤ ( P 0 + P 1 ) X = Z ⊤ Z . Every matrix in V \mathcal{V} V is A \mathbf{A} A times a matrix in St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) , and multiplying by A \mathbf{A} A preserves inner products, so we identify the polar factor with its coordinates A ⊤ Q ∈ St ( r − 1 , p ) \mathbf{A}^{\top}\mathbf{Q}\in\operatorname{St}(r-1,p) A ⊤ Q ∈ St ( r − 1 , p ) and write Q \mathbf{Q} Q for both. In coordinates,
Z = Q H , x ′ ( Q ) = P 2 x + A Q H , u ( Q ) = ∥ Q ⊤ a ∥ 2 with a = A ⊤ dir ( ν ) , \mathbf{Z}=\mathbf{Q}\mathbf{H},\qquad\mathbf{x}'(\mathbf{Q})=\mathbf{P}_2\mathbf{x}+\mathbf{A}\mathbf{Q}\mathbf{H},\qquad u(\mathbf{Q})=\lVert\mathbf{Q}^{\top}\mathbf{a}\rVert^2\ \text{ with }\ \mathbf{a}=\mathbf{A}^{\top}\operatorname{dir}(\boldsymbol{\nu}), Z = QH , x ′ ( Q ) = P 2 x + AQH , u ( Q ) = ∥ Q ⊤ a ∥ 2 with a = A ⊤ dir ( ν ) ,
where a \mathbf{a} a is a unit vector, the uniform distribution on V \mathcal{V} V becomes the uniform distribution on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) , written d Q d\mathbf{Q} d Q , and the Givens rotation (21) becomes the ( r − 1 ) × ( r − 1 ) (r-1)\times(r-1) ( r − 1 ) × ( r − 1 ) rotation of rows i i i and j j j , still written G i j ( ω ) \mathbf{G}_{ij}(\omega) G ij ( ω ) .
Proof of Theorem 3.1
The proof uses the distribution of the coordinates Z \mathbf{Z} Z .
Proposition A.1 (Distribution of the coordinates). Under data model (1) and null (5) , the matrix Z \mathbf{Z} Z follows M N ( 0 , I r − 1 , Σ ) \mathcal{MN}(\mathbf{0},\mathbf{I}_{r-1},\boldsymbol{\Sigma}) M N ( 0 , I r − 1 , Σ ) and is independent of P 2 X \mathbf{P}_{2}\mathbf{X} P 2 X .
Proof. Multiplying (1) on the left by A T \mathbf{A}^{\mathsf{T}} A T gives Z ∼ M N ( A T μ , A T A , Σ ) = M N ( A T μ , I r − 1 , Σ ) \mathbf{Z} \sim\mathcal{MN}(\mathbf{A}^{\mathsf{T}}\boldsymbol{\mu},\mathbf{A}^{\mathsf{T}}\mathbf{A},\boldsymbol{\Sigma}) = \mathcal{MN}(\mathbf{A}^{\mathsf{T}}\boldsymbol{\mu},\mathbf{I}_{r-1},\boldsymbol{\Sigma}) Z ∼ M N ( A T μ , A T A , Σ ) = M N ( A T μ , I r − 1 , Σ ) . Under (5) , the rows of μ \boldsymbol{\mu} μ in C ^ 1 ∪ C ^ 2 \widehat{\mathcal{C}}_{1}\cup\widehat{\mathcal{C}}_{2} C 1 ∪ C 2 are equal, so ( P 0 + P 1 ) μ = 0 (\mathbf{P}_{0}+\mathbf{P}_{1})\boldsymbol{\mu}=\mathbf{0} ( P 0 + P 1 ) μ = 0 and A T μ = A T ( P 0 + P 1 ) μ = 0 \mathbf{A}^{\mathsf{T}}\boldsymbol{\mu}=\mathbf{A}^{\mathsf{T}}(\mathbf{P}_{0}+\mathbf{P}_{1})\boldsymbol{\mu}=\mathbf{0} A T μ = A T ( P 0 + P 1 ) μ = 0 . The matrices Z \mathbf{Z} Z and P 2 X \mathbf{P}_{2}\mathbf{X} P 2 X are jointly Gaussian, and their cross-covariance is proportional to A T P 2 = 0 \mathbf{A}^{\mathsf{T}}\mathbf{P}_{2}=\mathbf{0} A T P 2 = 0 , so they are independent.
Proof of Theorem 3.1. We must show that Q \mathbf{Q} Q is uniformly distributed on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) and independent of ( H , P 2 X ) (\mathbf{H},\mathbf{P}_{2}\mathbf{X}) ( H , P 2 X ) . Because ( Q , H ) (\mathbf{Q},\mathbf{H}) ( Q , H ) is a function of Z \mathbf{Z} Z , which is independent of P 2 X \mathbf{P}_{2}\mathbf{X} P 2 X by Proposition A.1 , it is enough to show that for all bounded functions h 1 h_{1} h 1 of Q \mathbf{Q} Q and h 2 h_{2} h 2 of H \mathbf{H} H ,
E [ h 1 ( Q ) h 2 ( H ) ] = E [ h 2 ( H ) ] ∫ h 1 ( Q ′ ) d Q ′ . (31) \mathbb{E}\left[h_{1}(\mathbf{Q})h_{2}(\mathbf{H})\right]=\mathbb{E}\left[h_{2}(\mathbf{H})\right]\int h_{1}(\mathbf{Q}')\,d\mathbf{Q}'. \tag*{(31)} E [ h 1 ( Q ) h 2 ( H ) ] = E [ h 2 ( H ) ] ∫ h 1 ( Q ′ ) d Q ′ . (31)
The matrix Z \mathbf{Z} Z has rank p p p with probability one when r − 1 ≥ p r-1\ge p r − 1 ≥ p , so H = ( Z T Z ) 1 / 2 \mathbf{H}=(\mathbf{Z}^{\mathsf{T}}\mathbf{Z})^{1/2} H = ( Z T Z ) 1/2 is invertible and Q = Z H − 1 \mathbf{Q}=\mathbf{Z}\mathbf{H}^{-1} Q = Z H − 1 .
Next, let O \mathbf{O} O be a uniformly distributed ( r − 1 ) × ( r − 1 ) (r-1)\times(r-1) ( r − 1 ) × ( r − 1 ) orthogonal matrix, drawn independently of X \mathbf{X} X . By Proposition A.1 ,
O Z ∼ M N ( 0 , O O T , Σ ) = M N ( 0 , I r − 1 , Σ ) , \mathbf{O}\mathbf{Z}\sim\mathcal{MN}(\mathbf{0},\mathbf{O}\mathbf{O}^{\mathsf{T}},\boldsymbol{\Sigma})=\mathcal{MN}(\mathbf{0},\mathbf{I}_{r-1},\boldsymbol{\Sigma}), OZ ∼ M N ( 0 , O O T , Σ ) = M N ( 0 , I r − 1 , Σ ) ,
so O Z \mathbf{O}\mathbf{Z} OZ has the same distribution as Z \mathbf{Z} Z . The polar decomposition of O Z \mathbf{O}\mathbf{Z} OZ is ( O Q ) H (\mathbf{O}\mathbf{Q})\mathbf{H} ( OQ ) H , because O Q \mathbf{O}\mathbf{Q} OQ has orthonormal columns and ( O Z ) T ( O Z ) = Z T Z = H 2 (\mathbf{O}\mathbf{Z})^{\mathsf{T}}(\mathbf{O}\mathbf{Z})=\mathbf{Z}^{\mathsf{T}}\mathbf{Z}=\mathbf{H}^{2} ( OZ ) T ( OZ ) = Z T Z = H 2 . So ( O Q , H ) (\mathbf{O}\mathbf{Q},\mathbf{H}) ( OQ , H ) has the same distribution as ( Q , H ) (\mathbf{Q},\mathbf{H}) ( Q , H ) , and
E [ h 1 ( Q ) h 2 ( H ) ] = E [ h 1 ( O Q ) h 2 ( H ) ] = E [ h 2 ( H ) E { h 1 ( O Q ) ∣ Q , H } ] . \mathbb{E}\left[h_{1}(\mathbf{Q})h_{2}(\mathbf{H})\right]=\mathbb{E}\left[h_{1}(\mathbf{O}\mathbf{Q})h_{2}(\mathbf{H})\right]=\mathbb{E}\left[h_{2}(\mathbf{H})\mathbb{E}\left\{h_{1}(\mathbf{O}\mathbf{Q})\mid\mathbf{Q},\mathbf{H}\right\}\right]. E [ h 1 ( Q ) h 2 ( H ) ] = E [ h 1 ( OQ ) h 2 ( H ) ] = E [ h 2 ( H ) E { h 1 ( OQ ) ∣ Q , H } ] .
Finally, for a fixed Q 0 ∈ St ( r − 1 , p ) \mathbf{Q}_{0}\in\operatorname{St}(r-1,p) Q 0 ∈ St ( r − 1 , p ) , the matrix O Q 0 \mathbf{O}\mathbf{Q}_{0} O Q 0 is uniformly distributed on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) , so the inner expectation equals ∫ h 1 ( Q ′ ) d Q ′ \int h_{1}(\mathbf{Q}')\,d\mathbf{Q}' ∫ h 1 ( Q ′ ) d Q ′ whatever the values of Q \mathbf{Q} Q and H \mathbf{H} H . This gives (31).
Proof of Proposition 3.2
Proposition 3.2 makes two claims: the identity (12) , which holds for any data with an invertible pooled covariance, and the Beta distribution of u ( Q ) u(\mathbf{Q}) u ( Q ) under the null.
Proof of the identity (12) . Write ν ˉ = dir ( ν ) \bar{\boldsymbol{\nu}}=\operatorname{dir}(\boldsymbol{\nu}) ν ˉ = dir ( ν ) and b = Q T ν ˉ ∈ R p \mathbf{b}=\mathbf{Q}^{\mathsf{T}}\bar{\boldsymbol{\nu}}\in\mathbb{R}^{p} b = Q T ν ˉ ∈ R p , with Q \mathbf{Q} Q the n × p n\times p n × p polar factor of § 3.1 . Since P 0 = ν ˉ ν ˉ T \mathbf{P}_{0}=\bar{\boldsymbol{\nu}}\bar{\boldsymbol{\nu}}^{\mathsf{T}} P 0 = ν ˉ ν ˉ T , we have u ( Q ) = ∥ P 0 Q ∥ F 2 = ∥ b ∥ 2 u(\mathbf{Q})=\lVert\mathbf{P}_{0}\mathbf{Q}\rVert_{F}^{2}=\lVert\mathbf{b}\rVert^{2} u ( Q ) = ∥ P 0 Q ∥ F 2 = ∥ b ∥ 2 . We write both ingredients of T 2 T^{2} T 2 , the difference in cluster means and the pooled covariance, in terms of H \mathbf{H} H and b \mathbf{b} b .
The difference in cluster means is X ˉ C ^ 1 − X ˉ C ^ 2 = X T ν = ∥ ν ∥ 2 X T ν ˉ \bar{\mathbf{X}}_{\widehat{\mathcal{C}}_{1}}-\bar{\mathbf{X}}_{\widehat{\mathcal{C}}_{2}}=\mathbf{X}^{\mathsf{T}}\boldsymbol{\nu}=\lVert\boldsymbol{\nu}\rVert^{2}\mathbf{X}^{\mathsf{T}}\bar{\boldsymbol{\nu}} X ˉ C 1 − X ˉ C 2 = X T ν = ∥ ν ∥ 2 X T ν ˉ , and n 1 n 2 / r = ∥ ν ∥ − 2 n_{1}n_{2}/r=\lVert\boldsymbol{\nu}\rVert^{-2} n 1 n 2 / r = ∥ ν ∥ − 2 , so
T 2 = ( r − 2 ) ν ˉ T X ( X T P 1 X ) − 1 X T ν ˉ . (32) T^{2}=(r-2)\bar{\boldsymbol{\nu}}^{\mathsf{T}}\mathbf{X}(\mathbf{X}^{\mathsf{T}}\mathbf{P}_{1}\mathbf{X})^{-1}\mathbf{X}^{\mathsf{T}}\bar{\boldsymbol{\nu}}. \tag*{(32)} T 2 = ( r − 2 ) ν ˉ T X ( X T P 1 X ) − 1 X T ν ˉ . (32)
The vector ν ˉ \bar{\boldsymbol{\nu}} ν ˉ lies in the range of P 0 \mathbf{P}_{0} P 0 , so ν ˉ = ( P 0 + P 1 ) ν ˉ \bar{\boldsymbol{\nu}}=(\mathbf{P}_{0}+\mathbf{P}_{1})\bar{\boldsymbol{\nu}} ν ˉ = ( P 0 + P 1 ) ν ˉ , and by (11) ,
X T ν ˉ = X T ( P 0 + P 1 ) ν ˉ = H Q T ν ˉ = H b . (33) \mathbf{X}^{\mathsf{T}}\bar{\boldsymbol{\nu}}=\mathbf{X}^{\mathsf{T}}(\mathbf{P}_{0}+\mathbf{P}_{1})\bar{\boldsymbol{\nu}}=\mathbf{H}\mathbf{Q}^{\mathsf{T}}\bar{\boldsymbol{\nu}}=\mathbf{H}\mathbf{b}. \tag*{(33)} X T ν ˉ = X T ( P 0 + P 1 ) ν ˉ = H Q T ν ˉ = Hb . (33)
Since P 1 = ( P 0 + P 1 ) − P 0 \mathbf{P}_1=(\mathbf{P}_0+\mathbf{P}_1)-\mathbf{P}_0 P 1 = ( P 0 + P 1 ) − P 0 , the same identity gives
X T P 1 X = H 2 − X T ν ˉ ν ˉ T X = H 2 − H b b T H = H ( I p − b b T ) H . (34) \mathbf{X}^{\mathsf{T}}\mathbf{P}_1\mathbf{X}=\mathbf{H}^2-\mathbf{X}^{\mathsf{T}}\bar{\boldsymbol{\nu}}\bar{\boldsymbol{\nu}}^{\mathsf{T}}\mathbf{X}=\mathbf{H}^2-\mathbf{H}\mathbf{b}\mathbf{b}^{\mathsf{T}}\mathbf{H}=\mathbf{H}(\mathbf{I}_p-\mathbf{b}\mathbf{b}^{\mathsf{T}})\mathbf{H}. \tag*{(34)} X T P 1 X = H 2 − X T ν ˉ ν ˉ T X = H 2 − Hb b T H = H ( I p − b b T ) H . (34)
The matrix I p − b b T \mathbf{I}_p-\mathbf{b}\mathbf{b}^{\mathsf{T}} I p − b b T has determinant 1 − ∥ b ∥ 2 2 = 1 − u ( Q ) 1-\lVert\mathbf{b}\rVert_2^2=1-u(\mathbf{Q}) 1 − ∥ b ∥ 2 2 = 1 − u ( Q ) , so the pooled covariance is invertible exactly when u ( Q ) < 1 u(\mathbf{Q})<1 u ( Q ) < 1 . Substituting (33) and (34) into (32), the factors H \mathbf{H} H cancel:
T 2 = ( r − 2 ) b T H H − 1 ( I p − b b T ) − 1 H − 1 H b = ( r − 2 ) b T ( I p − b b T ) − 1 b . T^2=(r-2)\mathbf{b}^{\mathsf{T}}\mathbf{H}\mathbf{H}^{-1}(\mathbf{I}_p-\mathbf{b}\mathbf{b}^{\mathsf{T}})^{-1}\mathbf{H}^{-1}\mathbf{H}\mathbf{b}=(r-2)\mathbf{b}^{\mathsf{T}}(\mathbf{I}_p-\mathbf{b}\mathbf{b}^{\mathsf{T}})^{-1}\mathbf{b}. T 2 = ( r − 2 ) b T H H − 1 ( I p − b b T ) − 1 H − 1 Hb = ( r − 2 ) b T ( I p − b b T ) − 1 b .
By the Sherman–Morrison formula,
( I p − b b T ) − 1 = I p + b b T 1 − ∥ b ∥ 2 2 , so b T ( I p − b b T ) − 1 b = ∥ b ∥ 2 2 + ∥ b ∥ 2 4 1 − ∥ b ∥ 2 2 = ∥ b ∥ 2 2 1 − ∥ b ∥ 2 2 . (\mathbf{I}_p-\mathbf{b}\mathbf{b}^{\mathsf{T}})^{-1}=\mathbf{I}_p+\frac{\mathbf{b}\mathbf{b}^{\mathsf{T}}}{1-\lVert\mathbf{b}\rVert_2^2},
\qquad\text{so}\qquad
\mathbf{b}^{\mathsf{T}}(\mathbf{I}_p-\mathbf{b}\mathbf{b}^{\mathsf{T}})^{-1}\mathbf{b}=\lVert\mathbf{b}\rVert_2^2+\frac{\lVert\mathbf{b}\rVert_2^4}{1-\lVert\mathbf{b}\rVert_2^2}=\frac{\lVert\mathbf{b}\rVert_2^2}{1-\lVert\mathbf{b}\rVert_2^2}. ( I p − b b T ) − 1 = I p + 1 − ∥ b ∥ 2 2 b b T , so b T ( I p − b b T ) − 1 b = ∥ b ∥ 2 2 + 1 − ∥ b ∥ 2 2 ∥ b ∥ 2 4 = 1 − ∥ b ∥ 2 2 ∥ b ∥ 2 2 .
With ∥ b ∥ 2 2 = u ( Q ) \lVert\mathbf{b}\rVert_2^2=u(\mathbf{Q}) ∥ b ∥ 2 2 = u ( Q ) , this is (12). When p = 1 p=1 p = 1 , u ( Q ) = ∥ P 0 X ∥ F 2 / ∥ ( P 0 + P 1 ) X ∥ F 2 = w u(\mathbf{Q})=\lVert\mathbf{P}_0\mathbf{X}\rVert_F^2/\lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F^2=w u ( Q ) = ∥ P 0 X ∥ F 2 / ∥( P 0 + P 1 ) X ∥ F 2 = w and 1 − u ( Q ) = ∥ P 1 X ∥ F 2 / ∥ ( P 0 + P 1 ) X ∥ F 2 1-u(\mathbf{Q})=\lVert\mathbf{P}_1\mathbf{X}\rVert_F^2/\lVert(\mathbf{P}_0+\mathbf{P}_1)\mathbf{X}\rVert_F^2 1 − u ( Q ) = ∥ P 1 X ∥ F 2 / ∥( P 0 + P 1 ) X ∥ F 2 , which gives T 2 = R T^2=R T 2 = R .
Proof of the distribution in Proposition 3.2. By Theorem 3.1, under the null Q \mathbf{Q} Q is uniformly distributed on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) , and in coordinates u ( Q ) = ∥ Q T a ∥ 2 2 u(\mathbf{Q})=\lVert\mathbf{Q}^{\mathsf{T}}\mathbf{a}\rVert_2^2 u ( Q ) = ∥ Q T a ∥ 2 2 for the fixed unit vector a \mathbf{a} a . We find the distribution in three steps.
First, a uniformly distributed Q \mathbf{Q} Q has the same distribution as the first p p p columns of a uniformly distributed ( r − 1 ) × ( r − 1 ) (r-1)\times(r-1) ( r − 1 ) × ( r − 1 ) orthogonal matrix O \mathbf{O} O . Then Q T a \mathbf{Q}^{\mathsf{T}}\mathbf{a} Q T a consists of the first p p p entries of the vector O T a \mathbf{O}^{\mathsf{T}}\mathbf{a} O T a .
Second, O T a \mathbf{O}^{\mathsf{T}}\mathbf{a} O T a is a fixed unit vector turned by a uniformly distributed orthogonal matrix, so it is uniformly distributed on the unit sphere of R r − 1 \mathbb{R}^{r-1} R r − 1 . A standard Gaussian vector z ∼ N ( 0 , I r − 1 ) \mathbf{z}\sim\mathcal{N}(\mathbf{0},\mathbf{I}_{r-1}) z ∼ N ( 0 , I r − 1 ) has a distribution that is unchanged by orthogonal matrices, so its direction z / ∥ z ∥ 2 \mathbf{z}/\lVert\mathbf{z}\rVert_2 z / ∥ z ∥ 2 is also uniformly distributed on the sphere. Hence O T a \mathbf{O}^{\mathsf{T}}\mathbf{a} O T a has the same distribution as z / ∥ z ∥ 2 \mathbf{z}/\lVert\mathbf{z}\rVert_2 z / ∥ z ∥ 2 .
Third, therefore,
u ( Q ) = ∑ j = 1 p z j 2 ∥ z ∥ 2 2 = U U + V , U = ∑ j = 1 p z j 2 ∼ χ p 2 , V = ∑ j = p + 1 r − 1 z j 2 ∼ χ r − 1 − p 2 . u(\mathbf{Q})=\sum_{j=1}^{p}\frac{z_j^2}{\lVert\mathbf{z}\rVert_2^2}=\frac{U}{U+V},
\qquad
U=\sum_{j=1}^{p}z_j^2\sim\chi_p^2,
\qquad
V=\sum_{j=p+1}^{r-1}z_j^2\sim\chi_{r-1-p}^2. u ( Q ) = j = 1 ∑ p ∥ z ∥ 2 2 z j 2 = U + V U , U = j = 1 ∑ p z j 2 ∼ χ p 2 , V = j = p + 1 ∑ r − 1 z j 2 ∼ χ r − 1 − p 2 .
with U U U and V V V independent, and such a ratio has the Beta ( p 2 , r − 1 − p 2 ) \operatorname{Beta}\left(\frac{p}{2},\frac{r-1-p}{2}\right) Beta ( 2 p , 2 r − 1 − p ) distribution. The statement for T 2 T^2 T 2 follows from (12), because r − p − 1 ( r − 2 ) p T 2 = r − 1 − p p U V \frac{r-p-1}{(r-2)p}T^2=\frac{r-1-p}{p}\frac{U}{V} ( r − 2 ) p r − p − 1 T 2 = p r − 1 − p V U is a ratio of independent χ 2 \chi^2 χ 2 variables divided by their degrees of freedom. The substitution u ( Q ) = cos 2 ϕ u(\mathbf{Q})=\cos^2\phi u ( Q ) = cos 2 ϕ gives the density f f f of Section 4.3.
Proof of Proposition 3.3
Proposition 3.3 makes three claims. (a) Given P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and the event that the clustering returns C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 , the polar factor Q \mathbf{Q} Q is uniformly distributed on S Q S_{\mathbf{Q}} S Q . (b) The p p p -value p p o l a r p_{\mathrm{polar}} p polar is the ratio of integrals in (14). (c) Under the null, p p o l a r p_{\mathrm{polar}} p polar is uniformly distributed given that the clustering returns C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 . Throughout, S Q S_{\mathbf{Q}} S Q is the set of Section 3.3 with the random ( P 2 X , H ) (\mathbf{P}_2\mathbf{X},\mathbf{H}) ( P 2 X , H ) in place of their observed values,
S Q = { Q ′ ∈ St ( r − 1 , p ) : C ^ 1 , C ^ 2 ∈ C ( P 2 X + A Q ′ H ) } . S_{\mathbf{Q}}=\{\mathbf{Q}'\in\operatorname{St}(r-1,p):\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{P}_2\mathbf{X}+\mathbf{A}\mathbf{Q}'\mathbf{H})\}. S Q = { Q ′ ∈ St ( r − 1 , p ) : C 1 , C 2 ∈ C ( P 2 X + A Q ′ H )} .
Proof of (a). The data are X = P 2 X + A Q H \mathbf{X}=\mathbf{P}_2\mathbf{X}+\mathbf{A}\mathbf{Q}\mathbf{H} X = P 2 X + AQH , so the clustering returns C ^ 1 \widehat{C}_1 C 1 and C ^ 2 \widehat{C}_2 C 2 exactly when Q ∈ S Q \mathbf{Q}\in S_{\mathbf{Q}} Q ∈ S Q . By Theorem 3.1, Q \mathbf{Q} Q is uniformly distributed and independent of ( P 2 X , H ) (\mathbf{P}_2\mathbf{X},\mathbf{H}) ( P 2 X , H ) , and S Q S_{\mathbf{Q}} S Q is fixed once ( P 2 X , H ) (\mathbf{P}_2\mathbf{X},\mathbf{H}) ( P 2 X , H ) is. So for every set B ⊆ St ( r − 1 , p ) B\subseteq\operatorname{St}(r-1,p) B ⊆ St ( r − 1 , p ) ,
P ( Q ∈ B and C ^ 1 , C ^ 2 ∈ C ( X ) ∣ P 2 X , H ) = P ( Q ∈ B ∩ S Q ∣ P 2 X , H ) = ∫ B ∩ S Q d Q . \mathbb{P}(\mathbf{Q}\in B\text{ and }\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X})\mid\mathbf{P}_2\mathbf{X},\mathbf{H})=\mathbb{P}(\mathbf{Q}\in B\cap S_{\mathbf{Q}}\mid\mathbf{P}_2\mathbf{X},\mathbf{H})=\int_{B\cap S_{\mathbf{Q}}}d\mathbf{Q}. P ( Q ∈ B and C 1 , C 2 ∈ C ( X ) ∣ P 2 X , H ) = P ( Q ∈ B ∩ S Q ∣ P 2 X , H ) = ∫ B ∩ S Q d Q .
Taking B = St ( r − 1 , p ) B=\operatorname{St}(r-1,p) B = St ( r − 1 , p ) gives P ( C ^ 1 , C ^ 2 ∈ C ( X ) ∣ P 2 X , H ) = ∫ S Q d Q \mathbb{P}(\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X})\mid\mathbf{P}_2\mathbf{X},\mathbf{H})=\int_{\mathcal{S}_{\mathbf{Q}}}d\mathbf{Q} P ( C 1 , C 2 ∈ C ( X ) ∣ P 2 X , H ) = ∫ S Q d Q , and dividing the two displays,
P ( Q ∈ B ∣ C ^ 1 , C ^ 2 ∈ C ( X ) , P 2 X , H ) = ∫ B ∩ S Q d Q ∫ S Q d Q . \mathbb{P}(\mathbf{Q}\in B\mid\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X}),\mathbf{P}_2\mathbf{X},\mathbf{H})=\frac{\int_{B\cap\mathcal{S}_{\mathbf{Q}}}d\mathbf{Q}}{\int_{\mathcal{S}_{\mathbf{Q}}}d\mathbf{Q}}. P ( Q ∈ B ∣ C 1 , C 2 ∈ C ( X ) , P 2 X , H ) = ∫ S Q d Q ∫ B ∩ S Q d Q .
which is the uniform distribution on S Q \mathcal{S}_{\mathbf{Q}} S Q . The division is allowed: the clustering returns the tested clusters while ∫ S Q d Q = 0 \int_{\mathcal{S}_{\mathbf{Q}}}d\mathbf{Q}=0 ∫ S Q d Q = 0 with probability E [ 1 { ∫ S Q d Q = 0 } ∫ S Q d Q ] = 0 \mathbb{E}\left[1\left\{\int_{\mathcal{S}_{\mathbf{Q}}}d\mathbf{Q}=0\right\}\int_{\mathcal{S}_{\mathbf{Q}}}d\mathbf{Q}\right]=0 E [ 1 { ∫ S Q d Q = 0 } ∫ S Q d Q ] = 0 .
Proof of (b). By (12) , T 2 T^2 T 2 increases with u ( Q ) u(\mathbf{Q}) u ( Q ) , so T 2 ( X ) ≥ T 2 ( x ) T^2(\mathbf{X})\geq T^2(\mathbf{x}) T 2 ( X ) ≥ T 2 ( x ) exactly when u ( Q ) ≥ u ( Q o b s ) u(\mathbf{Q})\geq u(\mathbf{Q}_{\mathrm{obs}}) u ( Q ) ≥ u ( Q obs ) . Taking B = { Q : u ( Q ) ≥ u ( Q o b s ) } B=\{\mathbf{Q}:u(\mathbf{Q})\geq u(\mathbf{Q}_{\mathrm{obs}})\} B = { Q : u ( Q ) ≥ u ( Q obs )} in (a) gives (14) .
Proof of (c). Fix P 2 X \mathbf{P}_2\mathbf{X} P 2 X and H \mathbf{H} H . For a number c c c , the probability that u ( Q ) ≥ c u(\mathbf{Q})\geq c u ( Q ) ≥ c when Q \mathbf{Q} Q is uniformly distributed on S Q \mathcal{S}_{\mathbf{Q}} S Q is
F ‾ ( c ) = ∫ S Q 1 { u ( Q ) ≥ c } d Q ∫ S Q d Q . \overline{F}(c)=\frac{\int_{\mathcal{S}_{\mathbf{Q}}}1\{u(\mathbf{Q})\geq c\}\,d\mathbf{Q}}{\int_{\mathcal{S}_{\mathbf{Q}}}d\mathbf{Q}}. F ( c ) = ∫ S Q d Q ∫ S Q 1 { u ( Q ) ≥ c } d Q .
By (b), p p o l a r = F ‾ ( u ( Q o b s ) ) p_{\mathrm{polar}}=\overline{F}(u(\mathbf{Q}_{\mathrm{obs}})) p polar = F ( u ( Q obs )) , and by (a), under the null Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs is a draw from the uniform distribution on S Q \mathcal{S}_{\mathbf{Q}} S Q .
The function F ‾ \overline{F} F is continuous. Under the uniform distribution on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) , u ( Q ) u(\mathbf{Q}) u ( Q ) has a Beta distribution (Proposition 3.2 ), so each value c c c has probability zero. The uniform distribution on S Q \mathcal{S}_{\mathbf{Q}} S Q is the uniform distribution on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) restricted to a set of positive probability, so each value still has probability zero.
For a random variable with a continuous distribution, its upper tail probability evaluated at the variable itself is uniformly distributed (the probability integral transform). Hence
P ( p p o l a r ≤ α ∣ C ^ 1 , C ^ 2 ∈ C ( X ) , P 2 X , H ) = α for all α ∈ [ 0 , 1 ] . \mathbb{P}(p_{\mathrm{polar}}\leq\alpha\mid\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{X}),\mathbf{P}_2\mathbf{X},\mathbf{H})=\alpha\qquad\text{for all }\alpha\in[0,1]. P ( p polar ≤ α ∣ C 1 , C 2 ∈ C ( X ) , P 2 X , H ) = α for all α ∈ [ 0 , 1 ] .
The right side does not depend on ( P 2 X , H ) (\mathbf{P}_2\mathbf{X},\mathbf{H}) ( P 2 X , H ) , so averaging over them given the selection event gives the statement conditional on the selection event alone.
Three one-dimensional tests side by side
Table A.1 lists, for the test of Gao et al. [24 ] , the test of Yun and Barber (2023), and p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d , the null hypothesis, the nuisance parameters, the parts of X = P 0 X + P 1 X + P 2 X \mathbf{X}=\mathbf{P}_0\mathbf{X}+\mathbf{P}_1\mathbf{X}+\mathbf{P}_2\mathbf{X} X = P 0 X + P 1 X + P 2 X that each test holds fixed, and the scalar that remains random.
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.
The k k k -means trajectory event and the Monte Carlo kernels
This appendix proves the results of § 3.4 , § 4.1 , § 4.2 , and § 4.4 . Appendices B.1 and B.2 show that the event that Lloyd’s algorithm repeats its observed sequence of assignments is a set of quadratic inequalities in Q \mathbf{Q} Q , with closed-form solutions on a Givens circle; Appendices B.3 to B.6 prove the reversibility of the kernels, Proposition 3.4 on the one-dimensional test, and the exactness of the Besag–Clifford p p p -value.
We use the notation of Appendix A: the basis A \mathbf{A} A , the polar factor Q \mathbf{Q} Q written in coordinates in St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) , and d Q \mathrm{d}\mathbf{Q} d Q for the uniform distribution on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) . We write S \mathcal{S} S for the set of polar factors that the test conditions on ( S Q (\mathcal{S}_{\mathbf{Q}} ( S Q or S Q , τ ) \mathcal{S}_{\mathbf{Q},\tau}) S Q , τ ) .
The trajectory event is quadratic in Q \mathbf{Q} Q
This subsection proves Proposition 4.3. For a polar factor Q \mathbf{Q} Q , the data set
x ′ ( Q ) = P 2 x + A Q H (35) \mathbf{x}'(\mathbf{Q})=\mathbf{P}_{2}\mathbf{x}+\mathbf{A}\mathbf{Q}\mathbf{H} \tag*{(35)} x ′ ( Q ) = P 2 x + AQH (35)
keeps P 2 x \mathbf{P}_{2}\mathbf{x} P 2 x and H \mathbf{H} H and replaces the polar factor. Writing α i T \boldsymbol{\alpha}_{i}^{\mathsf{T}} α i T for the i i i th row of A \mathbf{A} A , which is zero for observations outside C ^ 1 ∪ C ^ 2 \widehat{C}_{1}\cup\widehat{C}_{2} C 1 ∪ C 2 , and b i T \mathbf{b}_{i}^{\mathsf{T}} b i T for the i i i th row of P 2 x \mathbf{P}_{2}\mathbf{x} P 2 x , each observation is an affine function of Q \mathbf{Q} Q ,
x i ′ ( Q ) T = b i T + α i T Q H . (36) \mathbf{x}'_{i}(\mathbf{Q})^{\mathsf{T}}=\mathbf{b}_{i}^{\mathsf{T}}+\boldsymbol{\alpha}_{i}^{\mathsf{T}}\mathbf{Q}\mathbf{H}. \tag*{(36)} x i ′ ( Q ) T = b i T + α i T QH . (36)
Let S ℓ ( t ) = { i : c i ( t ) = ℓ } \mathcal{S}_{\ell}^{(t)}=\{i:c_{i}^{(t)}=\ell\} S ℓ ( t ) = { i : c i ( t ) = ℓ } be the observations that the observed sequence τ \tau τ assigns to cluster ℓ \ell ℓ at iteration t t t ; no cluster is empty at any iteration, since otherwise Lloyd’s algorithm is not defined. With these assignments held fixed, each centroid is a fixed average of the rows (36), so it is also affine in Q \mathbf{Q} Q :
m ℓ ( t ) ( Q ) T = b ˉ ℓ ( t ) T + α ˉ ℓ ( t ) T Q H , α ˉ ℓ ( t ) = 1 ∣ S ℓ ( t − 1 ) ∣ ∑ i ∈ S ℓ ( t − 1 ) α i , b ˉ ℓ ( t ) = 1 ∣ S ℓ ( t − 1 ) ∣ ∑ i ∈ S ℓ ( t − 1 ) b i , (37) \mathbf{m}_{\ell}^{(t)}(\mathbf{Q})^{\mathsf{T}}=\bar{\mathbf{b}}_{\ell}^{(t)\mathsf{T}}+\bar{\boldsymbol{\alpha}}_{\ell}^{(t)\mathsf{T}}\mathbf{Q}\mathbf{H},\qquad\bar{\boldsymbol{\alpha}}_{\ell}^{(t)}=\frac{1}{\lvert\mathcal{S}_{\ell}^{(t-1)}\rvert}\sum_{i\in\mathcal{S}_{\ell}^{(t-1)}}\boldsymbol{\alpha}_{i},\qquad\bar{\mathbf{b}}_{\ell}^{(t)}=\frac{1}{\lvert\mathcal{S}_{\ell}^{(t-1)}\rvert}\sum_{i\in\mathcal{S}_{\ell}^{(t-1)}}\mathbf{b}_{i}, \tag*{(37)} m ℓ ( t ) ( Q ) T = b ˉ ℓ ( t ) T + α ˉ ℓ ( t ) T QH , α ˉ ℓ ( t ) = ∣ S ℓ ( t − 1 ) ∣ 1 i ∈ S ℓ ( t − 1 ) ∑ α i , b ˉ ℓ ( t ) = ∣ S ℓ ( t − 1 ) ∣ 1 i ∈ S ℓ ( t − 1 ) ∑ b i , (37)
for t ≥ 1 t\ge1 t ≥ 1 , and the initial centroids m ℓ ( 0 ) ( Q ) = x I ℓ ′ ( Q ) \mathbf{m}_{\ell}^{(0)}(\mathbf{Q})=\mathbf{x}'_{I_{\ell}}(\mathbf{Q}) m ℓ ( 0 ) ( Q ) = x I ℓ ′ ( Q ) are affine by (36).
Proof of Proposition 4.3. Fix t t t , i i i , and a cluster ℓ ≠ c = c i ( t ) \ell\ne c=c_{i}^{(t)} ℓ = c = c i ( t ) . Expanding the two squared distances in (26), the terms ∥ x i ′ ( Q ) ∥ 2 2 \lVert\mathbf{x}'_{i}(\mathbf{Q})\rVert_{2}^{2} ∥ x i ′ ( Q ) ∥ 2 2 cancel and
g t , i , ℓ ( Q ) = 2 ⟨ x i ′ ( Q ) , m ℓ ( t ) ( Q ) − m c ( t ) ( Q ) ⟩ + ∥ m c ( t ) ( Q ) ∥ 2 2 − ∥ m ℓ ( t ) ( Q ) ∥ 2 2 . g_{t,i,\ell}(\mathbf{Q})=2\left\langle\mathbf{x}'_{i}(\mathbf{Q}),\mathbf{m}_{\ell}^{(t)}(\mathbf{Q})-\mathbf{m}_{c}^{(t)}(\mathbf{Q})\right\rangle+\lVert\mathbf{m}_{c}^{(t)}(\mathbf{Q})\rVert_{2}^{2}-\lVert\mathbf{m}_{\ell}^{(t)}(\mathbf{Q})\rVert_{2}^{2}. g t , i , ℓ ( Q ) = 2 ⟨ x i ′ ( Q ) , m ℓ ( t ) ( Q ) − m c ( t ) ( Q ) ⟩ + ∥ m c ( t ) ( Q ) ∥ 2 2 − ∥ m ℓ ( t ) ( Q ) ∥ 2 2 .
Substituting (36) and (37), the terms with two factors of Q \mathbf{Q} Q are
2 α i T Q H 2 Q T ( α ˉ ℓ ( t ) − α ˉ c ( t ) ) + α ˉ c ( t ) T Q H 2 Q T α ˉ c ( t ) − α ˉ ℓ ( t ) T Q H 2 Q T α ˉ ℓ ( t ) , 2\boldsymbol{\alpha}_{i}^{\mathsf{T}}\mathbf{Q}\mathbf{H}^{2}\mathbf{Q}^{\mathsf{T}}\left(\bar{\boldsymbol{\alpha}}_{\ell}^{(t)}-\bar{\boldsymbol{\alpha}}_{c}^{(t)}\right)+\bar{\boldsymbol{\alpha}}_{c}^{(t)\mathsf{T}}\mathbf{Q}\mathbf{H}^{2}\mathbf{Q}^{\mathsf{T}}\bar{\boldsymbol{\alpha}}_{c}^{(t)}-\bar{\boldsymbol{\alpha}}_{\ell}^{(t)\mathsf{T}}\mathbf{Q}\mathbf{H}^{2}\mathbf{Q}^{\mathsf{T}}\bar{\boldsymbol{\alpha}}_{\ell}^{(t)}, 2 α i T Q H 2 Q T ( α ˉ ℓ ( t ) − α ˉ c ( t ) ) + α ˉ c ( t ) T Q H 2 Q T α ˉ c ( t ) − α ˉ ℓ ( t ) T Q H 2 Q T α ˉ ℓ ( t ) ,
the terms with one factor of Q \mathbf{Q} Q are linear in its entries, and the rest does not depend on Q \mathbf{Q} Q . All coefficients are determined by P 2 x \mathbf{P}_{2}\mathbf{x} P 2 x , H \mathbf{H} H , and τ \tau τ . So g t , i , ℓ g_{t,i,\ell} g t , i , ℓ is a quadratic polynomial in the entries of Q \mathbf{Q} Q , and S Q , τ \mathcal{S}_{\mathbf{Q},\tau} S Q , τ is the intersection of the sets { g t , i , ℓ ≤ 0 } \{g_{t,i,\ell}\le0\} { g t , i , ℓ ≤ 0 } over all t ≤ t max t\le t_{\max} t ≤ t m a x , i ≤ n i\le n i ≤ n , and ℓ ≠ c i ( t ) \ell\ne c_{i}^{(t)} ℓ = c i ( t ) , which are ( t max + 1 ) n ( K − 1 ) (t_{\max}+1)n(K-1) ( t m a x + 1 ) n ( K − 1 ) quadratic inequalities. □ \square □
The proof uses the observed assignments at every iteration. If we condition only on the final clusters, the intermediate assignments vary with Q \mathbf{Q} Q , and formally
S Q = ⋃ τ ′ S Q , τ ′ , (38) \mathcal{S}_{\mathbf{Q}}=\bigcup_{\tau'}\mathcal{S}_{\mathbf{Q},\tau'}, \tag*{(38)} S Q = τ ′ ⋃ S Q , τ ′ , (38)
where the union is over the sequences of assignments τ ′ \tau' τ ′ that end in clusters containing C ^ 1 \hat{C}_1 C ^ 1 and C ^ 2 \hat{C}_2 C ^ 2 . Each S Q , τ ′ S_{Q,\tau'} S Q , τ ′ is an intersection of quadratic sets, so S Q S_Q S Q is a union of intersections of quadratic sets. The union is finite, but the number of sequences can be very large and they cannot be listed in advance, which is why we condition on τ \tau τ when we want closed forms. Techniques that compute such unions of truncation sets efficiently have been developed for other selective tests [36 ] (Chen et al. 2023) and might apply here.
This subsection proves Proposition 4.4 and gives the hit-and-run step. Fix the current Q ∈ S Q , τ \mathbf{Q} \in S_{Q,\tau} Q ∈ S Q , τ and a pair of rows i < j i < j i < j . Then
G i j ( ω ) Q = Q + ( cos ω − 1 ) D 1 + sin ω D 2 , G_{ij}(\omega)\mathbf{Q} = \mathbf{Q} + (\cos\omega- 1)\mathbf{D}_1 + \sin\omega\mathbf{D}_2, G ij ( ω ) Q = Q + ( cos ω − 1 ) D 1 + sin ω D 2 ,
where D 1 \mathbf{D}_1 D 1 has rows i i i and j j j equal to those of Q \mathbf{Q} Q and D 2 \mathbf{D}_2 D 2 has rows i i i and j j j equal to − Q j ⋅ -\mathbf{Q}_{j\cdot} − Q j ⋅ and Q i ⋅ \mathbf{Q}_{i\cdot} Q i ⋅ , all other rows being zero. By (35) ,
x ′ ( G i j ( ω ) Q ) = Y 0 + cos ω Y 1 + sin ω Y 2 , Y 0 = P 2 x + A ( Q − D 1 ) H , Y 1 = A D 1 H , Y 2 = A D 2 H . (39) \mathbf{x}'(G_{ij}(\omega)\mathbf{Q}) = \mathbf{Y}_0 + \cos\omega\mathbf{Y}_1 + \sin\omega\mathbf{Y}_2,
\qquad
\mathbf{Y}_0 = \mathbf{P}_2\mathbf{x} + \mathbf{A}(\mathbf{Q} - \mathbf{D}_1)\mathbf{H},\quad
\mathbf{Y}_1 = \mathbf{A}\mathbf{D}_1\mathbf{H},\quad
\mathbf{Y}_2 = \mathbf{A}\mathbf{D}_2\mathbf{H}. \tag*{(39)} x ′ ( G ij ( ω ) Q ) = Y 0 + cos ω Y 1 + sin ω Y 2 , Y 0 = P 2 x + A ( Q − D 1 ) H , Y 1 = A D 1 H , Y 2 = A D 2 H . (39)
The proof below uses only this form, Y 0 + cos ω Y 1 + sin ω Y 2 \mathbf{Y}_0+\cos\omega\mathbf{Y}_1+\sin\omega\mathbf{Y}_2 Y 0 + cos ω Y 1 + sin ω Y 2 , so it covers any curve D 0 + cos ω D 1 + sin ω D 2 \mathbf{D}_0+\cos\omega\mathbf{D}_1+\sin\omega\mathbf{D}_2 D 0 + cos ω D 1 + sin ω D 2 in Proposition 4.4, with Y 0 = P 2 x + A D 0 H \mathbf{Y}_0=\mathbf{P}_2\mathbf{x}+\mathbf{A}\mathbf{D}_0\mathbf{H} Y 0 = P 2 x + A D 0 H and Y s = A D s H \mathbf{Y}_s=\mathbf{A}\mathbf{D}_s\mathbf{H} Y s = A D s H . The one-dimensional path of Section 3.4 has the same form, with Q ( I p − γ γ T ) \mathbf{Q}(\mathbf{I}_p-\boldsymbol{\gamma}\boldsymbol{\gamma}^{\mathsf T}) Q ( I p − γ γ T ) , A T ν γ ˉ T \mathbf{A}^{\mathsf T}\boldsymbol{\nu}\bar{\boldsymbol{\gamma}}^{\mathsf T} A T ν γ ˉ T , and A T dir ( P 1 q ) γ T \mathbf{A}^{\mathsf T}\operatorname{dir}(\mathbf{P}_1\mathbf{q})\boldsymbol{\gamma}^{\mathsf T} A T dir ( P 1 q ) γ T in place of Q − D 1 \mathbf{Q}-\mathbf{D}_1 Q − D 1 , D 1 \mathbf{D}_1 D 1 , and D 2 \mathbf{D}_2 D 2 . With the assignments fixed by τ \tau τ , each centroid is the same fixed average of the rows of Y 0 \mathbf{Y}_0 Y 0 , Y 1 \mathbf{Y}_1 Y 1 , and Y 2 \mathbf{Y}_2 Y 2 ,
m ℓ ( t ) ( ω ) = y ˉ 0 , ℓ ( t ) + cos ω y ˉ 1 , ℓ ( t ) + sin ω y ˉ 2 , ℓ ( t ) . \mathbf{m}^{(t)}_{\ell}(\omega)=\bar{\mathbf{y}}^{(t)}_{0,\ell}+\cos\omega\bar{\mathbf{y}}^{(t)}_{1,\ell}+\sin\omega\bar{\mathbf{y}}^{(t)}_{2,\ell}. m ℓ ( t ) ( ω ) = y ˉ 0 , ℓ ( t ) + cos ω y ˉ 1 , ℓ ( t ) + sin ω y ˉ 2 , ℓ ( t ) .
Proof of Proposition 4.4. Fix t t t , an observation k k k with observed label c = c k ( t ) c=c_k^{(t)} c = c k ( t ) , and a cluster ℓ ≠ c \ell\ne c ℓ = c . The differences between observation k k k and the two centroids are
x k ′ ( ω ) − m c ( t ) ( ω ) = e 0 + cos ω e 1 + sin ω e 2 , x k ′ ( ω ) − m ℓ ( t ) ( ω ) = f 0 + cos ω f 1 + sin ω f 2 , \mathbf{x}'_k(\omega)-\mathbf{m}^{(t)}_c(\omega)=\mathbf{e}_0+\cos\omega\mathbf{e}_1+\sin\omega\mathbf{e}_2,\qquad
\mathbf{x}'_k(\omega)-\mathbf{m}^{(t)}_\ell(\omega)=\mathbf{f}_0+\cos\omega\mathbf{f}_1+\sin\omega\mathbf{f}_2, x k ′ ( ω ) − m c ( t ) ( ω ) = e 0 + cos ω e 1 + sin ω e 2 , x k ′ ( ω ) − m ℓ ( t ) ( ω ) = f 0 + cos ω f 1 + sin ω f 2 ,
with e s = [ Y s ] k − y ˉ s , c ( t ) \mathbf{e}_s=[\mathbf{Y}_s]_k-\bar{\mathbf{y}}^{(t)}_{s,c} e s = [ Y s ] k − y ˉ s , c ( t ) and f s = [ Y s ] k − y ˉ s , ℓ ( t ) \mathbf{f}_s=[\mathbf{Y}_s]_k-\bar{\mathbf{y}}^{(t)}_{s,\ell} f s = [ Y s ] k − y ˉ s , ℓ ( t ) for s = 0 , 1 , 2 s=0,1,2 s = 0 , 1 , 2 . The difference of the two squared norms is
g ( ω ) = κ 1 cos 2 ω + κ 2 sin 2 ω + κ 3 cos ω sin ω + κ 4 cos ω + κ 5 sin ω + κ 6 , g(\omega)=\kappa_1\cos^2\omega+\kappa_2\sin^2\omega+\kappa_3\cos\omega\sin\omega+\kappa_4\cos\omega+\kappa_5\sin\omega+\kappa_6, g ( ω ) = κ 1 cos 2 ω + κ 2 sin 2 ω + κ 3 cos ω sin ω + κ 4 cos ω + κ 5 sin ω + κ 6 ,
where
κ 1 = ∥ e 1 ∥ 2 − ∥ f 1 ∥ 2 , κ 2 = ∥ e 2 ∥ 2 − ∥ f 2 ∥ 2 , κ 3 = 2 ( e 1 T e 2 − f 1 T f 2 ) , \kappa_1=\lVert\mathbf{e}_1\rVert^2-\lVert\mathbf{f}_1\rVert^2,\qquad
\kappa_2=\lVert\mathbf{e}_2\rVert^2-\lVert\mathbf{f}_2\rVert^2,\qquad
\kappa_3=2(\mathbf{e}_1^{\mathsf T}\mathbf{e}_2-\mathbf{f}_1^{\mathsf T}\mathbf{f}_2), κ 1 = ∥ e 1 ∥ 2 − ∥ f 1 ∥ 2 , κ 2 = ∥ e 2 ∥ 2 − ∥ f 2 ∥ 2 , κ 3 = 2 ( e 1 T e 2 − f 1 T f 2 ) ,
κ 4 = 2 ( e 0 T e 1 − f 0 T f 1 ) , κ 5 = 2 ( e 0 T e 2 − f 0 T f 2 ) , κ 6 = ∥ e 0 ∥ 2 − ∥ f 0 ∥ 2 . \kappa_4=2(\mathbf{e}_0^{\mathsf T}\mathbf{e}_1-\mathbf{f}_0^{\mathsf T}\mathbf{f}_1),\qquad
\kappa_5=2(\mathbf{e}_0^{\mathsf T}\mathbf{e}_2-\mathbf{f}_0^{\mathsf T}\mathbf{f}_2),\qquad
\kappa_6=\lVert\mathbf{e}_0\rVert^2-\lVert\mathbf{f}_0\rVert^2. κ 4 = 2 ( e 0 T e 1 − f 0 T f 1 ) , κ 5 = 2 ( e 0 T e 2 − f 0 T f 2 ) , κ 6 = ∥ e 0 ∥ 2 − ∥ f 0 ∥ 2 .
Using cos 2 ω = ( 1 + cos 2 ω ) / 2 \cos^2\omega=(1+\cos2\omega)/2 cos 2 ω = ( 1 + cos 2 ω ) /2 , sin 2 ω = ( 1 − cos 2 ω ) / 2 \sin^2\omega=(1-\cos2\omega)/2 sin 2 ω = ( 1 − cos 2 ω ) /2 , and cos ω sin ω = sin 2 ω / 2 \cos\omega\sin\omega=\sin2\omega/2 cos ω sin ω = sin 2 ω /2 gives (27) ,
g ( ω ) = β 1 cos 2 ω + β 2 sin 2 ω + β 3 cos ω + β 4 sin ω + β 5 , β 1 = κ 1 − κ 2 2 , β 2 = κ 3 2 , β 3 = κ 4 , β 4 = κ 5 , β 5 = κ 1 + κ 2 2 + κ 6 . (40) \begin{aligned}
g(\omega)&=\beta_1\cos2\omega+\beta_2\sin2\omega+\beta_3\cos\omega+\beta_4\sin\omega+\beta_5,\\
\beta_1&=\frac{\kappa_1-\kappa_2}{2},\qquad
\beta_2=\frac{\kappa_3}{2},\qquad
\beta_3=\kappa_4,\qquad
\beta_4=\kappa_5,\qquad
\beta_5=\frac{\kappa_1+\kappa_2}{2}+\kappa_6. \tag*{(40)}
\end{aligned} g ( ω ) β 1 = β 1 cos 2 ω + β 2 sin 2 ω + β 3 cos ω + β 4 sin ω + β 5 , = 2 κ 1 − κ 2 , β 2 = 2 κ 3 , β 3 = κ 4 , β 4 = κ 5 , β 5 = 2 κ 1 + κ 2 + κ 6 . (40)
To find the zeros, substitute s = tan ( ω / 2 ) s=\tan(\omega/2) s = tan ( ω /2 ) , so that
cos ω = 1 − s 2 1 + s 2 , sin ω = 2 s 1 + s 2 , cos 2 ω = 1 − 6 s 2 + s 4 ( 1 + s 2 ) 2 , sin 2 ω = 4 s − 4 s 3 ( 1 + s 2 ) 2 . \cos\omega=\frac{1-s^2}{1+s^2},\qquad
\sin\omega=\frac{2s}{1+s^2},\qquad
\cos2\omega=\frac{1-6s^2+s^4}{(1+s^2)^2},\qquad
\sin2\omega=\frac{4s-4s^3}{(1+s^2)^2}. cos ω = 1 + s 2 1 − s 2 , sin ω = 1 + s 2 2 s , cos 2 ω = ( 1 + s 2 ) 2 1 − 6 s 2 + s 4 , sin 2 ω = ( 1 + s 2 ) 2 4 s − 4 s 3 .
Algorithm B.1 One step of the hit-and-run kernel on the trajectory event
Require: current Q ∈ S Q , τ \mathbf{Q} \in\mathcal{S}_{\mathbf{Q},\tau} Q ∈ S Q , τ ; H \mathbf{H} H , P 2 X \mathbf{P}_{2\mathbf{X}} P 2 X , and the observed sequence τ \tau τ
Draw a pair of rows i < j i<j i < j uniformly from { 1 , … , r − 1 } \{1,\ldots,r-1\} { 1 , … , r − 1 }
Form Y 0 , Y 1 , Y 2 \mathbf{Y}_0,\mathbf{Y}_1,\mathbf{Y}_2 Y 0 , Y 1 , Y 2 from (39) and the centroid coefficients y ˉ 0 , ℓ ( t ) , y ˉ 1 , ℓ ( t ) , y ˉ 2 , ℓ ( t ) \bar{y}^{(t)}_{0,\ell},\bar{y}^{(t)}_{1,\ell},\bar{y}^{(t)}_{2,\ell} y ˉ 0 , ℓ ( t ) , y ˉ 1 , ℓ ( t ) , y ˉ 2 , ℓ ( t )
for each constraint ( t , k , ℓ ) (t,k,\ell) ( t , k , ℓ ) do
Compute β 1 , … , β 5 \beta_1,\ldots,\beta_5 β 1 , … , β 5 from (40) ; skip the constraint if it holds on the whole circle
Add the real roots of (41) , mapped to angles, to the list of endpoints (and π \pi π if g ( π ) = 0 g(\pi)=0 g ( π ) = 0 )
end for
Keep the intervals between consecutive endpoints whose midpoints satisfy every constraint, giving S ω = ⋃ a [ ω a l o , ω a h i ] \mathcal{S}_{\omega}=\bigcup_a[\omega_a^{\mathrm{lo}},\omega_a^{\mathrm{hi}}] S ω = ⋃ a [ ω a lo , ω a hi ]
Draw ω \omega ω uniformly on S ω \mathcal{S}_{\omega} S ω
Ensure: G i j ( ω ) Q \mathbf{G}_{ij}(\omega)\mathbf{Q} G ij ( ω ) Q
Multiplying g g g by ( 1 + s 2 ) 2 (1+s^2)^2 ( 1 + s 2 ) 2 gives the polynomial
φ ( s ) = ( β 1 + β 3 + β 5 ) + ( 4 β 2 + 2 β 4 ) s + ( 2 β 5 − 6 β 1 ) s 2 + ( 2 β 4 − 4 β 2 ) s 3 + ( β 1 − β 3 + β 5 ) s 4 . (41) \varphi(s)=(\beta_1+\beta_3+\beta_5)+(4\beta_2+2\beta_4)s+(2\beta_5-6\beta_1)s^2+(2\beta_4-4\beta_2)s^3+(\beta_1-\beta_3+\beta_5)s^4. \tag*{(41)} φ ( s ) = ( β 1 + β 3 + β 5 ) + ( 4 β 2 + 2 β 4 ) s + ( 2 β 5 − 6 β 1 ) s 2 + ( 2 β 4 − 4 β 2 ) s 3 + ( β 1 − β 3 + β 5 ) s 4 . (41)
Each real root s ∗ s_* s ∗ of φ \varphi φ gives a zero ω ∗ = 2 arctan s ∗ \omega_*=2\arctan s_* ω ∗ = 2 arctan s ∗ of g g g , and every zero of g g g in ( − π , π ) (-\pi,\pi) ( − π , π ) arises this way. The substitution misses only ω = π \omega=\pi ω = π , where s = tan ( ω / 2 ) s=\tan(\omega/2) s = tan ( ω /2 ) is infinite. At ω = π \omega=\pi ω = π ,
g ( π ) = β 1 − β 3 + β 5 , g(\pi)=\beta_1-\beta_3+\beta_5, g ( π ) = β 1 − β 3 + β 5 ,
which is the leading coefficient of φ \varphi φ . So ω = π \omega=\pi ω = π is a zero exactly when φ \varphi φ has degree at most three.
We can now count the zeros. If g g g is identically zero, the constraint g ≤ 0 g\leq0 g ≤ 0 holds on the whole circle and plays no role. Otherwise, either g ( π ) ≠ 0 g(\pi)\ne0 g ( π ) = 0 and the zeros of g g g are the at most four real roots of the quartic φ \varphi φ , or g ( π ) = 0 g(\pi)=0 g ( π ) = 0 and the zeros are ω = π \omega=\pi ω = π and the at most three real roots of the cubic φ \varphi φ . In both cases g g g has at most four zeros on the circle.
Finally, each g t , k , ℓ g_{t,k,\ell} g t , k , ℓ is continuous in ω \omega ω , so it keeps its sign between two consecutive zeros. Take all the zeros of all the constraints together and sort them by increasing angle in [ 0 , 2 π ) [0,2\pi) [ 0 , 2 π ) . On each interval between two consecutive zeros, every constraint keeps its sign, so either every point of the interval satisfies all the constraints or none does. The feasible set on the circle is therefore a union of intervals whose endpoints are among these zeros. There are at most four zeros per constraint, so the number of intervals is at most four times the number of constraints; a single constraint alone gives at most two intervals.
We also note two shortcuts that further reduce the computational cost. First, some constraints hold on the whole circle and can be dropped. The two pairs of terms in (40) are bounded, ∣ β 1 cos 2 ω + β 2 sin 2 ω ∣ ≤ β 1 2 + β 2 2 |\beta_1\cos2\omega+\beta_2\sin2\omega|\leq\sqrt{\beta_1^2+\beta_2^2} ∣ β 1 cos 2 ω + β 2 sin 2 ω ∣ ≤ β 1 2 + β 2 2 and ∣ β 3 cos ω + β 4 sin ω ∣ ≤ β 3 2 + β 4 2 |\beta_3\cos\omega+\beta_4\sin\omega|\leq\sqrt{\beta_3^2+\beta_4^2} ∣ β 3 cos ω + β 4 sin ω ∣ ≤ β 3 2 + β 4 2 , so if
β 5 + β 1 2 + β 2 2 + β 3 2 + β 4 2 < 0 , \beta_5+\sqrt{\beta_1^2+\beta_2^2}+\sqrt{\beta_3^2+\beta_4^2}<0, β 5 + β 1 2 + β 2 2 + β 3 2 + β 4 2 < 0 ,
then g ( ω ) < 0 g(\omega)<0 g ( ω ) < 0 for every ω \omega ω , and the constraint can be skipped. Second, the feasible set can be read off from the zeros of the remaining constraints. Sort these zeros by increasing angle from 0 0 0 to 2 π 2\pi 2 π , and add 0 0 0 and 2 π 2\pi 2 π as the first and last points. On each interval between two consecutive points, the proof above shows that either every point is feasible or none is, so it is enough to check one point, the midpoint, against all the constraints. Keep the intervals whose midpoint is feasible, and merge neighboring kept intervals into one. Algorithm B.1 gives one step of the hit-and-run kernel. We checked the closed-form intervals against a dense grid of angles: they agreed at all 400,000 grid points we tried.
Reversibility of the hit-and-run kernel
This subsection proves that the hit-and-run kernel of § 4.4 is reversible with respect to the uniform distribution on S S S , which is all that Proposition 4.2 requires. The proof does not use the quadratic form of S S S ; it holds for any set S S S with ∫ 1 S ( Q ) d Q > 0 \int1_{S}(\mathbf{Q})\,\mathrm{d}\mathbf{Q}>0 ∫ 1 S ( Q ) d Q > 0 .
Fix a pair of rows i < j i<j i < j . Rotating rows i i i and j j j of Q \mathbf{Q} Q by every angle ω ∈ [ 0 , 2 π ) \omega\in[0,2\pi) ω ∈ [ 0 , 2 π ) gives the points G i j ( ω ) Q \mathbf{G}_{ij}(\omega)\mathbf{Q} G ij ( ω ) Q , which form a closed curve through Q \mathbf{Q} Q in St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) ; we call this curve the circle through Q \mathbf{Q} Q . (Figure 3 (b) shows the data along such a circle, and Figure 3 (c) shows the angles ω \omega ω .) The fraction of this circle that lies in S S S is
z ( Q ) = 1 2 π ∫ 0 2 π 1 S ( G i j ( ω ) Q ) d ω . z(\mathbf{Q})=\frac{1}{2\pi}\int_{0}^{2\pi}1_{S}(\mathbf{G}_{ij}(\omega)\mathbf{Q})\,\mathrm{d}\omega. z ( Q ) = 2 π 1 ∫ 0 2 π 1 S ( G ij ( ω ) Q ) d ω .
The kernel K i j \mathcal{K}_{ij} K ij moves Q \mathbf{Q} Q to G i j ( ω ) Q \mathbf{G}_{ij}(\omega)\mathbf{Q} G ij ( ω ) Q with ω \omega ω drawn uniformly from the feasible angles { ω : G i j ( ω ) Q ∈ S } \{\omega:\mathbf{G}_{ij}(\omega)\mathbf{Q}\in S\} { ω : G ij ( ω ) Q ∈ S } . So, when z ( Q ) > 0 z(\mathbf{Q})>0 z ( Q ) > 0 , the expected value of a bounded function h h h after one step is
( K i j h ) ( Q ) = ∫ 0 2 π 1 S ( G i j ( ω ) Q ) h ( G i j ( ω ) Q ) d ω ∫ 0 2 π 1 S ( G i j ( ω ) Q ) d ω , (42) (\mathcal{K}_{ij}h)(\mathbf{Q})=\frac{\int_{0}^{2\pi}1_{S}(\mathbf{G}_{ij}(\omega)\mathbf{Q})h(\mathbf{G}_{ij}(\omega)\mathbf{Q})\,\mathrm{d}\omega}{\int_{0}^{2\pi}1_{S}(\mathbf{G}_{ij}(\omega)\mathbf{Q})\,\mathrm{d}\omega}, \tag*{(42)} ( K ij h ) ( Q ) = ∫ 0 2 π 1 S ( G ij ( ω ) Q ) d ω ∫ 0 2 π 1 S ( G ij ( ω ) Q ) h ( G ij ( ω ) Q ) d ω , (42)
and K i j \mathcal{K}_{ij} K ij leaves Q \mathbf{Q} Q in place when z ( Q ) = 0 z(\mathbf{Q})=0 z ( Q ) = 0 . The hit-and-run kernel K \mathcal{K} K draws the pair i < j i<j i < j uniformly and then applies K i j \mathcal{K}_{ij} K ij .
Two facts about circles drive the proof. First, a function that depends on Q \mathbf{Q} Q only through its circle takes the same value at G i j ( ψ ) Q \mathbf{G}_{ij}(\psi)\mathbf{Q} G ij ( ψ ) Q as at Q \mathbf{Q} Q for every ψ \psi ψ ; examples are z z z and K i j h \mathcal{K}_{ij}h K ij h , because replacing Q \mathbf{Q} Q by G i j ( ψ ) Q \mathbf{G}_{ij}(\psi)\mathbf{Q} G ij ( ψ ) Q only shifts the angle of integration. Second, the uniform distribution on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) is unchanged by multiplying on the left by an orthogonal matrix, so ∫ h ( G i j ( ω ) Q ) d Q = ∫ h ( Q ) d Q \int h(\mathbf{G}_{ij}(\omega)\mathbf{Q})\,\mathrm{d}\mathbf{Q}=\int h(\mathbf{Q})\,\mathrm{d}\mathbf{Q} ∫ h ( G ij ( ω ) Q ) d Q = ∫ h ( Q ) d Q for every ω \omega ω . Averaging this identity over ω \omega ω , and then applying it to a product g h gh g h in which g g g depends on Q \mathbf{Q} Q only through its circle, gives
∫ g ( Q ) h ( Q ) d Q = ∫ g ( Q ) { 1 2 π ∫ 0 2 π h ( G i j ( ω ) Q ) d ω } d Q . (43) \int g(\mathbf{Q})h(\mathbf{Q})\,\mathrm{d}\mathbf{Q}
=
\int g(\mathbf{Q})\left\{\frac{1}{2\pi}\int_{0}^{2\pi}h(\mathbf{G}_{ij}(\omega)\mathbf{Q})\,\mathrm{d}\omega\right\}\mathrm{d}\mathbf{Q}. \tag*{(43)} ∫ g ( Q ) h ( Q ) d Q = ∫ g ( Q ) { 2 π 1 ∫ 0 2 π h ( G ij ( ω ) Q ) d ω } d Q . (43)
In words, inside an integral against d Q \mathrm{d}\mathbf{Q} d Q , h h h can be replaced by its average over the circle.
Proposition B.1 (Reversibility of the hit-and-run kernel). Each K i j \mathcal{K}_{ij} K ij , the kernel K \mathcal{K} K , and every power K L \mathcal{K}^{L} K L are reversible with respect to the uniform distribution on S S S .
Proof. By definition, K i j \mathcal{K}_{ij} K ij is reversible with respect to the uniform distribution on S S S if moving from Q \mathbf{Q} Q to a new point is as likely as moving back. Equivalently, for all bounded functions h 1 h_{1} h 1 and h 2 h_{2} h 2 , the integral ∫ 1 S ( Q ) h 1 ( Q ) ( K i j h 2 ) ( Q ) d Q \int1_{S}(\mathbf{Q})h_{1}(\mathbf{Q})(\mathcal{K}_{ij}h_{2})(\mathbf{Q})\,\mathrm{d}\mathbf{Q} ∫ 1 S ( Q ) h 1 ( Q ) ( K ij h 2 ) ( Q ) d Q is unchanged by swapping h 1 h_{1} h 1 and h 2 h_{2} h 2 .
Step 1: z ( Q ) > 0 z(\mathbf{Q})>0 z ( Q ) > 0 for almost every Q ∈ S \mathbf{Q}\in S Q ∈ S . Formula (42) needs z ( Q ) > 0 z(\mathbf{Q})>0 z ( Q ) > 0 , that is, a circle with a feasible arc of positive length. Applying (43) with g = 1 { z = 0 } g=1_{\{z=0\}} g = 1 { z = 0 } and h = 1 S h=1_{S} h = 1 S ,
∫ 1 { z ( Q ) = 0 } 1 S ( Q ) d Q = ∫ 1 { z ( Q ) = 0 } z ( Q ) d Q = 0. \int1_{\{z(\mathbf{Q})=0\}}1_{S}(\mathbf{Q})\,\mathrm{d}\mathbf{Q}
=
\int1_{\{z(\mathbf{Q})=0\}}z(\mathbf{Q})\,\mathrm{d}\mathbf{Q}=0. ∫ 1 { z ( Q ) = 0 } 1 S ( Q ) d Q = ∫ 1 { z ( Q ) = 0 } z ( Q ) d Q = 0.
So the other case has probability zero.
Step 2: symmetry. The function K i j h 2 \mathcal{K}_{ij}h_{2} K ij h 2 depends on Q \mathbf{Q} Q only through its circle, so (43) with g = K i j h 2 g=\mathcal{K}_{ij}h_{2} g = K ij h 2 and h = 1 S h 1 h=1_{S}h_{1} h = 1 S h 1 , followed by (42) , gives
∫ 1 S ( Q ) h 1 ( Q ) ( K i j h 2 ) ( Q ) d Q = ∫ { z > 0 } 1 z ( Q ) { 1 2 π ∫ 0 2 π ( 1 S h 1 ) ( G i j ( ω ) Q ) d ω } { 1 2 π ∫ 0 2 π ( 1 S h 2 ) ( G i j ( ω ) Q ) d ω } d Q . \int1_{S}(\mathbf{Q})h_{1}(\mathbf{Q})(\mathcal{K}_{ij}h_{2})(\mathbf{Q})\,\mathrm{d}\mathbf{Q}
=
\int_{\{z>0\}}\frac{1}{z(\mathbf{Q})}
\left\{\frac{1}{2\pi}\int_{0}^{2\pi}(1_{S}h_{1})(\mathbf{G}_{ij}(\omega)\mathbf{Q})\,\mathrm{d}\omega\right\}
\left\{\frac{1}{2\pi}\int_{0}^{2\pi}(1_{S}h_{2})(\mathbf{G}_{ij}(\omega)\mathbf{Q})\,\mathrm{d}\omega\right\}\mathrm{d}\mathbf{Q}. ∫ 1 S ( Q ) h 1 ( Q ) ( K ij h 2 ) ( Q ) d Q = ∫ { z > 0 } z ( Q ) 1 { 2 π 1 ∫ 0 2 π ( 1 S h 1 ) ( G ij ( ω ) Q ) d ω } { 2 π 1 ∫ 0 2 π ( 1 S h 2 ) ( G ij ( ω ) Q ) d ω } d Q .
The right side is symmetric in h 1 h_1 h 1 and h 2 h_2 h 2 , so K i j K_{ij} K ij is reversible. Finally, K \mathcal{K} K averages the kernels K i j K_{ij} K ij with weights that do not depend on Q Q Q , and an average of reversible kernels is reversible. A power of a reversible kernel is reversible too, so K L \mathcal{K}^{L} K L is.
Two remarks complete the picture. First, reversibility is all that the exactness of the test needs: the kernel need not reach every part of S \mathcal{S} S , which can be disconnected. How well it moves through S \mathcal{S} S affects only the power, which is why the path length M M M and the number of steps L L L matter (§ 4.2 ). Second, the pair of rows is drawn afresh at every step, independently of Q Q Q , so it is part of the kernel and not an extra condition; keeping one pair fixed for the whole path would keep the path on one circle.
Proof of Proposition 3.4
This subsection proves Proposition 3.4, the one-dimensional selective p p p -value, in three steps. We first describe all polar factors with the same coordinates Γ \boldsymbol{\Gamma} Γ (Proposition B.2), then show that u ( Q ) u(Q) u ( Q ) is independent of Γ \boldsymbol{\Gamma} Γ , and finally condition on the clustering.
In coordinates, write u = u ( Q ) = ∥ Q T a ∥ 2 2 u=u(Q)=\lVert Q^{\mathsf{T}}a\rVert_{2}^{2} u = u ( Q ) = ∥ Q T a ∥ 2 2 with 0 < u < 1 0<u<1 0 < u < 1 . Since γ = dir ( Q T a ) \gamma=\operatorname{dir}(Q^{\mathsf{T}}a) γ = dir ( Q T a ) , we have Q T a = u γ Q^{\mathsf{T}}a=\sqrt{u}\,\gamma Q T a = u γ . Let q = Q γ q=Q\gamma q = Q γ , a unit vector with a T q = u a^{\mathsf{T}}q=\sqrt{u} a T q = u , and split it into its parts along a a a and orthogonal to a a a :
q = u a + 1 − u w , w = q − u a 1 − u , (44) q=\sqrt{u}\,a+\sqrt{1-u}\,w,\qquad w=\frac{q-\sqrt{u}\,a}{\sqrt{1-u}}, \tag*{(44)} q = u a + 1 − u w , w = 1 − u q − u a , (44)
where w w w is the within-cluster direction dir ( P 1 q ) \operatorname{dir}(P_1q) dir ( P 1 q ) in coordinates. With B = Q ( I p − γ γ T ) B=Q(I_p-\gamma\gamma^{\mathsf{T}}) B = Q ( I p − γ γ T ) , the coordinates of Section 3.4 are Γ = ( γ , w , B ) \boldsymbol{\Gamma}=(\gamma,w,B) Γ = ( γ , w , B ) , and
Q = Q γ γ T + Q ( I p − γ γ T ) = B + ( u a + 1 − u w ) γ T . (45) Q=Q\gamma\gamma^{\mathsf{T}}+Q(I_p-\gamma\gamma^{\mathsf{T}})=B+(\sqrt{u}\,a+\sqrt{1-u}\,w)\gamma^{\mathsf{T}}. \tag*{(45)} Q = Q γ γ T + Q ( I p − γ γ T ) = B + ( u a + 1 − u w ) γ T . (45)
Proposition B.2 (Polar factors with the same Γ \boldsymbol{\Gamma} Γ ). The coordinates ( γ , w , B ) (\gamma,w,B) ( γ , w , B ) satisfy
∥ γ ∥ 2 = ∥ w ∥ 2 = 1 , a T w = 0 , B γ = 0 , B T a = B T w = 0 , B T B = I p − γ γ T . (46) \lVert\gamma\rVert_2=\lVert w\rVert_2=1,\qquad a^{\mathsf{T}}w=0,\qquad B\gamma=0,\qquad B^{\mathsf{T}}a=B^{\mathsf{T}}w=0,\qquad B^{\mathsf{T}}B=I_p-\gamma\gamma^{\mathsf{T}}. \tag*{(46)} ∥ γ ∥ 2 = ∥ w ∥ 2 = 1 , a T w = 0 , B γ = 0 , B T a = B T w = 0 , B T B = I p − γ γ T . (46) Conversely, for every triple ( γ , w , B ) (\gamma,w,B) ( γ , w , B ) that satisfies (46) and every u ∈ ( 0 , 1 ) u\in(0,1) u ∈ ( 0 , 1 ) , the matrix B + ( u a + 1 − u w ) γ T B+(\sqrt{u}\,a+\sqrt{1-u}\,w)\gamma^{\mathsf{T}} B + ( u a + 1 − u w ) γ T lies in St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) and has coordinates ( γ , w , B ) (\gamma,w,B) ( γ , w , B ) and between-cluster fraction u u u . Hence the polar factors with the same Γ \boldsymbol{\Gamma} Γ as Q Q Q form the curve
Q Γ ( ϕ ) = B + ( cos ϕ a + sin ϕ w ) γ T , 0 < ϕ < π / 2 , (47) Q_{\boldsymbol{\Gamma}}(\phi)=B+(\cos\phi\,a+\sin\phi\,w)\gamma^{\mathsf{T}},\qquad0<\phi<\pi/2, \tag*{(47)} Q Γ ( ϕ ) = B + ( cos ϕ a + sin ϕ w ) γ T , 0 < ϕ < π /2 , (47) along which u ( Q Γ ( ϕ ) ) = cos 2 ϕ u(Q_{\boldsymbol{\Gamma}}(\phi))=\cos^2\phi u ( Q Γ ( ϕ )) = cos 2 ϕ .
Proof. We check (46) one identity at a time. The vector γ \gamma γ is a direction, and w w w has length one because ∥ q − u a ∥ 2 2 = 1 − 2 u + u = 1 − u \lVert q-\sqrt{u}\,a\rVert_2^2=1-2u+u=1-u ∥ q − u a ∥ 2 2 = 1 − 2 u + u = 1 − u . Next, a T w = ( u − u ) / 1 − u = 0 a^{\mathsf{T}}w=(\sqrt{u}-\sqrt{u})/\sqrt{1-u}=0 a T w = ( u − u ) / 1 − u = 0 , and B γ = Q ( γ − γ ) = 0 B\gamma=Q(\gamma-\gamma)=0 B γ = Q ( γ − γ ) = 0 . For the products with B B B ,
B T a = ( I p − γ γ T ) Q T a = u ( I p − γ γ T ) γ = 0 , B T q = ( I p − γ γ T ) Q T Q γ = ( I p − γ γ T ) γ = 0 , B^{\mathsf{T}}a=(I_p-\gamma\gamma^{\mathsf{T}})Q^{\mathsf{T}}a=\sqrt{u}(I_p-\gamma\gamma^{\mathsf{T}})\gamma=0,\qquad B^{\mathsf{T}}q=(I_p-\gamma\gamma^{\mathsf{T}})Q^{\mathsf{T}}Q\gamma=(I_p-\gamma\gamma^{\mathsf{T}})\gamma=0, B T a = ( I p − γ γ T ) Q T a = u ( I p − γ γ T ) γ = 0 , B T q = ( I p − γ γ T ) Q T Q γ = ( I p − γ γ T ) γ = 0 ,
and B T w B^{\mathsf{T}}w B T w is a combination of these two, so it is zero too. Finally,
B T B = ( I p − γ γ T ) Q T Q ( I p − γ γ T ) = I p − γ γ T . B^{\mathsf{T}}B=(I_p-\gamma\gamma^{\mathsf{T}})Q^{\mathsf{T}}Q(I_p-\gamma\gamma^{\mathsf{T}})=I_p-\gamma\gamma^{\mathsf{T}}. B T B = ( I p − γ γ T ) Q T Q ( I p − γ γ T ) = I p − γ γ T .
For the converse, fix a triple that satisfies (46) and u ∈ ( 0 , 1 ) u\in(0,1) u ∈ ( 0 , 1 ) , and let q u = u a + 1 − u w q_u=\sqrt{u}\,a+\sqrt{1-u}\,w q u = u a + 1 − u w and Q u = B + q u γ T Q_u=B+q_u\gamma^{\mathsf{T}} Q u = B + q u γ T . The vector q u q_u q u has length one, because a a a and w w w are orthogonal unit vectors, and B T q u = 0 B^{\mathsf{T}}q_u=0 B T q u = 0 . So
Q u T Q u = B T B + γ q u T q u γ T = I p − γ γ T + γ γ T = I p , Q_u^{\mathsf{T}}Q_u=B^{\mathsf{T}}B+\gamma q_u^{\mathsf{T}}q_u\gamma^{\mathsf{T}}=I_p-\gamma\gamma^{\mathsf{T}}+\gamma\gamma^{\mathsf{T}}=I_p, Q u T Q u = B T B + γ q u T q u γ T = I p − γ γ T + γ γ T = I p ,
@page 37/50 starts_mid=1 ends_mid=1 The right side is symmetric in h 1 h_1 h 1 and h 2 h_2 h 2 , so K i j K_{ij} K ij is reversible. Finally, K \mathcal{K} K averages the kernels K i j K_{ij} K ij with weights that do not depend on Q Q Q , and an average of reversible kernels is reversible. A power of a reversible kernel is reversible too, so K L \mathcal{K}^{L} K L is.
Two remarks complete the picture. First, reversibility is all that the exactness of the test needs: the kernel need not reach every part of S \mathcal{S} S , which can be disconnected. How well it moves through S \mathcal{S} S affects only the power, which is why the path length M M M and the number of steps L L L matter (§ 4.2 ). Second, the pair of rows is drawn afresh at every step, independently of Q Q Q , so it is part of the kernel and not an extra condition; keeping one pair fixed for the whole path would keep the path on one circle.
Proof of Proposition 3.4
This subsection proves Proposition 3.4, the one-dimensional selective p p p -value, in three steps. We first describe all polar factors with the same coordinates Γ \boldsymbol{\Gamma} Γ (Proposition B.2), then show that u ( Q ) u(Q) u ( Q ) is independent of Γ \boldsymbol{\Gamma} Γ , and finally condition on the clustering.
In coordinates, write u = u ( Q ) = ∥ Q T a ∥ 2 2 u=u(Q)=\lVert Q^{\mathsf{T}}a\rVert_{2}^{2} u = u ( Q ) = ∥ Q T a ∥ 2 2 with 0 < u < 1 0<u<1 0 < u < 1 . Since γ = dir ( Q T a ) \gamma=\operatorname{dir}(Q^{\mathsf{T}}a) γ = dir ( Q T a ) , we have Q T a = u γ Q^{\mathsf{T}}a=\sqrt{u}\,\gamma Q T a = u γ . Let q = Q γ q=Q\gamma q = Q γ , a unit vector with a T q = u a^{\mathsf{T}}q=\sqrt{u} a T q = u , and split it into its parts along a a a and orthogonal to a a a :
q = u a + 1 − u w , w = q − u a 1 − u , (48) q=\sqrt{u}\,a+\sqrt{1-u}\,w,\qquad w=\frac{q-\sqrt{u}\,a}{\sqrt{1-u}}, \tag*{(48)} q = u a + 1 − u w , w = 1 − u q − u a , (48)
where w w w is the within-cluster direction dir ( P 1 q ) \operatorname{dir}(P_1q) dir ( P 1 q ) in coordinates. With B = Q ( I p − γ γ T ) B=Q(I_p-\gamma\gamma^{\mathsf{T}}) B = Q ( I p − γ γ T ) , the coordinates of Section 3.4 are Γ = ( γ , w , B ) \boldsymbol{\Gamma}=(\gamma,w,B) Γ = ( γ , w , B ) , and
Q = Q γ γ T + Q ( I p − γ γ T ) = B + ( u a + 1 − u w ) γ T . (49) Q=Q\gamma\gamma^{\mathsf{T}}+Q(I_p-\gamma\gamma^{\mathsf{T}})=B+(\sqrt{u}\,a+\sqrt{1-u}\,w)\gamma^{\mathsf{T}}. \tag*{(49)} Q = Q γ γ T + Q ( I p − γ γ T ) = B + ( u a + 1 − u w ) γ T . (49)
Proposition B.2 (Polar factors with the same Γ \boldsymbol{\Gamma} Γ ). The coordinates ( γ , w , B ) (\gamma,w,B) ( γ , w , B ) satisfy
∥ γ ∥ 2 = ∥ w ∥ 2 = 1 , a T w = 0 , B γ = 0 , B T a = B T w = 0 , B T B = I p − γ γ T . (50) \lVert\gamma\rVert_2=\lVert w\rVert_2=1,\qquad a^{\mathsf{T}}w=0,\qquad B\gamma=0,\qquad B^{\mathsf{T}}a=B^{\mathsf{T}}w=0,\qquad B^{\mathsf{T}}B=I_p-\gamma\gamma^{\mathsf{T}}. \tag*{(50)} ∥ γ ∥ 2 = ∥ w ∥ 2 = 1 , a T w = 0 , B γ = 0 , B T a = B T w = 0 , B T B = I p − γ γ T . (50) Conversely, for every triple ( γ , w , B ) (\gamma,w,B) ( γ , w , B ) that satisfies (46) and every u ∈ ( 0 , 1 ) u\in(0,1) u ∈ ( 0 , 1 ) , the matrix B + ( u a + 1 − u w ) γ T B+(\sqrt{u}\,a+\sqrt{1-u}\,w)\gamma^{\mathsf{T}} B + ( u a + 1 − u w ) γ T lies in St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) and has coordinates ( γ , w , B ) (\gamma,w,B) ( γ , w , B ) and between-cluster fraction u u u . Hence the polar factors with the same Γ \boldsymbol{\Gamma} Γ as Q Q Q form the curve
Q Γ ( ϕ ) = B + ( cos ϕ a + sin ϕ w ) γ T , 0 < ϕ < π / 2 , (51) Q_{\boldsymbol{\Gamma}}(\phi)=B+(\cos\phi\,a+\sin\phi\,w)\gamma^{\mathsf{T}},\qquad0<\phi<\pi/2, \tag*{(51)} Q Γ ( ϕ ) = B + ( cos ϕ a + sin ϕ w ) γ T , 0 < ϕ < π /2 , (51) along which u ( Q Γ ( ϕ ) ) = cos 2 ϕ u(Q_{\boldsymbol{\Gamma}}(\phi))=\cos^2\phi u ( Q Γ ( ϕ )) = cos 2 ϕ .
Proof. We check (46) one identity at a time. The vector γ \gamma γ is a direction, and w w w has length one because ∥ q − u a ∥ 2 2 = 1 − 2 u + u = 1 − u \lVert q-\sqrt{u}\,a\rVert_2^2=1-2u+u=1-u ∥ q − u a ∥ 2 2 = 1 − 2 u + u = 1 − u . Next, a T w = ( u − u ) / 1 − u = 0 a^{\mathsf{T}}w=(\sqrt{u}-\sqrt{u})/\sqrt{1-u}=0 a T w = ( u − u ) / 1 − u = 0 , and B γ = Q ( γ − γ ) = 0 B\gamma=Q(\gamma-\gamma)=0 B γ = Q ( γ − γ ) = 0 . For the products with B B B ,
B T a = ( I p − γ γ T ) Q T a = u ( I p − γ γ T ) γ = 0 , B T q = ( I p − γ γ T ) Q T Q γ = ( I p − γ γ T ) γ = 0 , B^{\mathsf{T}}a=(I_p-\gamma\gamma^{\mathsf{T}})Q^{\mathsf{T}}a=\sqrt{u}(I_p-\gamma\gamma^{\mathsf{T}})\gamma=0,\qquad B^{\mathsf{T}}q=(I_p-\gamma\gamma^{\mathsf{T}})Q^{\mathsf{T}}Q\gamma=(I_p-\gamma\gamma^{\mathsf{T}})\gamma=0, B T a = ( I p − γ γ T ) Q T a = u ( I p − γ γ T ) γ = 0 , B T q = ( I p − γ γ T ) Q T Q γ = ( I p − γ γ T ) γ = 0 ,
and B T w B^{\mathsf{T}}w B T w is a combination of these two, so it is zero too. Finally,
B T B = ( I p − γ γ T ) Q T Q ( I p − γ γ T ) = I p − γ γ T . B^{\mathsf{T}}B=(I_p-\gamma\gamma^{\mathsf{T}})Q^{\mathsf{T}}Q(I_p-\gamma\gamma^{\mathsf{T}})=I_p-\gamma\gamma^{\mathsf{T}}. B T B = ( I p − γ γ T ) Q T Q ( I p − γ γ T ) = I p − γ γ T .
For the converse, fix a triple that satisfies (46) and u ∈ ( 0 , 1 ) u\in(0,1) u ∈ ( 0 , 1 ) , and let q u = u a + 1 − u w q_u=\sqrt{u}\,a+\sqrt{1-u}\,w q u = u a + 1 − u w and Q u = B + q u γ T Q_u=B+q_u\gamma^{\mathsf{T}} Q u = B + q u γ T . The vector q u q_u q u has length one, because a a a and w w w are orthogonal unit vectors, and B T q u = 0 B^{\mathsf{T}}q_u=0 B T q u = 0 . So
Q u T Q u = B T B + γ q u T q u γ T = I p − γ γ T + γ γ T = I p , (52) Q_u^{\mathsf{T}}Q_u=B^{\mathsf{T}}B+\gamma q_u^{\mathsf{T}}q_u\gamma^{\mathsf{T}}=I_p-\gamma\gamma^{\mathsf{T}}+\gamma\gamma^{\mathsf{T}}=I_p, \tag*{(52)} Q u T Q u = B T B + γ q u T q u γ T = I p − γ γ T + γ γ T = I p , (52)
and Q u ∈ St ( r − 1 , p ) \mathbf{Q}_u \in\operatorname{St}(r-1,p) Q u ∈ St ( r − 1 , p ) . Its coordinates are the given ones: Q u T a = B T a + γ q u T a = u γ \mathbf{Q}_u^{\mathsf{T}}\mathbf{a}=\mathbf{B}^{\mathsf{T}}\mathbf{a}+\gamma\mathbf{q}_u^{\mathsf{T}}\mathbf{a}=\sqrt{u}\gamma Q u T a = B T a + γ q u T a = u γ , so u ( Q u ) = u u(\mathbf{Q}_u)=u u ( Q u ) = u and the direction of Q u T a \mathbf{Q}_u^{\mathsf{T}}\mathbf{a} Q u T a is γ \gamma γ ; then Q u γ = B γ + q u = q u \mathbf{Q}_u\gamma=\mathbf{B}\gamma+\mathbf{q}_u=\mathbf{q}_u Q u γ = B γ + q u = q u , whose split (44) returns w \mathbf{w} w ; and Q u ( I p − γ γ T ) = B − B γ γ T = B \mathbf{Q}_u(\mathbf{I}_p-\gamma\gamma^{\mathsf{T}})=\mathbf{B}-\mathbf{B}\gamma\gamma^{\mathsf{T}}=\mathbf{B} Q u ( I p − γ γ T ) = B − B γ γ T = B . Writing u = cos 2 ϕ u=\cos^2\phi u = cos 2 ϕ with ϕ ∈ ( 0 , π / 2 ) \phi\in(0,\pi/2) ϕ ∈ ( 0 , π /2 ) gives (47).
Proof of the independence in Proposition 3.4. Under the null, Q \mathbf{Q} Q is uniformly distributed on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) (Theorem 3.1). We show that u u u and Γ \mathbf{\Gamma} Γ are independent, using maps that change Γ \mathbf{\Gamma} Γ but not u u u or the distribution of Q \mathbf{Q} Q . Call a triple admissible if it satisfies (46). By Proposition B.2, the set of admissible triples does not depend on u u u .
Step 1: the maps. Let O 1 \mathbf{O}_1 O 1 be an ( r − 1 ) × ( r − 1 ) (r-1)\times(r-1) ( r − 1 ) × ( r − 1 ) orthogonal matrix with O 1 a = a \mathbf{O}_1\mathbf{a}=\mathbf{a} O 1 a = a , and O 2 \mathbf{O}_2 O 2 a p × p p\times p p × p orthogonal matrix. The map Q ↦ O 1 Q O 2 T \mathbf{Q}\mapsto\mathbf{O}_1\mathbf{Q}\mathbf{O}_2^{\mathsf{T}} Q ↦ O 1 Q O 2 T does not change the uniform distribution on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) . It keeps u u u , because ( O 1 Q O 2 T ) T a = O 2 Q T a (\mathbf{O}_1\mathbf{Q}\mathbf{O}_2^{\mathsf{T}})^{\mathsf{T}}\mathbf{a}=\mathbf{O}_2\mathbf{Q}^{\mathsf{T}}\mathbf{a} ( O 1 Q O 2 T ) T a = O 2 Q T a has the same length as Q T a \mathbf{Q}^{\mathsf{T}}\mathbf{a} Q T a , and it changes the coordinates to ( O 2 γ , O 1 w , O 1 B O 2 T ) (\mathbf{O}_2\gamma,\mathbf{O}_1\mathbf{w},\mathbf{O}_1\mathbf{B}\mathbf{O}_2^{\mathsf{T}}) ( O 2 γ , O 1 w , O 1 B O 2 T ) .
Step 2: the maps reach every admissible triple. Take two admissible triples ( γ 1 , w 1 , B 1 ) (\gamma_1,\mathbf{w}_1,\mathbf{B}_1) ( γ 1 , w 1 , B 1 ) and ( γ 2 , w 2 , B 2 ) (\gamma_2,\mathbf{w}_2,\mathbf{B}_2) ( γ 2 , w 2 , B 2 ) . Choose O 2 \mathbf{O}_2 O 2 with O 2 γ 1 = γ 2 \mathbf{O}_2\gamma_1=\gamma_2 O 2 γ 1 = γ 2 , and let B ~ = B 1 O 2 T \widetilde{\mathbf{B}}=\mathbf{B}_1\mathbf{O}_2^{\mathsf{T}} B = B 1 O 2 T . Let v 1 , … , v p − 1 \mathbf{v}_1,\ldots,\mathbf{v}_{p-1} v 1 , … , v p − 1 be an orthonormal basis of the vectors orthogonal to γ 2 \gamma_2 γ 2 . By (46), the two lists
B ~ v 1 , … , B ~ v p − 1 , w 1 and B 2 v 1 , … , B 2 v p − 1 , w 2 \widetilde{\mathbf{B}}\mathbf{v}_1,\ldots,\widetilde{\mathbf{B}}\mathbf{v}_{p-1},\mathbf{w}_1
\qquad\text{and}\qquad
\mathbf{B}_2\mathbf{v}_1,\ldots,\mathbf{B}_2\mathbf{v}_{p-1},\mathbf{w}_2 B v 1 , … , B v p − 1 , w 1 and B 2 v 1 , … , B 2 v p − 1 , w 2
each consist of p p p orthonormal vectors orthogonal to a \mathbf{a} a . The vectors orthogonal to a \mathbf{a} a form a space of dimension r − 2 ≥ p r-2\ge p r − 2 ≥ p , so there is an orthogonal O 1 \mathbf{O}_1 O 1 with O 1 a = a \mathbf{O}_1\mathbf{a}=\mathbf{a} O 1 a = a that maps the first list to the second. Then O 1 w 1 = w 2 \mathbf{O}_1\mathbf{w}_1=\mathbf{w}_2 O 1 w 1 = w 2 and O 1 B ~ = B 2 \mathbf{O}_1\widetilde{\mathbf{B}}=\mathbf{B}_2 O 1 B = B 2 , since both sides agree on v 1 , … , v p − 1 \mathbf{v}_1,\ldots,\mathbf{v}_{p-1} v 1 , … , v p − 1 and vanish on γ 2 \gamma_2 γ 2 . So ( O 1 , O 2 ) (\mathbf{O}_1,\mathbf{O}_2) ( O 1 , O 2 ) carries the first triple to the second. For p = 1 p=1 p = 1 , there are no v \mathbf{v} v 's.
Step 3: averaging. Draw ( O 1 , O 2 ) (\mathbf{O}_1,\mathbf{O}_2) ( O 1 , O 2 ) uniformly among such pairs, independently of Q \mathbf{Q} Q , and write ( O 1 , O 2 ) ⋅ Γ (\mathbf{O}_1,\mathbf{O}_2)\cdot\mathbf{\Gamma} ( O 1 , O 2 ) ⋅ Γ for the transformed coordinates. For a fixed admissible triple Γ 0 \mathbf{\Gamma}_0 Γ 0 , the distribution of ( O 1 , O 2 ) ⋅ Γ 0 (\mathbf{O}_1,\mathbf{O}_2)\cdot\mathbf{\Gamma}_0 ( O 1 , O 2 ) ⋅ Γ 0 does not depend on Γ 0 \mathbf{\Gamma}_0 Γ 0 : by Step 2, any other triple is a fixed map applied to Γ 0 \mathbf{\Gamma}_0 Γ 0 , and composing a uniform draw with a fixed map gives another uniform draw. So for a bounded function h 2 h_2 h 2 of the triple, h ˉ 2 = E [ h 2 ( ( O 1 , O 2 ) ⋅ Γ 0 ) ] \bar{h}_2=\mathbb{E}[h_2((\mathbf{O}_1,\mathbf{O}_2)\cdot\mathbf{\Gamma}_0)] h ˉ 2 = E [ h 2 (( O 1 , O 2 ) ⋅ Γ 0 )] is the same for every Γ 0 \mathbf{\Gamma}_0 Γ 0 . For a bounded function h 1 h_1 h 1 on ( 0 , 1 ) (0,1) ( 0 , 1 ) , Step 1 gives the first equality below:
E [ h 1 ( u ) h 2 ( Γ ) ] = E [ h 1 ( u ) h 2 ( ( O 1 , O 2 ) ⋅ Γ ) ] = E [ h 1 ( u ) E { h 2 ( ( O 1 , O 2 ) ⋅ Γ ) ∣ Q } ] = h ˉ 2 E [ h 1 ( u ) ] . \mathbb{E}[h_1(u)h_2(\mathbf{\Gamma})]
=\mathbb{E}[h_1(u)h_2((\mathbf{O}_1,\mathbf{O}_2)\cdot\mathbf{\Gamma})]
=\mathbb{E}\left[h_1(u)\mathbb{E}\{h_2((\mathbf{O}_1,\mathbf{O}_2)\cdot\mathbf{\Gamma})\mid\mathbf{Q}\}\right]
=\bar{h}_2\mathbb{E}[h_1(u)]. E [ h 1 ( u ) h 2 ( Γ )] = E [ h 1 ( u ) h 2 (( O 1 , O 2 ) ⋅ Γ )] = E [ h 1 ( u ) E { h 2 (( O 1 , O 2 ) ⋅ Γ ) ∣ Q } ] = h ˉ 2 E [ h 1 ( u )] .
Taking h 1 h_1 h 1 to be the constant 1 shows h ˉ 2 = E [ h 2 ( Γ ) ] \bar{h}_2=\mathbb{E}[h_2(\mathbf{\Gamma})] h ˉ 2 = E [ h 2 ( Γ )] , so E [ h 1 ( u ) h 2 ( Γ ) ] = E [ h 1 ( u ) ] E [ h 2 ( Γ ) ] \mathbb{E}[h_1(u)h_2(\mathbf{\Gamma})]=\mathbb{E}[h_1(u)]\mathbb{E}[h_2(\mathbf{\Gamma})] E [ h 1 ( u ) h 2 ( Γ )] = E [ h 1 ( u )] E [ h 2 ( Γ )] : the expectation factors, and u u u and Γ \mathbf{\Gamma} Γ are independent.
The factor cos p − 1 ϕ \cos^{p-1}\phi cos p − 1 ϕ in f f f is what a direct count misses. Given Γ \mathbf{\Gamma} Γ , the vector Q γ \mathbf{Q}\gamma Q γ lies on the unit sphere of the ( r − p ) (r-p) ( r − p ) -dimensional space orthogonal to the columns of B \mathbf{B} B . If it were uniform there, the angle would have density proportional to sin r − p − 2 ϕ \sin^{r-p-2}\phi sin r − p − 2 ϕ , which contradicts Proposition 3.2.
Proof of the conditional statement in Proposition 3.4. We condition on Γ \mathbf{\Gamma} Γ , H \mathbf{H} H , P 2 X \mathbf{P}_2\mathbf{X} P 2 X , and the clustering, in four steps. Write ϕ ∈ ( 0 , π / 2 ) \phi\in(0,\pi/2) ϕ ∈ ( 0 , π /2 ) for the angle with u = cos 2 ϕ u=\cos^2\phi u = cos 2 ϕ .
Step 1: the angle given ( Γ , H , P 2 X ) (\mathbf{\Gamma},\mathbf{H},\mathbf{P}_2\mathbf{X}) ( Γ , H , P 2 X ) . By Theorem 3.1, Q \mathbf{Q} Q is independent of ( H , P 2 X ) (\mathbf{H},\mathbf{P}_2\mathbf{X}) ( H , P 2 X ) , and by the independence just proved, u u u is independent of Γ \mathbf{\Gamma} Γ . So given ( Γ , H , P 2 X ) (\mathbf{\Gamma},\mathbf{H},\mathbf{P}_2\mathbf{X}) ( Γ , H , P 2 X ) , u u u keeps its Beta ( p / 2 , ( r − 1 − p ) / 2 ) \operatorname{Beta}(p/2,(r-1-p)/2) Beta ( p /2 , ( r − 1 − p ) /2 ) distribution, and the angle ϕ \phi ϕ has the density f f f of Section 4.3.
Step 2: the selection event in terms of the angle. Given ( Γ , H , P 2 X ) (\mathbf{\Gamma},\mathbf{H},\mathbf{P}_2\mathbf{X}) ( Γ , H , P 2 X ) , Proposition B.2 gives Q = Q Γ ( ϕ ) \mathbf{Q}=\mathbf{Q}_{\mathbf{\Gamma}}(\phi) Q = Q Γ ( ϕ ) , so the data are P 2 X + A Q Γ ( ϕ ) H \mathbf{P}_2\mathbf{X}+\mathbf{A}\mathbf{Q}_{\mathbf{\Gamma}}(\phi)\mathbf{H} P 2 X + A Q Γ ( ϕ ) H , a function of ϕ \phi ϕ alone. The clustering therefore returns C ^ 1 \widehat{\mathbf{C}}_1 C 1 and C ^ 2 \widehat{\mathbf{C}}_2 C 2 exactly when ϕ ∈ S θ \phi\in S_{\theta} ϕ ∈ S θ , with S θ S_{\theta} S θ in (18) computed from ( Γ , H , P 2 X ) (\mathbf{\Gamma},\mathbf{H},\mathbf{P}_2\mathbf{X}) ( Γ , H , P 2 X ) .
Step 3: Bayes' rule. Conditioning the density f f f on the event ϕ ∈ S θ \phi\in S_{\theta} ϕ ∈ S θ gives the truncated density (23), provided ∫ S θ f > 0 \int_{S_{\theta}}f>0 ∫ S θ f > 0 . Values of ( Γ , H , P 2 X ) (\mathbf{\Gamma},\mathbf{H},\mathbf{P}_2\mathbf{X}) ( Γ , H , P 2 X ) with ∫ S θ f = 0 \int_{S_{\theta}}f=0 ∫ S θ f = 0 have probability zero given the selection event, as in the proof of Proposition 3.3(a). Step 4: uniformity. The truncated density (23) has a continuous distribution function, even when S θ S_{\theta} S θ is a union of intervals. Since T 2 = ( r − 2 ) cot 2 ϕ T^2=(r-2)\cot^2\phi T 2 = ( r − 2 ) cot 2 ϕ decreases in ϕ \phi ϕ , the event T 2 ≥ T 2 ( x ) T^2 \ge T^2(x) T 2 ≥ T 2 ( x ) is the event ϕ ≤ θ \phi\le\theta ϕ ≤ θ , so p p o l a r , 1 d p_{\mathrm{polar,1d}} p polar , 1d in (24) is the distribution function of (23) evaluated at the observed angle θ \theta θ , which is a draw from (23) under the null. By the probability integral transform it is uniformly distributed, and averaging over ( Γ , H , P 2 X ) (\Gamma,\mathbf{H},\mathbf{P}_{2X}) ( Γ , H , P 2 X ) given the selection event keeps it uniform. Finally, the change of variables F = r − p − 1 p cot 2 ϕ F=\frac{r-p-1}{p}\cot^2\phi F = p r − p − 1 cot 2 ϕ turns (23) into the F p , r − p − 1 F_{p,r-p-1} F p , r − p − 1 density truncated to S Γ S_{\Gamma} S Γ . □ \square □
Propose-and-check kernels
The random Givens kernel of § 4.1 proposes a random rotation of Q \mathbf{Q} Q and keeps it only if the clustering algorithm returns the tested clusters. Two facts make such kernels reversible with respect to the uniform distribution on S S S ; we state them in the coordinates of this appendix.
Proposition B.3 (Accepting only feasible proposals). Let R ( Q , d Q ′ ) \mathcal{R}(\mathbf{Q},d\mathbf{Q}') R ( Q , d Q ′ ) be a proposal on St ( r − 1 , p ) \operatorname{St}(r-1,p) St ( r − 1 , p ) that is reversible with respect to the uniform distribution. The kernel that moves from Q ∈ S \mathbf{Q}\in S Q ∈ S to a proposal Q ′ \mathbf{Q}' Q ′ if Q ′ ∈ S \mathbf{Q}'\in S Q ′ ∈ S , and stays at Q \mathbf{Q} Q otherwise, is reversible with respect to the uniform distribution on S S S .
Proof. For bounded functions h h h , reversibility of R \mathcal{R} R means
∬ h ( Q , Q ′ ) R ( Q , d Q ′ ) d Q = ∬ h ( Q ′ , Q ) R ( Q , d Q ′ ) d Q . \iint h(\mathbf{Q},\mathbf{Q}')\mathcal{R}(\mathbf{Q},d\mathbf{Q}')\,d\mathbf{Q}
=
\iint h(\mathbf{Q}',\mathbf{Q})\mathcal{R}(\mathbf{Q},d\mathbf{Q}')\,d\mathbf{Q}. ∬ h ( Q , Q ′ ) R ( Q , d Q ′ ) d Q = ∬ h ( Q ′ , Q ) R ( Q , d Q ′ ) d Q .
Applied to h ( Q , Q ′ ) 1 S ( Q ) 1 S ( Q ′ ) h(\mathbf{Q},\mathbf{Q}')1_S(\mathbf{Q})1_S(\mathbf{Q}') h ( Q , Q ′ ) 1 S ( Q ) 1 S ( Q ′ ) , it shows that the accepted moves are symmetric in ( Q , Q ′ ) (\mathbf{Q},\mathbf{Q}') ( Q , Q ′ ) ; the rejected moves leave Q \mathbf{Q} Q in place and are symmetric trivially. Their sum is the kernel. □ \square □
Proposition B.4 (Symmetric random rotations). Let C \mathbf{C} C be a random ( r − 1 ) × ( r − 1 ) (r-1)\times(r-1) ( r − 1 ) × ( r − 1 ) orthogonal matrix, drawn independently of Q \mathbf{Q} Q , such that C − 1 \mathbf{C}^{-1} C − 1 has the same distribution as C \mathbf{C} C . Then the proposal Q ↦ C Q \mathbf{Q}\mapsto\mathbf{C}\mathbf{Q} Q ↦ CQ is reversible with respect to the uniform distribution. The distribution of C \mathbf{C} C may depend on P 2 X \mathbf{P}_{2X} P 2 X , H \mathbf{H} H , and the clustering. Two examples are
the random Givens kernel, C = G i j ( ω ) \mathbf{C}=\mathbf{G}_{ij}(\omega) C = G ij ( ω ) with i < j i<j i < j uniform and ω \omega ω symmetric about zero, for which G i j ( ω ) − 1 = G i j ( − ω ) \mathbf{G}_{ij}(\omega)^{-1}=\mathbf{G}_{ij}(-\omega) G ij ( ω ) − 1 = G ij ( − ω ) ;
the Cayley random walk, C = ( I r − 1 − ϵ 2 W ) − 1 ( I r − 1 + ϵ 2 W ) \mathbf{C}=(\mathbf{I}_{r-1}-\frac{\epsilon}{2}\mathbf{W})^{-1}(\mathbf{I}_{r-1}+\frac{\epsilon}{2}\mathbf{W}) C = ( I r − 1 − 2 ϵ W ) − 1 ( I r − 1 + 2 ϵ W ) with W \mathbf{W} W a random skew-symmetric matrix such that − W -\mathbf{W} − W has the same distribution as W \mathbf{W} W , for which C − 1 \mathbf{C}^{-1} C − 1 is this map at − W -\mathbf{W} − W .
Proof. For a bounded function h h h , the substitution Q ′ = C Q \mathbf{Q}'=\mathbf{C}\mathbf{Q} Q ′ = CQ , under which the uniform distribution is unchanged, and then the equality in distribution of C − 1 \mathbf{C}^{-1} C − 1 and C \mathbf{C} C give
E [ ∫ h ( Q , C Q ) d Q ] = E [ ∫ h ( C − 1 Q ′ , Q ′ ) d Q ′ ] = E [ ∫ h ( C Q ′ , Q ′ ) d Q ′ ] , \mathbb{E}\left[\int h(\mathbf{Q},\mathbf{C}\mathbf{Q})\,d\mathbf{Q}\right]
=
\mathbb{E}\left[\int h(\mathbf{C}^{-1}\mathbf{Q}',\mathbf{Q}')\,d\mathbf{Q}'\right]
=
\mathbb{E}\left[\int h(\mathbf{C}\mathbf{Q}',\mathbf{Q}')\,d\mathbf{Q}'\right], E [ ∫ h ( Q , CQ ) d Q ] = E [ ∫ h ( C − 1 Q ′ , Q ′ ) d Q ′ ] = E [ ∫ h ( C Q ′ , Q ′ ) d Q ′ ] ,
which is the reversibility of the proposal. For the Cayley map, the eigenvalues of a real skew-symmetric matrix are purely imaginary, so I r − 1 − ϵ 2 W \mathbf{I}_{r-1}-\frac{\epsilon}{2}\mathbf{W} I r − 1 − 2 ϵ W is invertible, and because I r − 1 ± ϵ 2 W \mathbf{I}_{r-1}\pm\frac{\epsilon}{2}\mathbf{W} I r − 1 ± 2 ϵ W commute,
C T = ( I r − 1 − ϵ 2 W ) ( I r − 1 + ϵ 2 W ) − 1 = ( I r − 1 + ϵ 2 W ) − 1 ( I r − 1 − ϵ 2 W ) = C − 1 . \mathbf{C}^{\mathsf{T}}=(\mathbf{I}_{r-1}-\tfrac{\epsilon}{2}\mathbf{W})(\mathbf{I}_{r-1}+\tfrac{\epsilon}{2}\mathbf{W})^{-1}=(\mathbf{I}_{r-1}+\tfrac{\epsilon}{2}\mathbf{W})^{-1}(\mathbf{I}_{r-1}-\tfrac{\epsilon}{2}\mathbf{W})=\mathbf{C}^{-1}. C T = ( I r − 1 − 2 ϵ W ) ( I r − 1 + 2 ϵ W ) − 1 = ( I r − 1 + 2 ϵ W ) − 1 ( I r − 1 − 2 ϵ W ) = C − 1 .
□ \square □
Proof of Proposition 4.1. For a fixed step size ϵ \epsilon ϵ , the random Givens kernel accepts only feasible proposals from the proposal of Proposition B.4, so it is reversible by Proposition B.3. A power of a reversible kernel is reversible, and the kernel that draws ϵ \epsilon ϵ from a fixed distribution and then takes L L L steps is an average of reversible kernels with weights free of Q \mathbf{Q} Q , so it is also reversible. □ \square □
Our Cayley random walk draws W = N − N T \mathbf{W}=\mathbf{N}-\mathbf{N}^{\mathsf{T}} W = N − N T with N \mathbf{N} N a matrix of independent standard normal entries, and draws ϵ \epsilon ϵ as the random Givens kernel does. Neither proposition covers a step size tuned on trial moves from Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs (§ 4.2 ).
Proof of the exactness of the Besag–Clifford p p p -value
Proof of Proposition 4.2. Fix P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and the event that the clustering returns C ^ 1 \widehat{\mathbf{C}}_1 C 1 and C ^ 2 \widehat{\mathbf{C}}_2 C 2 . Because K \mathcal{K} K , M M M , and L L L depend on the data only through these, K \mathcal{K} K is a fixed kernel and M M M a fixed integer, and J J J , ξ \xi ξ , and the random inputs of every step are drawn independently of Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs . Write K ( Q , d Q ′ ) \mathcal{K}(\mathbf{Q},d\mathbf{Q}') K ( Q , d Q ′ ) for the distribution of one step of the path from Q \mathbf{Q} Q , and c = ∫ 1 S ( Q ) d Q c=\int1_S(\mathbf{Q})d\mathbf{Q} c = ∫ 1 S ( Q ) d Q . By Proposition 3.3 , Q o b s \mathbf{Q}_{\mathrm{obs}} Q obs has distribution c − 1 1 S ( Q ) d Q c^{-1}1_S(\mathbf{Q})d\mathbf{Q} c − 1 1 S ( Q ) d Q , and reversibility means
1 S ( Q ) d Q K ( Q , d Q ′ ) = 1 S ( Q ′ ) d Q ′ K ( Q ′ , d Q ) . 1_S(\mathbf{Q})d\mathbf{Q}\,\mathcal{K}(\mathbf{Q},d\mathbf{Q}')=1_S(\mathbf{Q}')d\mathbf{Q}'\,\mathcal{K}(\mathbf{Q}',d\mathbf{Q}). 1 S ( Q ) d Q K ( Q , d Q ′ ) = 1 S ( Q ′ ) d Q ′ K ( Q ′ , d Q ) .
A Givens step has no density, so these are statements about distributions, not densities.
The path. Applying reversibility to ( Q k , Q k − 1 ) (\mathbf{Q}_k,\mathbf{Q}_{k-1}) ( Q k , Q k − 1 ) , ( Q k − 1 , Q k − 2 ) (\mathbf{Q}_{k-1},\mathbf{Q}_{k-2}) ( Q k − 1 , Q k − 2 ) , and so on, gives for every k k k
1 S ( Q k ) d Q k ∏ j = 1 k K ( Q j , d Q j − 1 ) = 1 S ( Q 0 ) d Q 0 ∏ j = 0 k − 1 K ( Q j , d Q j + 1 ) . (53) 1_S(\mathbf{Q}_k)d\mathbf{Q}_k\prod_{j=1}^{k}\mathcal{K}(\mathbf{Q}_j,d\mathbf{Q}_{j-1})=1_S(\mathbf{Q}_0)d\mathbf{Q}_0\prod_{j=0}^{k-1}\mathcal{K}(\mathbf{Q}_j,d\mathbf{Q}_{j+1}). \tag*{(53)} 1 S ( Q k ) d Q k j = 1 ∏ k K ( Q j , d Q j − 1 ) = 1 S ( Q 0 ) d Q 0 j = 0 ∏ k − 1 K ( Q j , d Q j + 1 ) . (53)
Given J = k J=k J = k , Algorithm 1 starts at Q k = Q o b s \mathbf{Q}_k=\mathbf{Q}_{\mathrm{obs}} Q k = Q obs and runs the chain backward to Q 0 \mathbf{Q}_0 Q 0 and forward to Q M \mathbf{Q}_M Q M , so the path ( Q 0 , … , Q M ) (\mathbf{Q}_0,\ldots,\mathbf{Q}_M) ( Q 0 , … , Q M ) has distribution
c − 1 1 S ( Q k ) d Q k { ∏ j = 1 k K ( Q j , d Q j − 1 ) } { ∏ j = k M − 1 K ( Q j , d Q j + 1 ) } = c − 1 1 S ( Q 0 ) d Q 0 ∏ j = 0 M − 1 K ( Q j , d Q j + 1 ) . c^{-1}1_S(\mathbf{Q}_k)d\mathbf{Q}_k\left\{\prod_{j=1}^{k}\mathcal{K}(\mathbf{Q}_j,d\mathbf{Q}_{j-1})\right\}\left\{\prod_{j=k}^{M-1}\mathcal{K}(\mathbf{Q}_j,d\mathbf{Q}_{j+1})\right\}=c^{-1}1_S(\mathbf{Q}_0)d\mathbf{Q}_0\prod_{j=0}^{M-1}\mathcal{K}(\mathbf{Q}_j,d\mathbf{Q}_{j+1}). c − 1 1 S ( Q k ) d Q k { j = 1 ∏ k K ( Q j , d Q j − 1 ) } ⎩ ⎨ ⎧ j = k ∏ M − 1 K ( Q j , d Q j + 1 ) ⎭ ⎬ ⎫ = c − 1 1 S ( Q 0 ) d Q 0 j = 0 ∏ M − 1 K ( Q j , d Q j + 1 ) .
by (48). The right side does not depend on k k k : it is the distribution of a chain started from the uniform distribution on S S S . So J J J , which is uniform on { 0 , … , M } \{0,\ldots,M\} { 0 , … , M } , is independent of the path. The points of the path need not be exchangeable; only the position of the observed point is uniform ([31 Section 3.2] ).
The rank. Fix a path, and let its distinct values of u u u , in decreasing order, occur N 1 , … , N D N_1,\ldots,N_D N 1 , … , N D times, with N ‾ d = ∑ d ′ < d N d ′ \overline{N}_d=\sum_{d'<d}N_{d'} N d = ∑ d ′ < d N d ′ . Given the path, the observed point falls in the d d d th group with probability N d / ( M + 1 ) N_d/(M+1) N d / ( M + 1 ) , and then p ^ p o l a r = ( N ‾ d + N d ξ ) / ( M + 1 ) \widehat{p}_{\mathrm{polar}}=(\overline{N}_d+N_d\xi)/(M+1) p polar = ( N d + N d ξ ) / ( M + 1 ) is uniform on the interval m a t h i t I d = ( N ‾ d / ( M + 1 ) , ( N ‾ d + N d ) / ( M + 1 ) ) mathit{I}_d=(\overline{N}_d/(M+1),(\overline{N}_d+N_d)/(M+1)) ma t hi t I d = ( N d / ( M + 1 ) , ( N d + N d ) / ( M + 1 )) . So, given the path, p ^ p o l a r \widehat{p}_{\mathrm{polar}} p polar has density
∑ d = 1 D N d M + 1 ⋅ M + 1 N d 1 { x ∈ I d } = ∑ d = 1 D 1 { x ∈ I d } = 1 , 0 < x < 1 , \sum_{d=1}^{D}\frac{N_d}{M+1}\cdot\frac{M+1}{N_d}1\{x\in I_d\}=\sum_{d=1}^{D}1\{x\in I_d\}=1,\qquad0<x<1, d = 1 ∑ D M + 1 N d ⋅ N d M + 1 1 { x ∈ I d } = d = 1 ∑ D 1 { x ∈ I d } = 1 , 0 < x < 1 ,
because the intervals I 1 , … , I D I_1,\ldots,I_D I 1 , … , I D cover ( 0 , 1 ) (0,1) ( 0 , 1 ) without overlap. So p ^ p o l a r \widehat{p}_{\mathrm{polar}} p polar is uniform given the path, even when all values are tied. Averaging over the path completes the proof.
The kernels. The random Givens kernel is reversible by Proposition 4.1 and the hit-and-run kernel by Proposition B.1; in both cases L L L steps are reversible too. □
Additional material on the Monte Carlo test
This appendix collects material on the Monte Carlo test of § 4.1 and § 4.2 that the main text only mentions. 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 p 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.
Algorithm C.1 The one-dimensional selective test $\hat{p}_{\mathrm{polar},1d}$ for any clustering algorithm
Require: data $\mathbf{x} \in \mathbb{R}^{n \times p}$, clustering algorithm $\mathcal{C}$, tested clusters $\widehat{C}_1,\widehat{C}_2 \in \mathcal{C}(\mathbf{x})$, path length $M$, number of steps $L$
1: Compute $\mathbf{P}_0$, $\mathbf{P}_1$, $\mathbf{P}_2$, $\mathbf{H}$, and $\mathbf{Q}_{\mathrm{obs}}$ as in Algorithm 1
2: $\boldsymbol{\gamma} \leftarrow \operatorname{dir}(\mathbf{Q}_{\mathrm{obs}}^{\mathsf{T}}\boldsymbol{\nu})$, $\mathbf{q} \leftarrow \mathbf{Q}_{\mathrm{obs}}\boldsymbol{\gamma}$, and $\theta \leftarrow \arccos \lVert \mathbf{P}_0\mathbf{q}\rVert_2$ ▷ Section 3.4
3: Draw $J$ uniformly from $\{0,1,\ldots,M\}$ and set $\phi_J \leftarrow \theta$
4: for $j=J,J+1,\ldots,M-1$ do
5: $\phi_{j+1} \leftarrow \operatorname{RandomStep}(\phi_j)$ ▷ forward
6: end for
7: for $j=J,J-1,\ldots,1$ do
8: $\phi_{j-1} \leftarrow \operatorname{RandomStep}(\phi_j)$ ▷ backward
9: end for
10: Draw $\xi \sim \operatorname{Uniform}(0,1)$
Ensure: $\hat{p}_{\mathrm{polar},1d}=\dfrac{1}{M+1}\left(\sum_{j=0}^{M}\mathbf{1}\{\phi_j<\phi_J\}+\xi\sum_{j=0}^{M}\mathbf{1}\{\phi_j=\phi_J\}\right)$
11: function $\operatorname{RandomStep}(\phi)$ ▷ target density (23)
12: Draw $\log\epsilon$ uniformly on $[\log 10^{-3},0]$
13: for $\ell=1,\ldots,L$ do
14: Draw $\omega\sim\mathcal{N}(0,(\pi\epsilon)^2)$ and $U\sim\operatorname{Uniform}(0,1)$, and set $\phi'\leftarrow\phi+\omega$
15: if $\phi'\in(0,\pi/2)$ and $U\le f(\phi')/f(\phi)$ then ▷ $f(\phi)\propto\cos^{p-1}\phi\sin^{r-p-2}\phi$
16: if $\widehat{C}_1,\widehat{C}_2\in\mathcal{C}(\mathbf{P}_2\mathbf{x}+\mathbf{Q}_{\Gamma}(\phi')\mathbf{H})$ then ▷ path (17)
17: $\phi\leftarrow\phi'$
18: end if
19: end if
20: end for
21: return $\phi$
22: end function
The algorithm for the one-dimensional test
Algorithm C.1 computes p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d in (24) for any clustering algorithm, as described in Section 4.3. 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.
A naive Markov chain estimator
This subsection records the naive Markov chain estimator mentioned in Section 4.1 and why it fails. Its target distribution, the uniform distribution on S Q S_{\mathcal{Q}} 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 test of Section 4.2 needs none.
The naive estimator is built from B B B post-burn-in draws Q ( 1 ) , … , Q ( B ) \mathbf{Q}^{(1)},\ldots,\mathbf{Q}^{(B)} Q ( 1 ) , … , Q ( B ) with the uniform distribution on S Q S_{\mathcal{Q}} S Q as stationary distribution,
p ^ B = 1 + ∑ b = 1 B 1 { u ( Q ( b ) ) ≥ u ( Q o b s ) } B + 1 . \widehat{p}_B=\frac{1+\sum_{b=1}^{B}\mathbf{1}\{u(\mathbf{Q}^{(b)})\ge u(\mathbf{Q}_{\mathrm{obs}})\}}{B+1}. p B = B + 1 1 + ∑ b = 1 B 1 { u ( Q ( b ) ) ≥ u ( Q obs )} .
If the draws were close to independent conditional samples, this would approximate the selective tail probability. In our problem they are not. The selection event leaves a thin feasible set around the observed configuration, and a generic random walk that accepts only feasible moves travels through it slowly. The dimension of the Stiefel manifold is
dim St ( r − 1 , p ) = ( r − 1 ) p − p ( p + 1 ) 2 , \dim\operatorname{St}(r-1,p) = (r-1)p - \frac{p(p+1)}{2}, dim St ( r − 1 , p ) = ( r − 1 ) p − 2 p ( p + 1 ) ,
so larger tested pairs and larger feature dimension both make the exploration harder. On the 24 null cells with n ≤ 200 n \le200 n ≤ 200 , p ≤ 20 p \le20 p ≤ 20 , and isotropic, A R ( 1 ) AR(1) A R ( 1 ) , or compound-symmetric Σ \boldsymbol{\Sigma} Σ (600 replicates each), the naive estimator with a Cayley random-walk kernel, 1,000 burn-in steps, and 2,500 post-burn-in draws thinned by 5 has median selective Type I error 0.077 and reaches 0.185 at n = 200 n = 200 n = 200 , p = 10 p = 10 p = 10 ; at n = 200 n = 200 n = 200 and p ∈ { 50 , 100 } p \in\{50, 100\} p ∈ { 50 , 100 } it lies between 0.12 and 0.20, while the Besag–Clifford test is calibrated in the same cells. The bottleneck is not rejection of proposals; step-size adaptation keeps the acceptance rate moderate:
The naive estimator is valid only when the chain has mixed, which the Type I errors above show it has not. The Besag–Clifford p p p -value of § 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.
Path length, number of steps, and step size
Figure C.1 illustrates § 4.2 . On null data the Type I error of p ^ p o l a r \hat{p}_{\mathrm{polar}} p ^ polar stays at the nominal level from M = 25 M = 25 M = 25 to M = 25,600 M = 25{,}600 M = 25 , 600 (between 0.047 and 0.056 over 1,021 replicates, each evaluated at every M M M , with L = 2 L = 2 L = 2 steps between points), while on data with a signal the power grows with M M M and levels off (473 to 493 recovered replicates per separation). The identity kernel is an extreme case: it is reversible, and it returns p ^ p o l a r = ξ \hat{p}_{\mathrm{polar}} = \xi p ^ polar = ξ , which is exactly uniform and has no power.
The requirement that the kernel, M M M , and L L L depend on the data only through P 2 X \mathbf{P}_2\mathbf{X} P 2 X , H \mathbf{H} H , and the clustering cannot be dropped. Take the two-point space { 0 , 1 } \{0,1\} { 0 , 1 } with the uniform distribution, u ( x ) = x u(x) = x u ( x ) = x , and the kernel that always moves to the other point, which is reversible. Taking M = 1 M = 1 M = 1 and L = 1 L = 1 L = 1 when Q o b s = 1 Q_{\mathrm{obs}} = 1 Q obs = 1 but L = 2 L = 2 L = 2 when Q o b s = 0 Q_{\mathrm{obs}} = 0 Q obs = 0 gives P ( p ^ p o l a r ≤ 1 / 2 ) = 3 / 4 \mathbb{P}(\hat{p}_{\mathrm{polar}} \le1/2) = 3/4 P ( p ^ polar ≤ 1/2 ) = 3/4 , although each fixed K L K^L K L is reversible. Tuning a step size on trial moves from Q o b s Q_{\mathrm{obs}} Q obs is a choice of this kind. A step size, or a number of steps, drawn afresh for each block of steps from a fixed distribution is allowed, because the kernel of one block is then a mixture of reversible kernels with weights that do not depend on the current point of the path.
A pilot comparison of kernels
We compared four kernels in the construction of § 4.2 on the design of Figure 1 (n = 100 n = 100 n = 100 , p = 2 p = 2 p = 2 , compound-symmetric Σ \boldsymbol{\Sigma} Σ with correlation 0.6, k k k -means with K = 3 K = 3 K = 3 ), with M = 1,000 M = 1{,}000 M = 1 , 000 and L = 2 L = 2 L = 2 :
the random Givens kernel of Section 4.1;
the Cayley random walk of Appendix B.5;
a Givens step that draws the angle by a slice sampler with shrinkage [47 ] , which moves at every step but runs the clustering several times per step;
the hit-and-run step on the exact arcs of Section 4.4, which conditions on the Lloyd trajectory.
Figure C.1. Path length changes power but not the Type I error (n = 45 n = 45 n = 45 , p = 10 p = 10 p = 10 , K = 3 K = 3 K = 3 ). Left: selective Type I error against the path length M M M on null data, each replicate evaluated at every M M M . Right: conditional power against M M M for five separations δ \delta δ (one curve each).
On 588 null pairs, the Type I error at level 0.05 was 0.029 for the random Givens kernel, 0.070 for the Cayley random walk, 0.049 for the slice version, and 0.067 for the exact arcs (297 pairs). All four kernels are exact by Proposition 4.2 , and on a toy problem where Q o b s Q_{\mathrm{obs}} 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. With separation δ = 4 \delta= 4 δ = 4 (111 pairs), the power was 0.973 for the random Givens kernel (7 seconds per p p p -value), 0.955 for the Cayley random walk (10 seconds), and 1.000 for the slice version (38 seconds, about 10,000 runs of the clustering against 2,000 for the other two).
A larger run compared the random Givens kernel and the Cayley random walk with M = 5,000 M = 5{,}000 M = 5 , 000 and L = 2 L = 2 L = 2 in two settings with compound-symmetric Σ \Sigma Σ : the design above, and n = 200 n = 200 n = 200 with p = 50 p = 50 p = 50 , each with about 2,100 null pairs. Both kernels control the selective Type I error (Figure C.2(a)), and both reject H 0 H_0 H 0 for 98% to 100% of the pairs of true clusters at the separations we ran. The random Givens kernel is 20% to 30% faster (Figure C.2(b)) and moves at about 65% of its steps, against 3% to 11% for the Cayley random walk (Figure C.2(c)).
Additional simulation results
This appendix reports every cell of the k k k -means simulation study of § 5 , which Figure 4 summarizes. It also gives the results for Leiden community detection, the rows of § 5.3 that are not Gaussian, and the computing time of each test. The figures of this appendix also show a reference that is not available in practice, p p o l a r ( Σ ) p_{\mathrm{polar}}(\Sigma) p polar ( Σ ) , which replaces Hotelling’s T 2 T^2 T 2 in p p o l a r p_{\mathrm{polar}} p polar by ( x ˉ C ^ 1 − x ˉ C ^ 2 ) ⊤ Σ − 1 ( x ˉ C ^ 1 − x ˉ C ^ 2 ) (\bar{x}_{\widehat{C}_1} - \bar{x}_{\widehat{C}_2})^\top\Sigma^{-1}(\bar{x}_{\widehat{C}_1} - \bar{x}_{\widehat{C}_2}) ( x ˉ C 1 − x ˉ C 2 ) ⊤ Σ − 1 ( x ˉ C 1 − x ˉ C 2 ) and so requires the true Σ \Sigma Σ . Its conditional power is close to that of p p o l a r p_{\mathrm{polar}} p polar , except when p p p is close to the number of tested rows r r r , where estimating Σ \Sigma Σ costs power.
Selective Type I error of k k k -means. Table D.1 gives the selective Type I error at α = 0.05 \alpha= 0.05 α = 0.05 as the median and the maximum over the cells ( n , p ) (n,p) ( n , p ) , by covariance. Figure D.1 summarizes the cells for every test, and Figure D.2 shows the tests that we propose on a magnified scale. With 600 data sets per cell, the 95% Monte Carlo interval for a test with selective Type I error 0.05 is [0.033, 0.067]. Two comparators appear only here. The unknown-scale test p Y B p_{\mathrm{YB}} p YB of Yun and Barber (2023) divides by the within-cluster sum of squares of the two tested clusters, so it needs no estimate of σ \sigma σ ; it also assumes Σ = σ 2 I p \mathbf{\Sigma} = \sigma^{2}\mathbf{I}_{p} Σ = σ 2 I p and, like p C W ( σ ^ M E D I 2 ) p_{\mathrm{CW}}(\widehat{\sigma}^{2}_{\mathrm{MEDI}}) p CW ( σ MEDI 2 ) , holds the level only under isotropic noise. We computed it, with KmeansInference, on the same null data sets as the other tests. Data thinning (Neufeld et al., [49 ] ), p D T ( Σ ^ s a m p l e ) p_{\mathrm{DT}}(\widehat{\mathbf{\Sigma}}_{\mathrm{sample}}) p DT ( Σ sample ) , splits X \mathbf{X} X into two parts using the sample covariance of X \mathbf{X} X about its overall mean, clusters one part, and applies the classical Hotelling test to the other. Its two parts are independent only when the true Σ \mathbf{\Sigma} Σ is used, but with the sample covariance it is conservative in all of our cells.
Figure C.2. The random Givens kernel and the Cayley random walk with M = 5,000 M = 5{,}000 M = 5 , 000 and L = 2 L = 2 L = 2 , on null data with compound-symmetric Σ \mathbf{\Sigma} Σ . (a) Quantile-quantile plots of the p p p -values against the Uniform( 0 , 1 ) (0,1) ( 0 , 1 ) distribution. (b) Seconds of computing time per p p p -value. (c) The fraction of steps at which the chain moves.
Conditional power of k k k -means. Figure D.3 repeats Figure 4 (b) at n = 30 n = 30 n = 30 and 50 and Figure D.4 at n = 100 n = 100 n = 100 and 200. Figure D.5 shows the other covariances at n = 30 n = 30 n = 30 , for the tests that control the selective Type I error under them. Conditional power is shown where at least 50 data sets returned two true clusters.
Leiden community detection. Leiden community detection (Traag et al., [58 ] ) on a graph that joins each row to its 15 nearest neighbors has no closed-form selection event, so no existing selective test applies; we report p p o l a r p_{\mathrm{polar}} p polar . We used the design of Figure 1 : n = 100 n = 100 n = 100 , compound-symmetric Σ \mathbf{\Sigma} Σ with correlation 0.6, and two true groups with means ± ( δ / 2 ) u \pm(\delta/2)\mathbf{u} ± ( δ /2 ) u , where u = ( 1 , − 1 , 0 , … , 0 ) T / 2 \mathbf{u} = (1,-1,0,\ldots,0)^{\mathsf{T}}/\sqrt{2} u = ( 1 , − 1 , 0 , … , 0 ) T / 2 , with p ∈ { 2 , 5 } p \in\{2,5\} p ∈ { 2 , 5 } and δ ∈ { 0 , 2 , 4 , 6 } \delta\in\{0,2,4,6\} δ ∈ { 0 , 2 , 4 , 6 } . The resolution of the Leiden algorithm was fixed for each $p before the study so that it returns about three clusters, and every pair of clusters with at least p + 2 p+2 p + 2 members was tested. Figure D.6(a) shows that the null p p p -values of p p o l a r p_{\mathrm{polar}} p polar are uniform, with selective Type I error 0.043 at p = 2 p = 2 p = 2 and 0.051 at p = 5 p = 5 p = 5 , and Figure D.6(b) shows that its conditional power is 0.99 at δ = 4 \delta= 4 δ = 4 for both dimensions.
Table D.1. Selective Type I error at α = 0.05 \alpha= 0.05 α = 0.05 after k k k -means, by covariance: median [maximum] over the cells ( n , p ) (n,p) ( n , p ) of § 5.1 .
Rows that are not Gaussian. Figure D.7 reports the study of § 5.3 . All data sets have n = 200 n = 200 n = 200 , compound-symmetric Σ \boldsymbol{\Sigma} Σ with correlation 0.5, and no signal. The t t t rows are multivariate t t t with 5 or 10 degrees of freedom. The censored rows are Gaussian rows shifted so that a fraction s ∈ { 0.05 , 0.15 } s \in\{0.05, 0.15\} s ∈ { 0.05 , 0.15 } of each coordinate falls below zero and then censored at zero. For principal components, Gaussian rows with p ∈ { 50 , 200 } p \in\{50, 200\} p ∈ { 50 , 200 } are reduced to their first q ∈ { 5 , 10 } q \in\{5, 10\} q ∈ { 5 , 10 } principal components before k k k -means, and the tests use the component scores.
Computing time. Figure D.8 gives the median time for one p p p -value after k k k -means at n = 200 n = 200 n = 200 . We reran the simulation code of this section on six data sets for each value of p p p , three under the global null and three from the power study, with M = 5,000 M = 5{,}000 M = 5 , 000 and L = 2 L = 2 L = 2 . Each p p p -value was computed on one core of an Apple M4 Max processor, with macOS 15.4, R 4.5.2, and the Apple Accelerate linear algebra library restricted to one thread. One value of p p o l a r p_{\mathrm{polar}} p polar takes 2 to 6 seconds, and one value of p p o l a r , 1 d p_{\mathrm{polar},1d} p polar , 1 d takes 1 to 2.5 seconds. Each of the M L = 10,000 ML = 10{,}000 M L = 10 , 000 steps of the path reruns k k k -means once, so the time grows with the cost of one run of the clustering algorithm. The closed-form p p o l a r , 1 d t r a j p_{\mathrm{polar},1d}^{\mathrm{traj}} p polar , 1 d traj and the tests of Chen and Witten [14 ] take about 0.1 seconds.
Figure D.1. Selective Type I error at α = 0.05 \alpha= 0.05 α = 0.05 after k k k -means, by covariance structure, on a square-root scale. Each box summarizes one test over the cells ( n , p ) (n, p) ( 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 \alpha= 0.05 α = 0.05 after k k k -means for the tests that we propose, stratified by n n n (rows) and Σ \boldsymbol{\Sigma} Σ (columns). Each box summarizes one test over the values of p p p with p ≤ n / 2 p \le n/2 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 \alpha= 0.05 α = 0.05 after k k k -means with Σ = I p \boldsymbol{\Sigma} = I_p Σ = I p , stratified by n n n (rows) and p p p (columns), with 95% Wilson intervals.
Figure D.4. As Figure D.3, at n = 100 n = 100 n = 100 and 200.
Figure D.5. As Figure D.3, at n = 30 n = 30 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 p p -values with one true group (δ = 0 \delta= 0 δ = 0 ), stratified by p p p . (b) The conditional power (29) of p p o l a r p_{\mathrm{polar}} p polar at α = 0.05 \alpha= 0.05 α = 0.05 against δ \delta δ , with 95% Wilson intervals.
Figure D.7. Selective Type I error at α = 0.05 \alpha= 0.05 α = 0.05 with rows that are not Gaussian (§ 5.3 ), after k k k -means (left) and average-linkage hierarchical clustering (right), on a square-root scale. Each box summarizes one test over the values of p p p (and of q q q for principal components), which are drawn as points. The gray band is as in Figure D.1. There is no reference p p o l a r ( Σ ) p_{\mathrm{polar}}(\Sigma) p polar ( Σ ) for principal components.
Figure D.8. Median seconds for one p p p -value after k k k -means at n = 200 n = 200 n = 200 , on one core, by p p p . The vertical axis is on a log scale.