
Technical details and practical advice
Source:vignettes/articles/technical_details.Rmd
technical_details.RmdWhat the tests condition on
Write and for the two tested clusters and . The tests assume that the rows of the data are independent Gaussian vectors with a common covariance matrix , and they test the null hypothesis that all observations in the two clusters share one mean.
The deviations of the tested observations from their common mean form an matrix. Its polar decomposition writes it as , where is the square root of times their sample covariance matrix and has orthonormal columns. Under the null hypothesis, is uniformly distributed and independent of and of the rest of the data, whatever is. Hotellingโs is a function of alone. So, after fixing and the rest of the data, the only thing left random is , whose distribution is known, and the selective -value is the fraction of the matrices that reproduce the clusters and give a larger than the observed one.
The three p-values
The package computes three selective -values. All three are exact under the null hypothesis, whatever is; they differ in what they condition on, and the more they condition on, the less power they have.
| -value | Function | Clustering | Conditions on | Power |
|---|---|---|---|---|
selective_hotelling_test(),
selective_hotelling_bc()
|
any | the clusters returned | highest | |
selective_truncated_F(method = "bc") |
any | also all but one direction of | lower | |
selective_truncated_F(method = "exact") |
k-means | also the whole k-means trajectory | lowest |
Use by default. The one-dimensional samples a single angle instead of the whole matrix , so it is faster, and has a closed form and needs no sampling at all (the one-dimensional tutorial).
How the main p-value is computed
The set of matrices
that reproduce the clusters has no closed form. The package walks
through it with a Markov chain: each step rotates two rows of
by a random angle, reruns the clustering, and keeps the rotation only if
the tested clusters are returned again. The observed
is placed at a random position on a path of M + 1 points,
and the
-value
is its rank among them (Besag and Clifford, 1989). This
-value
is exact for any path length M and any
number of steps L between points: a short path gives a
valid test with less power.
Choosing M and L
- The defaults,
M = 5000andL = 2, are what we use in the paper. - Smaller
Mkeeps the test valid but lowers power.M = 1000is enough for exploration. - The clustering is rerun
Ltimes at each of theMsteps, so the computing time is roughlyM * Lruns of the clustering algorithm. -
MandLmust be chosen before looking at the data; they must not be tuned on the observed clusters.
Requirements and limitations
- Gaussian rows. The guarantee assumes Gaussian data. Heavy tails (for example, distributions) can inflate the Type I error, especially after average-linkage hierarchical clustering.
- Enough observations. The test needs , as Hotellingโs does. For high-dimensional data, reduce the dimension first, for example with principal components computed from data that are not tested.
-
A deterministic clustering function.
cl_funmust return the same labels each time it is run on the same data (the tutorial for other clustering algorithms). - The pair to test. The pair should be fixed in advance, or every pair should be tested. Choosing the pair by looking at the data, for example the two clusters that look most different, needs further adjustment.
- Large clusters. When the two clusters contain hundreds of observations, each step rotates only two of the coordinates, and a path of fixed length moves less; the test stays valid but can lose power.
References
Besag, J. and Clifford, P. (1989). Generalized Monte Carlo significance tests. Biometrika, 76(4), 633โ642.
Chen, Y. T. and Witten, D. M. (2023). Selective inference for -means clustering. Journal of Machine Learning Research, 24, 1โ41.
Gao, L. L., Bien, J., and Witten, D. (2024). Selective inference for hierarchical clustering. Journal of the American Statistical Association, 119(545), 332โ342.
Yun, Y.-J. and Barber, R. F. (2023). Selective inference for clustering with unknown variance. Electronic Journal of Statistics, 17(2), 1923โ1946.