Generalized Cochran Mantel Haenszel test for multilevel correlated categorical data: an algorithm and R function