Skip to content

CAssociation · Guide test 088

Cross distance covariance test

Uses sample splitting to obtain an asymptotically normal distance based independence test.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Test for any dependence (ξ, Hoeffding, distance correlation, HSIC), choose Dependence measure = Cross distance covariance (no permutations).

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Cross distance covariance test

30

Shape of the link

0.80
0.050

Your data

Simulated with a known link

If H₀ were true

z = 0.63
  1. The reference: how z varies across samples when H₀ is true (studentized cross U-statistic: normal by construction).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .265).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

z=n Uˉs^,k(a,b)=12(∣a∣+∣b∣−∣a−b∣)z=\sqrt{n}\,\dfrac{\bar U}{\hat s},\quad k(a,b)=\tfrac12\left(|a|+|b|-|a-b|\right)

With your numbers

Uˉ=0.0030,z=0.63\bar U = 0.0030,\qquad z = 0.63
k(a,b)k(a,b)
the distance kernel behind distance covariance
s^\hat s
standard deviation of the cross scores

The verdict

z = 0.63, p = .265

p > α = .050: compatible with H₀

Cross HSIC with the distance kernel: distance covariance's sensitivity, a normal null, and no permutations.

Statistic
0.627
p-value
0.2653
Cross distance covariance test on 30 (x, y) pairs: z = 0.63, p = .265. The p-value is above α = .050, so the data are compatible with H0.

Cross distance covariance test on 30 (x, y) pairs: z = 0.63, p = .265. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: X and Y are independent.

Assumptions

Independent identically distributed paired observations, split into two independent halves; the source’s kernel moment and nondegeneracy conditions for normal calibration.

Formula

hij=12(ϕ(Xi)−ϕ(Xj))⊗(ψ(Yi)−ψ(Yj))fs=∑i≠j∈shijn(n−1)U=⟨f1,f2⟩Z=n Usn\begin{gathered}h_{ij}=\tfrac12(\phi(X_i)-\phi(X_j))\otimes(\psi(Y_i)-\psi(Y_j))\\[5pt] f_s=\frac{\sum_{i\ne j\in s}h_{ij}}{n(n-1)}\\[5pt] U=\langle f_1,f_2\rangle\\[5pt] Z=\frac{\sqrt n\,U}{s_n}\end{gathered}

Parameters and notation

Each half has n observations. Set gi=(n−1)⁻¹Σj≠i〈hij,f2〉 for i in half 1, and sn²=4(n−1)/(n−2)² Σi(gi−U)². φ,ψ are kernel feature maps. For a negative type distance d, use k(x,x′)=[d(x,x0)+d(x′,x0)−d(x,x′)]/2 and similarly for Y; x0 is a fixed anchor. This connects distance covariance to the kernel formulation.

Structure of the method

Convert a negative-type distance into an anchored positive-definite kernel, then apply the split cross-covariance and jackknife-studentized construction used by cross-HSIC. The displayed statistic is therefore a distance-induced-kernel independence test with an asymptotic normal calibration rather than ordinary permuted distance covariance.

Estimated and nuisance parameters

Estimate two half-sample operators, the cross statistic, and its jackknife variance. The metric, anchor, and split are specified computational choices. Anchoring is a representation device; consistent centering removes the arbitrary origin in the associated distance-based dependence construction.

Settings and design choices

Prespecify distance exponent, feature scales, equal-half split, and significance level. Verify the required negative-type property and moment assumptions. Keep the half-size convention consistent between statistic and variance; a casual substitution of the full sample size changes standardization.

Fitting and adaptation

Rebuild distance-induced kernels and variance for a new sample. If preprocessing is learned, ensure its selection is compatible with the independence of the two halves and the cited theory. Ordinary refitting replaces fine-tuning; serial or clustered samples need a separately justified extension.

Sensitivity and robustness

Small halves, concentrated distances, extreme feature scales, and near-zero variance estimates can make the normal approximation unreliable. Power depends on metric and dimension. Repeatedly trying splits or distances and reporting the smallest unadjusted p-value invalidates the nominal test even though each formula is computed correctly.

How to use and calibrate

Reject for Z>z1−α asymptotically. The split and jackknife studentization avoid repeated permutations.

Example application

Test distance-induced kernel cross covariance dependence when permutation computation is expensive.

Interpretation and pitfalls

Watch out

The normal result is asymptotic, not a distribution free small sample guarantee. Repeating splits and choosing the best p value invalidates the test.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

One prespecified split into equal halves, exact cross-U-statistic projection and jackknife studentization from the cited paper. Upper standard-normal tail is asymptotic; do not try many splits and select the smallest p-value.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
n=30;x=rng.normal(size=2*n);y=x*x+rng.normal(size=2*n)
def kernel(a,b):return (abs(a[:,None])+abs(b[None,:])-abs(a[:,None]-b[None,:]))/2
K=kernel(x[:n],x[n:]);L=kernel(y[:n],y[n:]);H=np.eye(n)-np.ones((n,n))/n
S=K@H@L.T;d=np.diag(S);Q=(d[:,None]+d[None,:]-S-S.T)/(2*(n-1))
g=Q.sum(1)/(n-1);U=g.mean();sn2=4*(n-1)/(n-2)**2*np.sum((g-U)**2)
Z=np.sqrt(n)*U/np.sqrt(sn2);print(Z,stats.norm.sf(Z))
Output
0.9671357401759122 0.16673809041648857
R

Validated — Executed successfully in the validation environment · needs Base/standard library

set.seed(2026)
n<-30;x<-rnorm(2*n);y<-x^2+rnorm(2*n)
kernel<-function(a,b) (outer(abs(a),abs(b),"+")-abs(outer(a,b,"-")))/2
K<-kernel(x[1:n],x[n+1:n]);L<-kernel(y[1:n],y[n+1:n]);H<-diag(n)-matrix(1/n,n,n)
S<-K%*%H%*%t(L);Q<-(outer(diag(S),diag(S),"+")-S-t(S))/(2*(n-1))
g<-rowSums(Q)/(n-1);U<-mean(g);sn2<-4*(n-1)/(n-2)^2*sum((g-U)^2)
Z<-sqrt(n)*U/sqrt(sn2);print(c(statistic=Z,p=pnorm(Z,lower.tail=FALSE)))
Output
statistic         p 
0.4951709 0.3102398

Sources

  • Shekhar, Kim & Ramdas (2023) — Shekhar, Kim & Ramdas (2023) · A Permutation-Free Kernel Independence Testjmlr.org
  • 23-0248.pdfjmlr.org
Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 088, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT088.