NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Nearest-Neighbor Sampling Based Conditional Independence Testing

Shuai Li, Ziqi Chen, Hongtu Zhu, Christina Dan Wang, Wang Wen

Introduction

Conditional Independence Testing (CIT) is a fundamental task in statistical inference, serving as a building block for causal discovery and graphical modeling. The goal is to determine whether two variables, $X$ and $Y$, are independent given a third conditioning variable $Z$ ($X \perp Y | Z$). While CIT is straightforward in low-dimensional settings, it becomes notoriously difficult when $Z$ is high-dimensional—a challenge often referred to as the "curse of dimensionality."

Modern approaches to CIT frequently employ the Conditional Randomization Test (CRT) framework. The CRT relies on generating "pseudo-samples" of $X$ from the conditional distribution $p(X|Z)$ to establish a null distribution. However, in practice, $p(X|Z)$ is rarely known. Recent attempts to use deep generative models, such as Generative Adversarial Networks (GANs), to estimate this distribution have faced significant hurdles: they are computationally expensive to train and often fail to capture the true distribution accurately, leading to inflated Type-I errors (false positives).

This paper introduces NNSCIT, a novel method that replaces complex generative models with a simple, theoretically grounded 1-Nearest-Neighbor (1-NN) sampling strategy. By leveraging the empirical distribution of the data, NNSCIT achieves superior control over false positives and maintains high statistical power even in high-dimensional settings.

The NNSCIT Methodology

The core innovation of NNSCIT lies in its move away from parametric or deep generative modeling toward a non-parametric sampling approach. The method consists of three primary components:

1. 1-Nearest-Neighbor Sampling

To generate a pseudo-sample for a given observation $Z_i$, the algorithm utilizes a separate training dataset. It identifies the observation $Z_j$ in the training set that is closest to $Z_i$ (using $l_2$ distance) and "borrows" the corresponding $X_j$ to serve as the pseudo-sample. The authors provide theoretical justification for this approach, proving that as the sample size $n$ increases, the distribution of these 1-NN samples converges to the true conditional distribution in terms of Total Variation distance.

2. Test Statistic: CCMI

To measure the dependence between variables, NNSCIT employs Classifier-based Conditional Mutual Information (CCMI). This involves training a neural network to distinguish between the joint distribution and the product of marginals. This metric effectively captures the amount of information shared between $X$ and $Y$ given $Z$, providing a robust signal for independence testing.

3. Computational Efficiency

A major bottleneck in CRT-based methods is the need to calculate the test statistic for every permutation to derive a p-value. The authors introduce a computational shortcut, proving that they can replace the complex conditional calculation $I(X^{(m)}; Y | Z)$ with a simpler marginal calculation $I(X^{(m)}; Y)$ for the pseudo-samples. This optimization significantly accelerates the testing process without compromising the validity of the results.

Experimental Evaluation

The authors evaluated NNSCIT across four synthetic scenarios designed to simulate complex, real-world dependencies, including linear and highly non-linear relationships (using functions like $\tanh(x)$ and $\cos(x)$). The conditioning variable $Z$ was tested at dimensions ($d_Z$) ranging from 30 to 120.

Key Findings:

  • Superior Type-I Error Control: In high-dimensional linear scenarios, competing methods like GCIT (Generative Conditional Independence Test) saw false positive rates climb as high as 0.93. In contrast, NNSCIT consistently maintained a Type-I error rate near the target significance level of 0.05.
  • High Statistical Power: In specific non-linear structures (e.g., $X \to Z \leftarrow Y$), NNSCIT achieved a power of 1.0, perfectly detecting dependencies where traditional methods like RCIT and KCIT failed, often staying below a power of 0.2.
  • Robustness to Dimensionality: Unlike kernel-based or residual-based tests that degrade as the dimension of $Z$ increases, NNSCIT remained stable even at $d_Z = 120$.
  • Speed: By avoiding the iterative training cycles required by GANs, NNSCIT is computationally efficient and feasible for large-scale discovery tasks where other neural-network-based CIT methods are often too slow for practical use.

Discussion and Limitations

NNSCIT demonstrates that "simple" empirical sampling can outperform complex generative models in the context of CIT. While GANs often struggle with mode collapse or biasing outputs toward the edges of a distribution, 1-NN sampling remains faithful to the observed data manifold.

However, the method is not without limitations. The current study focuses primarily on univariate $X$ and $Y$. While the framework can be extended to multivariate cases, its performance in extremely high-dimensional $X, Y$ spaces remains an area for future exploration. Additionally, as a nearest-neighbor method, its accuracy is inherently tied to sample density; in extremely sparse regimes, the "nearest" neighbor may not be sufficiently close to provide an accurate conditional approximation. Finally, the reliance on $l_2$ distance suggests that exploring alternative metrics or learned embeddings for $Z$ could further enhance the method's performance in complex data spaces.

Conclusion

NNSCIT provides a powerful and efficient alternative to generative-model-based CIT. By combining the simplicity of 1-NN sampling with the robust CCMI test statistic, it offers a practical solution to the curse of dimensionality in conditional independence testing, ensuring both statistical validity and computational scalability.

Summary updated

BibTeX
@inproceedings{li2023nearest,
  author = {Shuai Li and Ziqi Chen and Hongtu Zhu and Christina Dan Wang and Wang Wen},
  title = {{Nearest-Neighbor Sampling Based Conditional Independence Testing}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i7.26039},
}
Figure