Tutorials › Multivariate Statistics (Graduate) › Worked Independence-Test Selection and Analysis

Multivariate Dependence Testing · Tutorial 455 of 975

Worked Independence-Test Selection and Analysis

Choose and analyze an independence test by aligning its statistic and calibration with the data design and the alternatives of interest.

Advanced 13 min read

What You'll Learn

  • Match cross-covariance, distance covariance, and HSIC to the dependence patterns they can detect.
  • Calculate a sample cross-covariance matrix without confusing it with an uncentered cross-moment.
  • Justify an exact permutation test under the independence null and identify when unrestricted permutations are invalid.
  • Interpret a permutation p-value in light of the test’s resolution and sensitivity.
  • Report nonrejection without claiming that independence has been proved.
  • Recognize when test selection or bandwidth choices require sensitivity analysis or adjustment.

From a Scientific Question to a Test

A test of independence asks whether two random vectors \(X\in\mathbb{R}^p\) and \(Y\in\mathbb{R}^q\) are independent. Choosing a statistic is not just a computational decision: different statistics respond to different forms of association. A test can be correctly calibrated and still have little power against the dependence pattern that matters in an application.

A defensible analysis therefore connects four decisions: the alternatives that matter, the statistic’s sensitivity to those alternatives, the calibration justified by the design, and the limits of the conclusion. Cross-covariance, distance covariance, and HSIC offer different approaches. Their established properties provide a starting point, but no single statistic is automatically best for every problem.

Definition: The independence null hypothesis is \(H_0: X\text{ and }Y\text{ are independent}\). A test statistic \(T_n\) measures a feature of the paired observations \((X_i,Y_i)\), \(i=1,\ldots,n\). A p-value is calculated relative to the distribution of \(T_n\) under \(H_0\), using a calibration justified by the sampling design and assumptions.

The population cross-covariance matrix is \(\operatorname{Cov}(X,Y)=E[(X-E[X])(Y-E[Y])^T]\), when the required moments exist. Distance covariance and HSIC instead use distances or kernels to capture broader distributional features. Under their respective regularity conditions, distance covariance and HSIC with characteristic kernels can detect general forms of dependence; the earlier material on distance covariance and HSIC gives their definitions and consistency conditions.

StatisticUseful whenImportant limitation
Cross-covarianceLinear cross-association is scientifically meaningful, or a focused low-dimensional summary is needed.A zero population cross-covariance does not imply independence.
Distance covarianceBroad dependence is of interest and the variables have suitable Euclidean representations and moments.Finite-sample sensitivity depends on the alternative and the chosen distance formulation.
HSICBroad dependence is of interest and meaningful kernels are available for both variables.Kernel and bandwidth choices can materially affect finite-sample power.

What Cross-Covariance Can and Cannot Establish

A basic implication helps explain the limitation of cross-covariance. If \(X\) and \(Y\) are independent and have finite second moments, their population cross-covariance is zero. The converse is generally false.

Proposition: If \(X\in\mathbb{R}^p\) and \(Y\in\mathbb{R}^q\) are independent and have finite second moments, then \(\operatorname{Cov}(X,Y)=0_{p\times q}\).

Proof. Write \(\mu_X=E[X]\) and \(\mu_Y=E[Y]\). Finite second moments ensure that each coordinate product below is integrable, by the Cauchy–Schwarz inequality. For every coordinate pair \(j,k\), independence gives \(E[(X_j-\mu_{X,j})(Y_k-\mu_{Y,k})]=E[X_j-\mu_{X,j}]E[Y_k-\mu_{Y,k}]=0\). Thus every entry of the cross-covariance matrix is zero. \(\square\)

Worked Example: Zero Covariance but Complete Dependence

Let \(X\) take the values \(-2,-1,1,2\), each with probability \(1/4\), and define \(Y=X^2\). Calculate the covariance and check whether \(X\) and \(Y\) are independent.

The symmetry of the four equally likely values gives \(E[X]=(-2-1+1+2)/4=0\). Also, \(E[Y]=(4+1+1+4)/4=5/2\), and \(E[XY]=E[X^3]=(-8-1+1+8)/4=0\). Therefore \(\operatorname{Cov}(X,Y)=E[XY]-E[X]E[Y]=0\).

But \(Y=X^2\) with probability one, so knowing \(X\) determines \(Y\). In particular, \(P(Y=1)=1/2\), whereas \(P(X=1,Y=1)=1/4\) and \(P(X=1)P(Y=1)=1/8\). These unequal probabilities violate the definition of independence. A cross-covariance test is consequently not a general test of independence; a distance or kernel test may be more appropriate if such nonlinear dependence is of interest.

Calculate the Statistic Before Calibrating It

For paired observations, an empirical cross-covariance matrix can be defined with divisor \(n\) as \(\widehat C_{XY}=n^{-1}\sum_{i=1}^n(X_i-\bar X)(Y_i-\bar Y)^T\). This convention is useful for defining a test statistic; a sample covariance using divisor \(n-1\) is a different scaling. In either case, centering matters. The uncentered quantity \(n^{-1}\sum_i X_iY_i^T\) is a cross-moment, not generally a cross-covariance.

Worked Example: Computing a Paired Cross-Covariance Matrix

Take four paired observations with \(X_i=Y_i\), where the vectors are \((1,0)^T,(0,1)^T,(-1,0)^T,(0,-1)^T\). Compute the empirical cross-covariance using divisor \(n=4\).

Both sample means are zero: the first and third vectors cancel, as do the second and fourth. Thus the centered cross-products equal the uncentered outer products. In order, these are \[ \begin{pmatrix}1&0\\0&0\end{pmatrix},\quad \begin{pmatrix}0&0\\0&1\end{pmatrix},\quad \begin{pmatrix}1&0\\0&0\end{pmatrix},\quad \begin{pmatrix}0&0\\0&1\end{pmatrix}. \] Their sum is \(\begin{pmatrix}2&0\\0&2\end{pmatrix}\), so \(\widehat C_{XY}=\frac14\begin{pmatrix}2&0\\0&2\end{pmatrix}=\frac12 I_2\). The Frobenius norm is \(\|\widehat C_{XY}\|_F=\sqrt{(1/2)^2+(1/2)^2}=1/\sqrt{2}\). If divisor \(n-1=3\) were used instead, the matrix would be \((2/3)I_2\). Neither calculated matrix, by itself, is evidence of a statistically significant association; that requires a justified reference distribution.

For a matrix-valued statistic, a scalar test statistic might be a norm such as \(\|\widehat C_{XY}\|_F\). But scaling variables differently can change that norm, and a few large-scale coordinates can dominate it. Standardization may help when scientifically appropriate, but estimating scale parameters can also affect calibration. The choice should be specified and justified rather than made after inspecting which version gives the smallest p-value.

Calibration: Match the Reference Distribution to the Design

A statistic’s null distribution is not determined by its formula alone. For example, under independence, appropriately exchangeable paired observations permit a permutation test: keep the \(X\) observations fixed, permute the \(Y\) observations among them, and recalculate the statistic. This tests whether the observed pairings are unusually associated relative to pairings allowed under the null. It is not valid to permute freely when the study design restricts which observations can be exchanged; in an exchangeable design, the appropriate restricted permutations must respect those restrictions.

Theorem: Suppose \((X_i,Y_i)\), \(i=1,\ldots,n\), are independent and identically distributed pairs, and \(X\) and \(Y\) are independent under \(H_0\). For any statistic \(T\) and a fixed set of observed \(X\) and \(Y\) values, define the upper-tail permutation p-value by \(p=(1/n!)\sum_{\pi} I\{T(X_1,\ldots,X_n;Y_{\pi(1)},\ldots,Y_{\pi(n)})\geq T_{\mathrm{obs}}\}\), where the sum is over all permutations. Then the test that rejects when \(p\leq\alpha\) has conditional type-I error at most \(\alpha\). The conclusion remains conservative in the presence of ties.

Proof. Under the null, the joint distribution of all observed \(X\) and \(Y\) values is invariant to permuting the \(Y\) labels: independence separates the \(X\) sample from the \(Y\) sample, and the identically distributed \(Y_i\) are exchangeable. Conditional on the observed values, the observed matching therefore has the same distribution as a uniformly selected matching from its permutation orbit. In the absence of ties, the rank of the observed statistic among the \(n!\) permuted statistics is uniform, so the fraction of statistics at least as large as the observed one is a valid upper-tail p-value. With ties, counting all statistics equal to the observed value in the upper tail can only increase this fraction, making the test conservative. Hence \(P(p\leq\alpha\mid\text{observed values})\leq\alpha\), and averaging over the observed values gives the unconditional level bound. \(\square\)

When enumerating all permutations is impractical, a Monte Carlo permutation procedure approximates the reference distribution; its p-value calculation must account for the finite number of sampled permutations. Other calibrations may be appropriate for other settings. For instance, parametric bootstrap calibration requires a credible parametric model and must account for estimated margins when those are part of the procedure. Distance and kernel statistics can have degenerate null limits, so using an ordinary normal or chi-square reference distribution without justification can give incorrect type-I error. The earlier material on degenerate null calibration addresses this issue.

Worked Example: An Exact Permutation Analysis

For \(n=4\), observe scalar values \(X=(1,2,3,4)\) and \(Y=(1,2,3,4)\) in the same order. Use the absolute centered cross-product as the statistic and enumerate its exact upper-tail permutation p-value.

The centered \(X\) values are \((-3/2,-1/2,1/2,3/2)\); the centered \(Y\) values are the same. The observed centered cross-product sum is \((-3/2)^2+(-1/2)^2+(1/2)^2+(3/2)^2=5\). Using the average rather than the sum gives \(T_{\mathrm{obs}}=5/4\); either scaling produces the same permutation ordering.

There are \(4!=24\) possible assignments of the four distinct \(Y\) values. By the rearrangement inequality, the largest centered sum is \(5\), attained only by the increasing assignment, and the smallest is \(-5\), attained only by the decreasing assignment. Since the statistic is the absolute value, exactly two permutations are at least as extreme as the observed value. Therefore \(p=2/24=1/12\approx0.0833\). At significance level \(0.05\), this analysis does not reject independence; at level \(0.10\), it does. With only four observations, the p-value has limited resolution, and this calculation alone does not establish that the association will reproduce in a broader population.

Sensitivity, Selection, and the Reported Conclusion

A practical selection process begins with the scientific alternative, not with a search for the smallest p-value. If linear cross-association is the target, a cross-covariance statistic may give a direct and interpretable test. If nonlinear or more general dependence is important, distance covariance or HSIC may be better aligned with the question. Kernel choice and bandwidth can influence HSIC’s finite-sample behavior, so prespecified alternatives or a justified sensitivity analysis are more informative than silently reporting whichever choice rejects.

Sensitivity analysis asks whether the substantive conclusion changes under reasonable, defensible choices: for example, alternative kernel bandwidths, distance specifications, or scaling conventions. It does not make an invalid calibration valid. If the analysis selects a statistic, bandwidth, or preprocessing rule after examining the same data, the nominal p-value for the selected procedure may no longer control the type-I error. Prespecification, an appropriate multiplicity adjustment, or genuinely separate data for selection and testing can address this concern.

The report should name the test statistic, explain why its sensitivity fits the scientific question, identify the calibration and the design assumptions that justify it, and give the p-value and chosen significance level. A rejection is evidence against independence under the stated procedure; it does not identify a causal direction or establish the form or practical importance of the dependence. A nonrejection means the data did not provide sufficient evidence against independence with this test, sample size, and calibration. It does not prove independence, especially when the test may be insensitive to relevant alternatives.

Common Mistakes

  • Equating zero cross-covariance with independence. Zero cross-covariance is necessary under independence with finite second moments, but the worked nonlinear example shows it is not sufficient.
  • Using an uncentered cross-moment as though it were a covariance. Subtract the sample means in the empirical covariance, or state explicitly that the uncentered quantity is being used.
  • Permuting observations that the design does not permit exchanging. Unrestricted permutations require exchangeability under the null; use design-respecting permutations when exchangeability is restricted.
  • Treating every calibrated test as equally sensitive. Calibration controls false positives under its assumptions; it does not guarantee power against every dependence pattern.
  • Interpreting nonrejection as proof of independence. State the evidence and its limits, including the statistic, calibration, and relevant sensitivity checks.
Key takeaway: Select the statistic for the dependence patterns of interest, calculate it correctly, and calibrate it under assumptions justified by the sampling design. The conclusion must remain within what that procedure can support.

Check Your Understanding

Use these questions to check both the calculations and the reasoning behind a test choice.

  1. Why does independence imply zero cross-covariance when second moments exist, and why does the converse fail?
  2. What distinction separates a sample cross-covariance matrix from an uncentered cross-moment?
  3. What assumptions justify unrestricted permutation of the \(Y\) observations in an independence test?
  4. Why might distance covariance or HSIC be selected instead of a cross-covariance statistic?
  5. What should be reported when a valid test does not reject the independence null?
Clinical Biostats