# Computational Test for Conditional Independence
#### Conditional Independence Testing  
A common notation of CI between random variables \(Y\) and \(X\) given \(Z\) is  
\[Y\perp\!\!\!\perp X|Z\Leftrightarrow X\perp\!\!\!\perp Y|Z, \tag{1}\]  
where \(Z\) can be extended to a set of variables \(\mathbf{Z}\). One can also express CI using probability distributions; \(p(Y\mid X,\mathbf{Z})=p(Y\mid\mathbf{Z})\) where \(p(\mathbf{Z})>0\), or \(p(X,Y\mid\mathbf{Z})=p(X\mid\mathbf{Z})p(Y\mid\mathbf{Z})\), which is to say that given that we know \(\mathbf{Z}=\mathbf{z}\) neither \(X\) nor \(Y\) carries information about each other's distribution [12].  
When \(Y\) and \(X\) are continuous and the conditioning set \(\mathbf{Z}\) contains a mixture of variable types, numerous testing methods for CI exist. The two state-of-the-art and readily available methods are the kernel-based test (KCI test) from [6] and the generalized covariance measure (GCM test) [1]. The KCI test is based on the foundational idea that the uncorrelatedness between functions in kernel Hilbert spaces can characterize statistical independence and CI. The test uses kernel matrices associated with the variables to construct a test statistic based on these matrices. As it stands, the test is designed for continuous data. However, since the KCI test uses a kernel function, it can potentially be modified to account for other data types by changing the function. The GCM test is based on the fact that the standardized covariance between residuals from the two generic regressions \(y=h(z)\) and \(x=g(z)\) follows, under the null hypothesis and given relatively mild assumptions, an asymptotic standard normal distribution. Although the GCM test statistic is designed for continuous data types, it also handles binary data well.  
When dealing with purely categorical variables within the CI statement, i.e., categorical variables with more than two categories, the literature on testing methods is somewhat scarcer. In cases where \(Y\), \(X\), and \(Z\) in Equation (1) are all categorical or of discrete types, the conditional \(\chi^{2}\) test, also known as the Cochran-Mantel-Haenszel test, is a well-known and reliable test. The \(\chi^{2}\) test requires sufficiently many observations in each conditioned category to function optimally [13] (pp. 231-232). Testing based on mutual information is also a common choice for testing CI with only discrete data [14]. However, in CI statements where either \(X\) or \(Y\) or both are categorical and \(Z\) consists of continuous variables, or a mix of continuous variables and other types, there are, to our knowledge, no reliable testing methods available. For example, it is suggested to employ multinomial regression or abstain from testing altogether [2]. Testing CI with a parametric model is problematic as it relies on specifying the correct, or close to correct, functional form.  
To create a CI testing framework for categorical variables, we suggest using ML classification algorithms in combination with permutation and Monte Carlo cross-validation (MCCV) to create a null distribution. One utilizes the same ML classification model without permutation with one train-test split to obtain the test statistic and \(p\)-value. As an extension to this, one can also create a test statistic distribution with MCCV and assess a distribution of \(p\)-values, which is a helpful extension in cases where testing is done with a limited sample size. The organization of our article is as follows: Section 2 details our proposed testing procedure, Section 3 presents the simulation study exploring key aspects such as type I error rates and power under difficult testing conditions. In Section 4, we present an illustrative example of the testing procedure, and test results of multiple simulations over a range of multivariate distributions. A general discussion follows in Section 5, and concluding remarks in Section 6.