Why Permuting One Variable Can Test Independence
A paired sample records \(n\) observations \((X_i,Y_i)\), where each pair links a value of \(X\) to a value of \(Y\). To test whether the variables are independent, one can keep the observed \(X\)'s fixed and rearrange the \(Y\)'s among them. Under independence, the original matching has no special status: the data distribution is unchanged by any such rearrangement. This symmetry, rather than a large-sample approximation, is the reason the resulting test can be valid in finite samples.
The argument requires independent and identically distributed pairs and the null hypothesis \(X\perp Y\). It does not require continuous variables, normality, or a particular choice of dependence statistic. Ties are allowed, although they can make the test conservative at a chosen significance level.
The Finite-Sample Validity Argument
Under the null \(X\perp Y\), the vector \((X_1,\ldots,X_n)\) is independent of \((Y_1,\ldots,Y_n)\). The \(Y_i\)'s are iid, so their joint distribution is invariant under index permutations. Consequently, the distribution of the full data is unchanged if the \(Y\) indices are permuted while the \(X\)'s remain fixed. The next result turns this invariance into a p-value guarantee.
Proof. Fix a possible data set and form its orbit by applying all \(n!\) permutations to its \(Y\)-indices. The orbit is the set of distinct permuted data sets. Under the null, the full data distribution is invariant under every such permutation. Conditional on an orbit, the observed data point is therefore uniform over the distinct points in that orbit.
To account for repeated points caused by tied \(Y\)-values, consider instead the list of all \(n!\) permutations, with repetitions retained. Every distinct orbit point occurs the same number of times: if one permutation produces that point, exactly the permutations in a coset of its stabilizer produce it. Thus, choosing a uniformly random permutation from the list gives the same relative frequencies as choosing a uniformly random point from the orbit.
Now sort the \(n!\) statistic values from smallest to largest, retaining ties. For any value in this list, its upper-tail fraction is the number of list entries greater than or equal to it, divided by \(n!\). Among list entries whose upper-tail fraction is at most \(\alpha\), there can be no more than \(\lfloor \alpha n!\rfloor\) entries: those entries must lie among the last \(\lfloor \alpha n!\rfloor\) positions, and ties can only increase their upper-tail fractions. Hence, conditional on the orbit, the probability that the observed entry has p-value at most \(\alpha\) is at most \(\lfloor \alpha n!\rfloor/n!\leq\alpha\). Averaging over orbits proves the stated bound. \(\square\)
The result gives finite-sample control: rejecting when \(p\leq\alpha\) has null rejection probability no greater than \(\alpha\). It need not equal \(\alpha\). The finite set of permutations and tied statistic values often make the p-value discrete. In particular, the smallest possible full-permutation p-value is at least \(1/n!\), because the identity permutation is always counted in its own upper tail.
Applying the Argument to Distance Covariance
For observed vectors \(X_1,\ldots,X_n\) and \(Y_1,\ldots,Y_n\), let \(D^X_{ij}\) and \(D^Y_{ij}\) be their pairwise Euclidean distances. Define the doubly centered distance matrices $$ A=HD^XH,\qquad B=HD^YH,\qquad H=I_n-\frac{1}{n}\mathbf{1}\mathbf{1}^{\mathsf T}. $$ Here \(\mathbf{1}\) is the \(n\)-vector of ones. A common nonnegative dependence statistic is the biased sample squared distance covariance $$ T_{\mathrm{dCov}}=\frac{1}{n^2}\sum_{i=1}^n\sum_{j=1}^n A_{ij}B_{ij}. $$