Skip to content

CAssociation · Guide test 087

Cross HSIC test

Uses sample splitting to obtain an asymptotically normal kernel independence statistic without permutation calibration.

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 HSIC (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 HSIC test

30

Shape of the link

0.80
0.050

Your data

Simulated with a known link

If H₀ were true

z = 1.58
  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 = .057).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

z=n Uˉs^,Uˉ=1n∑igi (one half against the other)z=\sqrt{n}\,\dfrac{\bar U}{\hat s},\quad \bar U=\tfrac1n\sum_i g_i\ \text{(one half against the other)}

With your numbers

Uˉ=0.01,z=1.58\bar U = 0.01,\qquad z = 1.58
gig_i
cross-kernel scores of each observation in the first half against the second
s^\hat s
their standard deviation

The verdict

z = 1.58, p = .057

p > α = .050: compatible with H₀

Splitting the sample into halves makes the studentized statistic exactly normal in the limit, so no permutations are needed (Shekhar, Kim & Ramdas 2023).

Statistic
1.580
p-value
0.0571
Cross HSIC test on 30 (x, y) pairs: z = 1.58, p = .057. The p-value is above α = .050, so the data are compatible with H0.

Cross HSIC test on 30 (x, y) pairs: z = 1.58, p = .057. 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. Choose kernels as in HSIC.

Structure of the method

Split observations into independent halves, estimate a kernel cross-covariance operator in each half, and take their inner product. Studentize this cross statistic using the specified first-half jackknife variance. The resulting one-sided z test has an asymptotic Gaussian null without repeated permutations.

Estimated and nuisance parameters

Estimated objects are the two empirical operators, their cross inner product, and the studentizing variance. Kernel choices and split allocation are analysis decisions. The symbol n in the formula denotes each half’s size, so the total number of observations is 2n.

Settings and design choices

Fix the split, kernels, bandwidth policy, and significance level before inspecting the result. The displayed variance needs n greater than two and a nondegenerate estimate. Repeated splitting requires a prespecified valid aggregation rule; selecting the best split p-value is not calibration.

Fitting and adaptation

A new sample requires new operators and variance estimation. If a bandwidth or representation is learned from paired dependence, separate that selection from testing or use a theory-covered construction. There is no neural fine-tuning in the statistic; adaptive feature learning changes its inferential problem.

Sensitivity and robustness

Asymptotic normality is not an exact distribution-free small-sample guarantee. Nearly zero studentizing variance, unusual kernel moments, and strong row dependence need attention. Compare null rejection behavior on representative simulations without using the final observed p-value to choose a favorable method.

How to use and calibrate

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

Example application

Test 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 np.exp(-(a[:,None]-b[None,:])**2/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
1.5914185533102723 0.0557577058133826
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) exp(-outer(a,b,"-")^2/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.2303958 0.4088921

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 087, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT087.