# Dichotomization of Multilevel Variables to Detect Hidden Associations
## 3 Materials and Methods  
### Method  
To avoid the scenarios, such as the one explained in the problem formulation subsection, we propose to transform the original variables \(\text{V}_{1}\) and \(\text{V}_{2}\), into new synthetic dichotomous variables \(\mathcal{A}\) and \(\mathcal{B}\), respectively. These new variables contain the fusion of different levels of each variable. In general, for each synthetic variable (\(\mathcal{A}\) or \(\mathcal{B}\)), the exact number of fusions of levels is the semi-sum of the number of combinations of \(L_{1}\) or \(L_{2}\) taking \(r\) levels at a time. This is computed as follows:  
\[N_{\mathcal{A}}=\Big{\lfloor}\frac{1}{2}\sum_{r=1}^{L_{1}}\frac{L_{1}!}{r!(L_ {1}-r)!}\Big{\rfloor} \tag{1}\]  
\[N_{\mathcal{B}}=\Big{\lfloor}\frac{1}{2}\sum_{r=1}^{L_{2}}\frac{L_{2}!}{r!(L_ {2}-r)!}\Big{\rfloor} \tag{2}\]  
where  
\(N_{\mathcal{A}}\) is the number of fusions of the \(L_{1}\) levels of variable \(V_{1}\),  
\(N_{\mathcal{B}}\)  
For V\({}_{1}\), we have \(L_{1}=4\), whereas for V\({}_{2}\) the number of levels is \(L_{2}=3\). The number of possible combinations for the fusions of variables \(\mathcal{A}\) and \(\mathcal{B}\) is computed with Equations (1) and (2):  
\[N_{\mathcal{A}}=\Big{\lfloor}\frac{1}{2}\sum_{r=1}^{L_{1}}\frac{L_{1}}{r(L_{1} -r)}\Big{\rfloor}=\Big{\lfloor}\frac{1}{2}\Big{(}\frac{4!}{1!(4-1)!}+\frac{4! }{2!(4-2)!}+\frac{4!}{3!(4-3)!}+\frac{4!}{4!(4-4)!}\Big{)}\Big{\rfloor}=7\]  
\[N_{\mathcal{B}}=\Big{\lfloor}\frac{1}{2}\sum_{r=1}^{L_{2}}\frac{L_{2}}{r(L_{2} -r)}\Big{\rfloor}=\Big{\lfloor}\frac{1}{2}\Big{(}\frac{3!}{1!(3-1)!}+\frac{3! }{2!(3-2)!}+\frac{3!}{3!(3-3)!}\Big{\rfloor}=3\]  
A total of 21 tests of independence are needed to completely explore the possible associations between V\({}_{1}\) and V\({}_{2}\). For this small example, it is possible to show all the fusions of levels; these are listed in Table 3.  
Algorithm 1 shows the complete method for completely exploring the associations between categorical variables with two or more levels. An implementation of this method in the Python programming language is publicly available at [[http://u.pc.cd/JjCrtalK](http://u.pc.cd/JjCrtalK)]([http://u.pc.cd/JjCrtalK](http://u.pc.cd/JjCrtalK)) (accessed on 1 December 2022). The computational load of Algorithm 1 is high. Considering only the most costly steps, we have the following. The generation of all combinations of n elements, taking \(r\) at a time (Line 26) has a cost of \(\mathcal{O}\Big{(} \begin{pmatrix}n\\ 1\end{pmatrix} + \begin{pmatrix}n\\ 2\end{pmatrix} +...+ \begin{pmatrix}n\\ \lfloor\frac{n}{2}\rfloor\end{pmatrix} \Big{)}\approx\mathcal{O}(2^{n})\). In addition, the creation of the synthetic variables, that is, the level partitioning of each variable, has a linear cost with respect to the size of the data set. The Processing with categorical variables of more than 12 levels with hundreds of pieces of data takes several minutes on everyday personal computers and hours if the number of samples are thousands. \begin{table}
\begin{tabular}{c c c c} \hline \hline  & \(\mathcal{A}\) & & \(\mathcal{B}\) \\ \hline
**Category I\({}_{\mathcal{A}}\)** & **Category II\({}_{\mathcal{A}}\)** & **Category Ig** & **Category II\({}_{\mathcal{B}}\)** \\
1 single & 1 married, divorced, widower & 1 private & 1 self-employment, never-worked \\
2 married & 2 single, divorced, widower & 2 self-employment & 2 private, never-worked \\
3 divorced & 3 single, married, widower & 3 never-worked & 3 private, self-employment \\
4 widower & 4 single, married, widower & & \\
5 single, married & 5 divorced, widower & & \\
6 single, divorced & 6 married, divorced & & \\
7 single, widower & 7 married, divorced & & \\ \hline \hline \end{tabular}
\end{table} 
Table 3: List of all possible fusions of variables’ levels.