# Computational Test for Conditional Independence
## Appendix B Pseudocode for Multivariate Distributions Generating Functions for Categorical Data
```
1:\(Z_{1}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
2:\(Z_{2}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
3:for\(i\gets 1\) to \(N\)do
4:if\(Z_{1}[i]<0\)and\(Z_{2}[i]<0\)then
5:\(X[i]\gets 0\)
6:elseif\(Z_{1}[i]<0\)and\(Z_{2}[i]\geq 0\)then
7:\(X[i]\gets 1\)
8:elseif\(Z_{1}[i]>=0\)and\(Z_{2}[i]<0\)then
9:\(X[i]\gets 2\)
10:else
11:\(X[i]\gets 3\)
12:endif
13:if\(Z_{1}[i]<0+Z_{2}[i]<-1\)then
15:\(Y[i]\gets 0\)
16:elseif\(Z_{1}[i]<0+Z_{2}[i]<0\)then
17:\(Y[i]\gets 1\)
18:elseif\(Z_{1}[i]<0+Z_{2}[i]<1\)then
19:\(Y[i]\gets 2\)
20:else
21:\(Y[i]\gets 3\)
22:endif
23:endfor
24:return\(\{Z_{1},Z_{2},X,Y\}\)
```  
**Algorithm A1** Interaction Data (Interaction)  
```
1:\(Z_{1}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
2:\(Z_{2}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
3:for\(i\gets 1\) to \(n\)do
4: Compute \(tempX\leftarrow\exp(Z1[i])+Z2[i]\)
5:if\(tempX>1\)then
6:\(X[i]\gets 3\)
7:elseif\(tempX>0\)then
8:\(X[i]\gets 2\)
9:elseif\(tempX>-1\)then
10:\(X[i]\gets 1\)
11:else
12:\(X[i]\gets 0\)
13:endif
14: Compute \(tempY\leftarrow\log(|Z1[i]|+1)+Z2[i]\)
15:if\(tempY>0.5\)then
16:\(Y[i]\gets 3\)
17:elseif\(tempY>0\)then
18:\(Y[i]\gets 2\)
19:elseif\(tempY>-0.5\)then
20:\(Y[i]\gets 1\)
21:else
22:\(Y[i]\gets 0\)
23:endif
24:endfor
25:return\(\{Z_{1},Z_{2},X,Y\}\)
```  
**Algorithm A2** Exponent and Logarithmic Data (ExpLog)```
1:Initialize number of samples \(N\)
2:\(Z_{1}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
3:\(Z_{2}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
4:for\(i\gets 1\) to \(N\)do
5:if\(Z_{1}[i]^{2}+Z_{2}[i]^{2}>2\)then
6:\(X[i]\gets 3\)
7:elseif\(Z_{1}[i]^{2}+Z_{2}[i]>0.5\)then
8:\(X[i]\gets 2\)
9:elseif\(Z_{1}[i]+Z_{2}[i]^{2}>0\)then
10:\(X[i]\gets 1\)
11:else
12:\(X[i]\gets 0\)
13:endif
14:if\(Z_{1}[i]^{3}+Z_{2}[i]>1\)then
15:\(Y[i]\gets 3\)
16:elseif\(Z_{1}[i]^{2}+Z_{2}[i]^{2}>0\)then
17:\(Y[i]\gets 2\)
18:elseif\(Z_{1}[i]+Z_{2}[i]^{3}>-1\)then
19:\(Y[i]\gets 1\)
20:else
21:\(Y[i]\gets 0\)
22:endif
23:endfor
24:return\(\{Z_{1},Z_{2},X,Y\}\)
```

**Algorithm A3** Polynomial Data (PolyData)

```
1:Initialize number of samples \(N\)
2:\(Z_{1}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
3:\(Z_{2}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
4:for\(i\gets 1\) to \(n\)do
5:if\(sin(Z_{1}[i])+cos(Z_{2}[i])>1\)then
6:\(X[i]\gets 3\)
7:elseif\(sin(Z_{1}[i])+cos(Z_{2}[i])>0\)then
8:\(X[i]\gets 2\)
9:elseif\(sin(Z_{1}[i])>-1\)then
10:\(X[i]\gets 1\)
11:else
12:\(X[i]\gets 0\)
13:endif
14:if\(cos(Z_{1}[i])-sin(Z_{2}[i])>1\)then
15:\(Y[i]\gets 3\)
16:elseif\(cos(Z_{1}[i])-sin(Z_{2}[i])>0\)then
17:\(Y[i]\gets 2\)
18:elseif\(cos(Z_{1}[i])>-1\)then
19:\(Y[i]\gets 1\)
20:else
21:\(Y[i]\gets 0\)
22:endif
23:endfor
24:return\(\{Z_{1},Z_{2},X,Y\}\)
```

**Algorithm A4** Trigonometric Data (TrigData)

```
1:Initialize number of samples \(N\)
2:\(Z_{1}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
3:\(Z_{2}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
4:for\(i\gets 1\) to \(n\)do
5:if\(sin(Z_{1}[i])+cos(Z_{2}[i])>1\)then
6:\(X[i]\gets 3\)
7:elseif\(sin(Z_{1}[i])+cos(Z_{2}[i])>0\)then
8:\(X[i]\gets 2\)
9:elseif\(sin(Z_{1}[i])>-1\)then
10:\(X[i]\gets 1\)
11:else
12:\(X[i]\gets 0\)  
```
1:Initialize number of samples \(N\)
2:\(Z_{1}\leftarrow\text{runif}(N,-1,1)\)
3:\(Z_{2}\leftarrow\text{runif}(N,-1,1)\)
4:for\(i\gets 1\) to \(N\)do
5:if\(\sin(Z_{1}[i]\times\pi)+Z_{2}[i]>1\)then
6:\(X[i]\gets 3\)
7:else if\(\sin(Z_{1}[i]\times\pi)+Z_{2}[i]>0.5\)then
8:\(X[i]\gets 2\)
9:else if\(\sin(Z_{1}[i]\times\pi)+Z_{2}[i]>0\)then
10:\(X[i]\gets 1\)
11:else
12:\(X[i]\gets 0\)
13:endif
14:if\(\cos(Z_{1}[i]\times\pi)+Z_{2}[i]>1\)then
15:\(Y[i]\gets 3\)
16:else if\(\cos(Z_{1}[i]\times\pi)+Z_{2}[i]>0.5\)then
17:\(Y[i]\gets 2\)
18:else if\(\cos(Z_{1}[i]\times\pi)+Z_{2}[i]>0\)then
19:\(Y[i]\gets 1\)
20:else
21:\(Y[i]\gets 0\)
22:endif
23:endfor
24:return\(\{Z_{1},Z_{2},X,Y\}\)
```
**Algorithm A5** Nonlinear Data (Nonlinear)
```
1:Initialize number of samples \(N\)
2:\(Z_{1}\leftarrow\text{Draw }N\) samples from \(\mathcal{N}(0,1)\)
3:\(Z_{2}\leftarrow\text{Draw }N\) samples from \(\mathcal{N}(0,1)\)
4:for\(i\gets 1\) to \(N\)do
5:if\(Z_{1}[i]>0\)and\(Z_{2}[i]>0\)then
6:\(X[i]\gets 3\)
7:else if\(Z_{1}[i]>0\)and\(Z_{2}[i]\leq 0\)then
8:\(X[i]\gets 2\)
9:else if\(Z_{1}[i]\leq 0\)and\(Z_{2}[i]>0\)then
10:\(X[i]\gets 1\)
11:else
12:\(X[i]\gets 0\)
13:endif
14:if\(Z_{1}[i]+Z_{2}[i]>1\)then
15:\(Y[i]\gets 3\)
16:else if\(Z_{1}[i]+Z_{2}[i]>0\)then
17:\(Y[i]\gets 2\)
18:else if\(Z_{1}[i]+Z_{2}[i]>-1\)then
19:\(Y[i]\gets 1\)
20:else
21:\(Y[i]\gets 0\)
22:endif
23:endfor
24:return\(\{Z_{1},Z_{2},X,Y\}\)
```
**Algorithm A6** Complex Categorization (ComplexCategorization)
```
1:Initialize number of samples \(N\)
2:\(Z_{1}\leftarrow\text{Draw }N\) samples from \(\mathcal{N}(0,1)\)
3:\(Z_{2}\leftarrow\text{Draw }N\) samples from \(\mathcal{N}(0,1)\)
4:for\(i\gets 1\) to \(N\)do
5:if\(Z_{1}[i]>0\)and\(Z_{2}[i]>0\)then
6:\(X[i]\gets 3\)
7:else if\(Z_{1}[i]>0\)and\(Z_{2}[i]\leq 0\)then
8:\(X[i]\gets 2\)
9:else if\(Z_{1}[i]\leq 0\)and\(Z_{2}[i]>0\)then
10:\(X[i]\gets 1\)
11:else
12:\(X[i]\gets 0\)
13:endif
14:if\(Z_{1}[i]+Z_{2}[i]>1\)then
15:\(Y[i]\gets 3\)
16:else if\(Z_{1}[i]+Z_{2}[i]>0\)then
17:\(Y[i]\gets 2\)
18:else if\(Z_{1}[i]+Z_{2}[i]>-1\)then
19:\(Y[i]\gets 1\)
20:else
21:\(Y[i]\gets 0\)
22:endif
23:endfor
24:return\(\{Z_{1},Z_{2},X,Y\}\)
```
**Algorithm A7** Complex Categorization (ComplexCategorization)
```
1:Initialize number of samples \(N\)
2:\(Z_{1}\leftarrow\text{Draw }N\) samples from \(\mathcal{N}(0,1)\)
3:\(Z_{2}\leftarrow\text{Draw }N\) samples from \(\mathcal{N}(0,1)\)
4:for\(i\gets 1\) to \(N\)do
5:if\(Z_{1}[i]>0\)and\(Z_{2}[i]\leq 0\)then
6:\(X[i]\gets 2\)
7:else if\(Z_{1}[i]\leq 0\)and\(Z_{2}[i]>0\)then
8:\(X[i]\gets 1\)
9:else
10:\(X[i]\gets 0\)



```
1:Initialize number of samples \(N\)
2:Initialize \(\zeta\gets 1.5\)
3:\(Z_{1}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
4:\(Z_{2}\leftarrow\) Draw \(N\) samples from \(\mathcal{N}(0,1)\)
5:\(random\leftarrow\) Draw \(N\) samples from \(\mathcal{U}(0,1)\)
6:for\(i\gets 1\) to \(N\)do
7:\(xb_{1}[i]\gets Z_{2}[i]+\zeta\times Z_{1}[i]\times Z_{2}[i]+\zeta\times Z _{1}[i]\)
8:\(xb_{2}[i]\gets Z_{2}[i]-\zeta\times Z_{1}\)
9:\(xp_{1}[i]\leftarrow\frac{1+\exp(xb_{1}[i])+\exp(xb_{2}[i])}{1+\exp(xb_{1}[i]) +\exp(xb_{2}[i])}\)
10:\(xp_{2}[i]\leftarrow\frac{\exp(xb_{1}[i])}{1+\exp(xb_{1}[i])+\exp(xb_{2}[i])}\)
11:if\(random[i]<xp_{1}[i]\)then
12:\(X[i]\leftarrow\)\"C\"
13:elseif\(random[i]<xp_{1}[i]+xp_{2}[i]\)then
14:\(X[i]\leftarrow\)\"A\"
15:else
16:\(X[i]\leftarrow\)\"B\"
17:endif
18:endfor
19:\(random2\leftarrow\) Draw \(N\) samples from \(\mathcal{U}(0,1)\)
20:for\(i\gets 1\) to \(N\)do
21:\(yb_{1}[i]\leftarrow\zeta\times Z_{1}[i]\times Z_{2}[i]\)
22:\(yb_{2}[i]\leftarrow\exp(Z_{2}[i])+\zeta\times Z_{1}[i]\)
23:\(yp_{1}[i]\leftarrow\frac{1+\exp(yb_{1}[i])+\exp(yb_{2}[i])}{1+\exp(yb_{1}[i])+ \exp(yb_{2}[i])}\)
24:\(yp_{2}[i]\leftarrow\frac{\exp(yb_{1}[i])}{1+\exp(yb_{1}[i])+\exp(yb_{2}[i])}\)
25:if\(random[i]<yp_{1}[i]\)then
26:\(Y[i]\leftarrow\)\"A\"
27:elseif\(random2[i]<yp_{1}[i]+yp_{2}[i]\)then
28:\(Y[i]\leftarrow\)\"Y\"
29:else
30:\(Y[i]\leftarrow\)\"Z\"
31:endif
32:endfor
33:return\(\{Z_{1},Z_{2},X,Y\}\)
```

**Algorithm A7** Multinomial (Multinomial)

## Appendix C Pseudocode for Multivariate Distributions Generating Functions for Continuous Data

Pseudo code for R functions generating data from multivariate continuous distributions.