Calculation of Chi-Square for Complex Contingency Tables