1 Introduction

There has been a great deal of attention given to the analysis of big data in the last few years (Tsai et al. 2015; Luo et al. 2016). For many areas of research—especially marketing, social, political, business and medical studies—much of their data is collected from surveys and questionnaires that comprise of questions whose responses are categorical. Understanding the association between multiple categorical variables in such cases is a big challenge for data scientists (Loughin and Scherer 1998). Central to studying these associations is Pearson’s chi-squared statistic and tests of independence; both of which are appropriate for the analysis of symmetrically associated variables where all variables are treated as explanatory variables. For the study of three categorical variables (Kroonenberg 1989; Carlier and Kroonenberg 1996) presented a decomposition of Pearson’s chi-squared statistic using Lancaster’s (1951) additive decomposition. The advantage of this decomposition is that each term reflects a specific source of association which can be tested for statistical significance.

Beh and Davy (1998) presented the partition of Pearson’s chi-squared statistic using orthogonal polynomials for three-way contingency tables where all three variables consist of completely ordered categories. Their partition isolates location (or linear), dispersion (quadratic) and higher order components for each variable and determines the three-way association and each combination of two-way associations for the three variables. The case when only one or two variables are ordered is studied in Beh and Davy (1999).

While Pearson’s statistic considers a symmetric association structure between categorical variables, one may also examine the partition of a measure of asymmetric association; where, for a two-way contingency table, one variable is treated as a predictor variable and the second is considered a response variable. In such cases, the Goodman–Kruskal tau index (Goodman and Kruskal 1954) may be used as an alternative to Pearson’s statistic. For ordinal two-way tables, D’Ambra et al. (2005) partitioned the Goodman–Kruskal tau index into components that reflect sources of association in terms of the location, dispersion and higher order moments for each variable. Three-way analogues of the Goodman–Kruskal tau index include the Gray–Williams statistic (Gray and Williams 1975), the delta index (Lombardo 1994, 2011) and Marcotorchino’s index (Marcotorchino 1984). Lombardo et al. (1996) presented the partition of Marcotorchino’s index that is an asymmetric analogue of Beh and Davy’s (1998, 1999) partition of Pearson’s chi-squared statistic and Lombardo (2011) presented a similar partition for the delta index.

Loisel and Takane (2016) clarified the expositions proposed by Lancaster (1951) on an ANOVA-like partition of Pearson’s statistic proposed under various representative hypotheses about the expected frequencies and further extended it to more general situations. The approach of Loisel and Takane (2016) involves transforming the diagonal matrix of hypothesized joint probabilities of the cells and the vector of observed joint probabilities from two-way/multi-way tables into a vector such that its inner product is equivalent to Pearson’s chi-squared statistic for that table. Thus, the method of partitioning the chi-squared statistic used by Loisel and Takane (2016) involves the transformation, vectorisation and construction of fully orthogonal matrices of appropriate dimension for each factor/association term and the use of Kronecker products. The idea of the partition is based on expressing the chi-squared statistic as a quadratic form in idempotent matrix. This method is applicable to multi-way contingency tables but involves matrices of sizes almost as large as all possible combinations of categories of all variables in the multi-way table. They also compare the partition of Pearson’s statistic with analogous decompositions of the log likelihood ratio statistic associated with log-linear analysis of a contingency table. Lombardo et al. (2020) developed a general framework for ANOVA-like decompositions of Pearson’s statistic under the independence assumption. It also accommodates the cases of specification of theoretically driven probabilities as well as the cases in which the marginal probabilities are fixed or estimated from the data. Lombardo et al. (2021) used orthogonal polynomials and/or the singular vectors to partition the three-way symmetric and asymmetric measures of association and demonstrate this partition with examples.

Lombardo et al. (2017) provided the chi2 × 3way package in R for partitioning three-way chi-squared statistic and Marcotorchino index, under two scenarios based on Kronecker product. Lombardo and Beh (2021) developed the CAvariants package in R which provides six variants of two-way correspondence analysis (CA). Lombardo et al. (2022) developed the CA3variants package in R which performs four variants of three-way CA. Both the chi2 × 3way and CA3variants R-packages can only be used on three-way tables. This motivated us to develop an algorithm that will theoretically deal with the partitions for multi-way tables and easily implement in software.

The main aim of the present paper is to develop an algorithm that simplifies the calculation of the terms from the partition of Pearson’s chi-squared statistic for multi-way contingency tables. Furthermore, the implementation of the new algorithm for partitions involving software that use tensors makes it more efficient than the existing ones. A Matlab function ‘catanova()’ is developed which gives an ANOVA-like partition for a multi-way contingency table. Such partitions quantify two-way, three-way and higher-way terms of association of a multi-way contingency table where all the terms can be formally tested for statistical significance through this function. Thus, the generalisation of what the chi2 × 3way package does for three-way tables is incorporated into the algorithm described in this paper.

This paper is organised as follows. Section 2 briefly describes the partition of Pearson’s chi-squared statistic by Carlier and Kroonenberg (1996) for three-way contingency tables. In Sect. 3, we extend their partition to four-way, five-way and multi-way contingency tables. Section 4 proposes a fast and efficient method of partitioning Pearson’s statistic yielding association terms for multi-way contingency tables. Section 5 provides an overview of tensors and utilizes them for the development of the proposed algorithm. Section 6 demonstrates the speed and applicability of this algorithm through a practical and simulation study; the practical demonstration of the algorithm is undertaken by considering contingency tables that have been commonly analysed in the literature. We provide some concluding remarks in Sect. 7.

2 Partition of Pearson’s Chi-Squared Statistic for a Three-way Contingency Table

Carlier and Kroonenberg (1996) presented a decomposition of Pearson’s chi-squared statistic for a three-way contingency table using Lancaster’s (1951) additive decomposition. Before we discuss the new algorithm (in Sect. 4), we first provide an overview of the partition of Pearson’s chi-squared statistic for a three-way contingency table.

Let \(n\) individuals be classified by three categorical variables \({A}_{1},{A}_{2}\) and \({A}_{3}\) with \({j}_{1},{j}_{2}\) and \({j}_{3}\) number of categories respectively. Let \({\varvec{N}}=\left({n}_{{i}_{1}{i}_{2}{i}_{3}}\right)\) be the corresponding three-way contingency table where \({n}_{{i}_{1}{i}_{2}{i}_{3}}\) is the number of individuals classified into \({i}_{k}^{th}\) category of the \({k}^{th}\) variable, for \({i}_{k}=\mathrm{1,2},\dots ,{j}_{k},\) and \(k=1, 2, 3.\) The matrix of joint proportions is \(P=\frac{1}{n}{\varvec{N}}=\left({p}_{{i}_{1}{i}_{2}{i}_{3}}\right)\) so that \(0\le {p}_{{i}_{1}{i}_{2}{i}_{3}}<1, \forall ({i}_{1},{i}_{2},{i}_{3})\) and \(\sum_{{i}_{1},{i}_{2},{i}_{3}}{p}_{{i}_{1}{i}_{2}{i}_{3}}=1\). The marginal proportion of variable \({A}_{1}\) is \({p}_{{i}_{1}..}=\sum_{{i}_{2},{i}_{3}}{p}_{{i}_{1}{i}_{2}{i}_{3}}, {i}_{1}=\mathrm{1,2},\dots ,{j}_{1}\). Define an inner product of two three-way arrays \(A=({a}_{{i}_{1}{i}_{2}{i}_{3}})\) and \(B=({b}_{{i}_{1}{i}_{2}{i}_{3}})\), \({\mathbb{R}}^{{j}_{1}\times {j}_{2}\times {j}_{3}}\), as

$$\left\langle {A,B} \right\rangle = \mathop \sum \limits_{{i_{1} ,i_{2} ,i_{3} }} p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} a_{{i_{1} i_{2} i_{3} }} b_{{i_{1} i_{2} i_{3} }} .$$

By doing so, \(A\) and \(B\) are orthogonal if \(<A,B>=0\).

The total inertia of the contingency table, which is also referred as its Pearson’s mean squared contingency coefficient or, alternatively, phi-squared statistic, \({\Phi }^{2}\), is based on the deviation of the observed joint proportions from the three-way independence model, and is defined as

$${\Phi }^{2} = \sum\limits_{{i_{1} ,i_{2} ,i_{3} }} {\frac{{\left( {p_{{i_{1} i_{2} i_{3} }} - p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} } \right)^{2} }}{{p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} }}} .$$

We shall refer to \({\Phi }^{2}\) as simply the total inertia of the contingency table. Such terminology is especially common in CA (Greenacre 1984; Beh and Lombardo 2014) and quantifies the symmetric association between categorical variables and is independent of the sample size. The total inertia, \({\Phi }^{2}\), can be expressed as the weighted norm of the \({j}_{1}\times {j}_{2}\times {j}_{3}\) array \(\boldsymbol{\Pi }\) whose \({\left({i}_{1},{i}_{2},{i}_{3}\right)}^{th}\) cell value is \({\pi }_{{i}_{1}{i}_{2}{i}_{3}}=\frac{{p}_{{i}_{1}{i}_{2}{i}_{3}}}{{p}_{{i}_{1}..}{p}_{.{i}_{2}.}{p}_{..{i}_{3}}}-1\) and is a measure of departure from complete independence of that cell such that

$${\Phi }^{2} = \sum\limits_{{i_{1} ,i_{2} ,i_{3} }} {p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} } \left( {\frac{{p_{{i_{1} i_{2} i_{3} }} }}{{p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} }} - 1} \right)^{2} ={\varvec{\varPi}}^{2}$$

Thus, \({\Phi }^{2}\) is the weighted sum-of-squares of the deviations of the observed relative frequencies from their expected value under complete independence, where the weights are given by the product of the marginal proportions, \({p}_{{i}_{1}..}{p}_{.{i}_{2}.}{p}_{..{i}_{3}}\). Consider the following three-way arrays and their corresponding elements that are weighted sums of the marginal proportions:

$$\begin{aligned}{\varvec{\varPi}}_{ \ldots } = & \left( {\pi_{ \ldots } } \right),\quad{\varvec{\varPi}}_{{{\varvec{i}}_{1} ..}} = \left( {\pi_{{i_{1} ..}} - \pi_{ \ldots } } \right), \\{\varvec{\varPi}}_{{.{\varvec{i}}_{2} .}} = & \left( {\pi_{{.i_{2} .}} - \pi_{ \ldots } } \right),\quad{\varvec{\varPi}}_{{..{\varvec{i}}_{3} }} = \left( {\pi_{{..i_{3} }} - \pi_{ \ldots } } \right), \\{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} .}} = & \left( {\pi_{{i_{1} i_{2} .}} - \pi_{{i_{1} ..}} {-} \pi_{{.i_{2} .}} + \pi_{ \ldots } } \right),{\varvec{\varPi}}_{{.{\varvec{i}}_{2} {\varvec{i}}_{3} }} = \left( {\pi_{{.i_{2} i_{3} }} - \pi_{{.i_{2} .}} - \pi_{{..i_{3} }} + \pi_{...} } \right), \\{\varvec{\varPi}}_{{{\varvec{i}}_{1} .{\varvec{i}}_{3} }} = & \left( {\pi_{{i_{1} .i_{3} }} - \pi_{{i_{1} ..}} {-} \pi_{{..i_{3} }} + \pi_{ \ldots } } \right), \\ {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} }} = & \left( {\pi_{{i_{1} i_{2} i_{3} }} - \pi_{{i_{1} i_{2} .}} - \pi_{{i_{1} .i_{3} }} - \pi_{{.i_{2} i_{3} }} + \pi_{{i_{1} ..}} + \pi_{{.i_{2} .}} + \pi_{{..i_{3} }} - \pi_{...} } \right) \\ \end{aligned}$$

where \({\pi }_{...}=\sum_{{i}_{1},{i}_{2},{i}_{3}}{p}_{{i}_{1}..}{p}_{.{i}_{2}.}{p}_{..{i}_{3}}{\pi }_{{i}_{1}{i}_{2}{i}_{3}}\), \({\pi }_{{i}_{1}..}=\sum_{{i}_{2},{i}_{3}}{p}_{.{i}_{2}.}{p}_{..{i}_{3}}{\pi }_{{i}_{1}{i}_{2}{i}_{3}}\), \({\pi }_{{i}_{1}{i}_{2}.}=\sum_{{i}_{3}}{p}_{..{i}_{3}}{\pi }_{{i}_{1}{i}_{2}{i}_{3}}\) and so on.

Observe that \(\boldsymbol{\Pi }\) is the summation of these eight arrays where all the arrays are orthogonal to each other with respect to the previously defined inner product on \({\mathbb{R}}^{{j}_{1}\times {j}_{2}\times {j}_{3}}\). Furthermore, since, \({\boldsymbol{\Pi }}_{{{\varvec{i}}}_{1}..}={\boldsymbol{\Pi }}_{.{{\varvec{i}}}_{2}.}={\boldsymbol{\Pi }}_{..{{\varvec{i}}}_{3}}={\varvec{O}}\),

$${\varvec{\varPi}}={\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} .}} +{\varvec{\varPi}}_{{{\varvec{i}}_{1} .{\varvec{i}}_{3} }} +{\varvec{\varPi}}_{{.{\varvec{i}}_{2} {\varvec{i}}_{3} }} + {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} }}$$

In terms of relative frequencies, the components are,

$$\left( {\frac{{p_{{i_{1} i_{2} i_{3} }} - p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} }}{{p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} }}} \right) = \frac{{p_{{i_{1} i_{2} .}} - p_{{i_{1} ..}} p_{{.i_{2} .}} }}{{p_{{i_{1} ..}} p_{{.i_{2} .}} }} + \frac{{p_{{i_{1} .i_{3} }} - p_{{i_{1} ..}} p_{{..i_{3} }} }}{{p_{{i_{1} ..}} p_{{..i_{3} }} }} + \frac{{p_{{.i_{2} i_{3} }} - p_{{.i_{2} .}} p_{{..i_{3} }} }}{{p_{{.i_{2} .}} p_{{..i_{3} }} }} + \frac{{p_{{i_{1} i_{2} i_{3} }} - {}_{\alpha }^{{}} p_{{i_{1} i_{2} i_{3} }} }}{{p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} }},$$

where \({}_{\alpha }{p}_{{i}_{1}{i}_{2}{i}_{3}}={p}_{{i}_{1}{i}_{2}.}{p}_{..{i}_{3}}+{p}_{{i}_{1}.{i}_{3}}{p}_{.{i}_{2}.}+{p}_{.{i}_{2}{i}_{3}}{p}_{{i}_{1}..}-2{p}_{{i}_{1}..}{p}_{.{i}_{2}.}{p}_{..{i}_{3}}\).

The orthogonality of the arrays leads to an additive partition of the squared norm of \(\boldsymbol{\Pi }\) as,

$$\parallel{\varvec{\varPi}}\parallel^{2} =\parallel{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} .}}\parallel^{2} +\parallel{\varvec{\varPi}}_{{{\varvec{i}}_{1} .{\varvec{i}}_{3} }}\parallel^{2} +\parallel{\varvec{\varPi}}_{{.{\varvec{i}}_{2} {\varvec{i}}_{3} }}\parallel^{2} + \parallel{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} }}\parallel^{2} .$$
(1)

Carlier and Kroonenberg (1996) expressed the above partition in terms of the inertia of each pair of categorical variables, and all three variables, so that

$$\begin{aligned} {\Phi }^{2} = & \mathop \sum \limits_{{i_{1} ,i_{2} }} p_{{i_{1} ..}} p_{{.i_{2} .}} \left( {\frac{{p_{{i_{1} i_{2} .}} - p_{{i_{1} ..}} p_{{.i_{2} .}} }}{{p_{{i_{1} ..}} p_{{.i_{2} .}} }}} \right)^{2} + \mathop \sum \limits_{{i_{1} ,i_{3} }} p_{{i_{1} ..}} p_{{..i_{3} }} \left( {\frac{{p_{{i_{1} .i_{3} }} - p_{{i_{1} ..}} p_{{..i_{3} }} }}{{p_{{i_{1} ..}} p_{{..i_{3} }} }}} \right)^{2} \\ \quad & + \mathop \sum \limits_{{i_{2} ,i_{3} }} p_{{.i_{2} .}} p_{{..i_{3} }} \left( {\frac{{p_{{.i_{2} i_{3} }} - p_{{.i_{2} .}} p_{{..i_{3} }} }}{{p_{{.i_{2} .}} p_{{..i_{3} }} }}} \right)^{2} + \mathop \sum \limits_{{i_{1} ,i_{2} ,i_{3} }} p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} \left( {\frac{{p_{{i_{1} i_{2} i_{3} }} - {}_{\alpha }p_{{i_{1} i_{2} i_{3} }} }}{{p_{{i_{1} ..}} p_{{.i_{2} .}} p_{{..i_{3} }} }}} \right)^{2} . \\ \end{aligned}$$

Note that this partition involves only the marginal (univariate) proportions of the three-variables \({A}_{1},{A}_{2}\) and \({A}_{3}\) and the joint proportions of each pair of variables. Thus, the orthogonal decomposition of Pearson’s chi-squared statistic \({\chi }_{Total}^{2}=n{\Phi }^{2}\) for N is,

$${\chi }_{Total}^{2}={\chi }_{{A}_{1}{A}_{2}}^{2}+{\chi }_{{A}_{1}{A}_{3}}^{2}+{\chi }_{{A}_{2}{A}_{3}}^{2}+{\chi }_{{A}_{1}{A}_{2}{A}_{3}}^{2}$$

Here \({\chi }_{{A}_{1}{A}_{2}}^{2}\) is Pearson’s chi-squared statistic of the two-way contingency table formed from the cross-classification of variables \({A}_{1}\) and \({A}_{2}\) and is a measure of deviation from complete independence of the observed cell frequencies. Similarly, \({\chi }_{{A}_{1}{A}_{3}}^{2}\) and \({\chi }_{{A}_{2}{A}_{3}}^{2}\) are the two-variable chi-squared statistics of the tables formed by cross-classifying \({A}_{1}\) and \({A}_{3}\), and \({A}_{2}\) and \({A}_{3}\), respectively. The term \({\chi }_{{A}_{1}{A}_{2}{A}_{3}}^{2}\) is the Pearson’s chi-squared statistic that assesses the association between all three variables. Furthermore, the terms \({\chi }_{{A}_{1}{A}_{2}}^{2},{\chi }_{{A}_{1}{A}_{3}}^{2},{\chi }_{{A}_{2}{A}_{3}}^{2}, {\chi }_{{A}_{1}{A}_{2}{A}_{3}}^{2}\) are asymptotically chi-squared with \(\left({j}_{1}-1\right)\left({j}_{2}-1\right), \left({j}_{1}-1\right)\left({j}_{3}-1\right), ({j}_{2}-1)({j}_{3}-1)\) and \(({j}_{1}-1)({j}_{2}-1)({j}_{3}-1)\) degrees of freedom respectively. Furthermore, Carlier & Kroonenberg (1996) proposed the quantification of the global measure of dependence into four measures of dependence: the three measures for each pair-wise dependence and one measure for the three-way interaction. The following section provides a description of the ANOVA-like partition of Pearson’s chi-squared statistic for multi-way tables.

3 Partitioning Pearson’s Chi-Squared Statistic for a Multi-way Table

In this section, we provide an overview of the standard approach commonly used to partition Pearson’s chi-squared statistic. We do so by extending the additive decomposition given by Lancaster (1951) and used by Carlier and Kroonenberg (1996) to four-way and five-way tables; we note that these authors confined their attention to the analysis of a three-way contingency table. We also discuss the challenges involved in the partition of Pearson’s chi-squared statistic for multiple (more than five) categorical variables.

3.1 Partition for a Four-Way Contingency Table

Let \(n\) individuals be cross classified according to four categorical variables, \({A}_{1},{A}_{2},{A}_{3}\) and \({A}_{4}\). Let \({j}_{k}\) be the number of categories of the \({k}^{th}\) variable, for \(k=1, 2, 3, 4\) and the joint frequencies be summarized into a four-way contingency table \({\varvec{N}}=({n}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}})\) that is of dimension \({j}_{1}\times {j}_{2}\times {j}_{3}\times {j}_{4}.\) Let \({\varvec{P}}=\left({p}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}\right)\) be the table of relative proportions such that \({\varvec{P}}=\frac{1}{n}{\varvec{N}}\). The total inertia \({\Phi }^{2}\) is based on the deviation of the observations from what is expected under complete (four-way) independence such that,

$${\Phi }^{2} = \sum\limits_{{i_{1} ,i_{2} ,i_{3} ,i_{4} }} {\frac{{\left( {p_{{i_{1} i_{2} i_{3} i_{4} }} - p_{{i_{1} ...}} p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} } \right)^{2} }}{{p_{{i_{1} ...}} p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} }}}.$$

This statistic can be expressed as the weight squared norm of \(\boldsymbol{\Pi }\) in \({\mathbb{R}}^{{j}_{1}\times {j}_{2}\times {j}_{3}\times {j}_{4}}\) where \({\pi }_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}=\frac{{p}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}}{{p}_{{i}_{1}...}{p}_{.{i}_{2}..}{p}_{..{i}_{3}.}{p}_{\dots {i}_{4}}}-1\) and \({\Vert \boldsymbol{\Pi }\Vert }^{2}=\sum_{{i}_{1},{i}_{2},{i}_{3},{i}_{4}}{p}_{{i}_{1}...}{p}_{.{i}_{2}..}{p}_{..{i}_{3}.}{p}_{\dots {i}_{4}}{\left({\pi }_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}\right)}^{2}\); this is apparent since this case is a four-way extension of the three-way partition described in Sect. 2. In this case, \(\boldsymbol{\Pi }\) can be expressed as the addition of eleven orthogonal arrays that consist of 4C2 = 6 two-way, 4C3 = 4 three-way and 4C1 = 1 four-way association terms. That is

$$\begin{aligned}{\varvec{\varPi}}=\, &{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} ..}} +{\varvec{\varPi}}_{{{\varvec{i}}_{1} .{\varvec{i}}_{3} .}} +{\varvec{\varPi}}_{{{\varvec{i}}_{1} ..{\varvec{i}}_{4} }} +{\varvec{\varPi}}_{{.{\varvec{i}}_{2} {\varvec{i}}_{3} .}} +{\varvec{\varPi}}_{{.{\varvec{i}}_{2} .{\varvec{i}}_{4} }} +{\varvec{\varPi}}_{{..{\varvec{i}}_{3} {\varvec{i}}_{4} }} \\ \quad & + {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} }} . + {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} .{\varvec{i}}_{4} }} + {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{.{\varvec{i}}_{2} {\varvec{i}}_{3} {\varvec{i}}_{4} }} + {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} .{\varvec{i}}_{3} {\varvec{i}}_{4} }} + {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} {\varvec{i}}_{4} }} , \\ \end{aligned}$$

where

$$ \begin{aligned} \uppi _{{i_{1} i_{2} ..}} =\, & \frac{{p_{{i_{1} i_{2} ..}} - p_{{i_{1} \ldots }} p_{{.i_{2} ..}} }}{{p_{{i_{1} \ldots }} p_{{.i_{2} ..}} }},\;\uppi _{{i_{1} .i_{3} .}} = \frac{{p_{{i_{1} .i_{3} .}} - p_{{i_{1} \ldots }} p_{{..i_{3} .}} }}{{p_{{i_{1} \ldots }} p_{{..i_{3} .}} }},\;\uppi _{{i_{1} ..i_{4} }} = \frac{{p_{{i_{1} ..i_{4} }} - p_{{i_{1} \ldots }} p_{{...i_{4} }} }}{{p_{{i_{1} \ldots }} p_{{...i_{4} }} }}, \\ \uppi _{{.i_{2} i_{3} .}} =\, & \frac{{p_{{.i_{2} i_{3} .}} - p_{{.i_{2} ..}} p_{{..i_{3} .}} }}{{p_{{.i_{2} ..}} p_{{..i_{3} .}} }},\;\uppi _{{.i_{2} .i_{4} }} = \frac{{p_{{.i_{2} .i_{4} }} - p_{{.i_{2} ..}} p_{{...i_{4} }} }}{{p_{{.i_{2} ..}} p_{{...i_{4} }} }},\;\uppi _{{..i_{3} i_{4} }} = \frac{{p_{{..i_{3} i_{4} }} - p_{{..i_{3} .}} p_{{...i_{4} }} }}{{p_{{..i_{3} .}} p_{{...i_{4} }} }}, \\ {}_{\alpha }\pi _{{i_{1} i_{2} i_{3} .}} =\, & \frac{{p_{{i_{1} i_{2} i_{3} .}} - {}_{\alpha }^{{}} p_{{i_{1} i_{2} i_{3} .}} }}{{p_{{i_{1} \ldots }} p_{{.i_{2} ..}} p_{{..i_{3} .}} }},\;{}_{\alpha }\pi _{{i_{1} i_{2} .i_{4} }} = \frac{{p_{{i_{1} i_{2} .i_{4} }} - {}_{\alpha }p_{{i_{1} i_{2} .i_{4} }} }}{{p_{{i_{1} \ldots }} p_{{.i_{2} ..}} p_{{...i_{4} }} }},\;{}_{\alpha }\pi _{{.i_{2} i_{3} i_{4} }} = \frac{{p_{{.i_{2} i_{3} i_{4} }} - {}_{\alpha }p_{{.i_{2} i_{3} i_{4} }} }}{{p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{...i_{4} }} }}, \\ {}_{\alpha }\pi _{{i_{1} .i_{3} i_{4} }} =\, & \frac{{p_{{i_{1} .i_{3} i_{4} }} - {}_{\alpha }^{{}} p_{{i_{1} .i_{3} i_{4} }} }}{{p_{{i_{1} \ldots }} p_{{..i_{3} .}} p_{{...i_{4} }} }},\;{}_{\alpha }\pi _{{i_{1} i_{2} i_{3} i_{4} }} = \frac{{p_{{i_{1} i_{2} i_{3} i_{4} }} - {}_{\alpha }p_{{i_{1} i_{2} i_{3} i_{4} }} }}{{p_{{i_{1} \ldots }} p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{...i_{4} }} }}, \\ {}_{\alpha }p_{{i_{1} i_{2} i_{3} .}} =\, & p_{{i_{1} i_{2} ..}} p_{{..i_{3} .}} + p_{{i_{1} .i_{3} .}} p_{{.i_{2} ..}} + p_{{.i_{2} i_{3} .}} p_{{i_{1} ...}} - 2p_{{i_{1} ...}} p_{{.i_{2} ..}} p_{{..i_{3} .}} , \\ {}_{\alpha }p_{{i_{1} i_{2} .i_{4} }} =\, & p_{{i_{1} i_{2} ..}} p_{{ \ldots i_{4} }} + p_{{i_{1} ..i_{4} }} p_{{.i_{2} ..}} + p_{{.i_{2} .i_{4} }} p_{{i_{1} \ldots }} - 2p_{{i_{1} \ldots }} p_{{.i_{2} ..}} p_{{ \ldots i_{4} }} , \\ {}_{\alpha }p_{{.i_{2} i_{3} i_{4} }} =\, & p_{{.i_{2} i_{3} .}} p_{{...i_{4} }} + p_{{.i_{2} .i_{4} }} p_{{..i_{3} .}} + p_{{..i_{3} i_{4} }} p_{{.i_{2} ..}} - 2p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{...i_{4} }} , \\ {}_{\alpha }p_{{i_{1} .i_{3} i_{4} }} =\, & p_{{i_{1} .i_{3} .}} p_{{...i_{4} }} + p_{{i_{1} ..i_{4} }} p_{{..i_{3} .}} + p_{{..i_{3} i_{4} }} p_{{i_{1} ...}} - 2p_{{i_{1} ...}} p_{{..i_{3} .}} p_{{...i_{4} }} , \\ \end{aligned}$$
$$\begin{aligned} {}_{\alpha }p_{{i_{1} i_{2} i_{3} i_{4} }} =\, & p_{{i_{1} i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} + p_{{i_{1} .i_{3} .}} p_{{.i_{2} ..}} p_{{ \ldots i_{4} }} + p_{{i_{1} ..i_{4} }} p_{{.i_{2} ..}} p_{{..i_{3} .}} + p_{{.i_{2} i_{3} .}} p_{{i_{1} \ldots }} p_{{ \ldots i_{4} }} \\ \quad & + p_{{.i_{2} .i_{4} }} p_{{i_{1} \ldots }} p_{{..i_{3} .}} + p_{{..i_{3} i_{4} }} p_{{i_{1} \ldots }} p_{{.i_{2} ..}} + p_{{i_{1} i_{2} i_{3} .}} p_{{ \ldots i_{4} }} + p_{{i_{1} i_{2} .i_{4} }} p_{{..i_{3} .}} + p_{{.i_{2} i_{3} i_{4} }} p_{{i_{1} \ldots }} \\ \quad & + p_{{i_{1} .i_{3} i_{4} }} p_{{.i_{2} ..}} + 9p_{{i_{1} \ldots }} p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} \\ \end{aligned}$$
(2)

Thus, the additive partition of the squared norm of the four-way array \(\boldsymbol{\Pi }\) can be expressed as

$$\begin{aligned}{\parallel\varvec{\varPi}\parallel}^{2} =\, &{\parallel\varvec{\varPi}}_{{{\varvec{i}}_{1}{\varvec{i}}_{2}..}}\parallel^{2} +{\parallel\varvec{\varPi}}_{{{\varvec{i}}_{1} .{\varvec{i}}_{3} .}}\parallel^{2} +{\parallel\varvec{\varPi}}_{{{\varvec{i}}_{1} ..{\varvec{i}}_{4} }}\parallel^{2} +{\parallel\varvec{\varPi}}_{{.{\varvec{i}}_{2} {\varvec{i}}_{3} .}}\parallel^{2} +{\parallel\varvec{\varPi}}_{{.{\varvec{i}}_{2} .{\varvec{i}}_{4} }}\parallel^{2} +\\ \quad &{\parallel\varvec{\varPi}}_{{..{\varvec{i}}_{3} {\varvec{i}}_{4} }}\parallel^{2} + \parallel{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} }} .\parallel^{2} + \parallel{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} .{\varvec{i}}_{4} }}\parallel^{2} + \parallel{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{.{\varvec{i}}_{2} {\varvec{i}}_{3} {\varvec{i}}_{4} }}\parallel^{2} + \parallel{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} .{\varvec{i}}_{3} {\varvec{i}}_{4} }}\parallel^{2} + \parallel{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} {\varvec{i}}_{4} }}\parallel^{2} \\ \end{aligned}$$

This partition can be alternatively, but equivalently, expressed in terms of the table’s inertia such that,

$$\begin{aligned} {\Phi }^{2} =\, & \mathop \sum \limits_{{i_{1} ,i_{2} }} p_{{i_{1} ...}} p_{{.i_{2} ..}} \left( {\frac{{p_{{i_{1} i_{2} ..}} - p_{{i_{1} ...}} p_{{.i_{2} ..}} }}{{p_{{i_{1} ...}} p_{{.i_{2} ..}} }}} \right)^{2} + \mathop \sum \limits_{{i_{1} ,i_{3} }} p_{{i_{1} ...}} p_{{..i_{3} .}} \left( {\frac{{p_{{i_{1} .i_{3} .}} - p_{{i_{1} ...}} p_{{..i_{3} .}} }}{{p_{{i_{1} ...}} p_{{..i_{3} .}} }}} \right)^{2} \\ \quad & + \mathop \sum \limits_{{i_{2} ,i_{3} }} p_{{.i_{2} ..}} p_{{..i_{3} .}} \left( {\frac{{p_{{.i_{2} i_{3} .}} - p_{{.i_{2} ..}} p_{{..i_{3} .}} }}{{p_{{.i_{2} ..}} p_{{..i_{3} .}} }}} \right)^{2} + \mathop \sum \limits_{{i_{1} ,i_{2} ,i_{3} }} p_{{i_{1} ...}} p_{{.i_{2} ..}} p_{{..i_{3} .}} \left( {\frac{{p_{{i_{1} i_{2} i_{3} .}} - {}_{\alpha }^{{}} p_{{i_{1} i_{2} i_{3} .}} }}{{p_{{i_{1} ...}} p_{{.i_{2} ..}} p_{{..i_{3} .}} }}} \right)^{2} \\ \quad & + \mathop \sum \limits_{{i_{1} ,i_{2} ,i_{4} }} p_{{i_{1} ...}} p_{{.i_{2} ..}} p_{{ \ldots i_{4} }} \left( {\frac{{p_{{i_{1} i_{2} .i_{4} }} - {}_{\alpha }^{{}} p_{{i_{1} i_{2} .i_{4} }} }}{{p_{{i_{1} ...}} p_{{.i_{2} ..}} p_{{ \ldots i_{4} }} }}} \right)^{2} + \mathop \sum \limits_{{i_{2} ,i_{3} ,i_{4} }} p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} \left( {\frac{{p_{{.i_{2} i_{3} i_{4} }} - {}_{\alpha }^{{}} p_{{.i_{2} i_{3} i_{4} }} }}{{p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} }}} \right)^{2} \\ \quad & + \mathop \sum \limits_{{i_{1} ,i_{3} ,i_{4} }} p_{{i_{1.}..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} \left( {\frac{{p_{{i_{1} .i_{3} i_{4} }} - {}_{\alpha }^{{}} p_{{i_{1} .i_{3} i_{4} }} }}{{p_{{i_{1} ...}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} }}} \right)^{2} \\ \quad & + \mathop \sum \limits_{{i_{1} ,i_{2} ,i_{3} ,i_{4} }} p_{{i_{1}...}} p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} \left( {\frac{{p_{{i_{1} i_{2} i_{3} i_{4} }} - {}_{\alpha }^{{}} p_{{i_{1} i_{2} i_{3} i_{4} }} }}{{p_{{i_{1} \ldots }} p_{{.i_{2} ..}} p_{{..i_{3} .}} p_{{ \ldots i_{4} }} }}} \right)^{2} . \\ \end{aligned}$$

Thus, the orthogonal partition of \({\chi }_{Total}^{2}=n{\Phi }^{2}\) for the four-way contingency table N is

$$\begin{aligned} \chi_{Total}^{2} =\, & \chi_{{A_{1} A_{2} }}^{2} + \chi_{{A_{1} A_{3} }}^{2} + \chi_{{A_{1} A_{4} }}^{2} + \chi_{{A_{2} A_{3} }}^{2} + \chi_{{A_{2} A_{4} }}^{2} + \chi_{{A_{3} A_{4} }}^{2} \\ \quad & + \chi_{{A_{1} A_{2} A_{3} }}^{2} + \chi_{{A_{1} A_{2} A_{4} }}^{2} + \chi_{{A_{2} A_{3} A_{4} }}^{2} + \chi_{{A_{1} A_{3} A_{4} }}^{2} + \chi_{{A_{1} A_{2} A_{3} A_{4} }}^{2} \\ \end{aligned}$$
(3)

In general, the \({\chi }_{{A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{j}}}^{2}\) \((j\ge 2)\) term of the chi-squared partition quantifies the association between \({A}_{{i}_{1}}\), \({A}_{{i}_{2}}\), \(\dots\) and \({A}_{{i}_{j}}\) with \(\left({i}_{1}-1\right)\left({i}_{2}-1\right)\dots ({i}_{j}-1)\) degrees of freedom and can be used to test the statistical significance of the association between these variables. \({\chi }_{{A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{j}}}^{2}\) is the aggregate of deviation of \({A}_{{i}_{1}}\), \({A}_{{i}_{2}}\), \(\dots\) and \({A}_{{i}_{j}}\) from what is expected under complete independence. In fact, this association term involves information about the overall association in terms of the linear, quadratic and higher order components for each of the variables \({A}_{{i}_{1}}\), \({A}_{{i}_{2}}\), \(\dots\) and \({A}_{{i}_{j}}\) when these variables have ordered categories. Beh and Davy (1999) shows that the terms from the partition of the chi-squared statistic with df larger than 1 can be further partitioned into linear, quadratic and higher order components using orthogonal polynomials. While Beh and Davy (1999) describe the link between this chi-squared partition and the ordinal log-linear model for multi-way tables, the \({u}_{{i}_{1}{i}_{2}\dots {i}_{j}}\) term in such a model for a multi-way table reflects the \(linear\times linear\times \dots \times linear\) association term between the ordered categorical variables \({A}_{{i}_{1}}\), \({A}_{{i}_{2}}\), \(\dots\) and \({A}_{{i}_{j}}\) and it can be obtained by further partitioning \({\chi }_{{A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{j}}}^{2}\) using orthogonal polynomials.

3.2 Partition for a Five-Way Contingency Table

Consider a five-way contingency table formed by cross-classifying the five categorical variables, \({A}_{1},{A}_{2},{A}_{3},{A}_{4}\) and \({A}_{5}\). By following the same process described in Sect. 3.1, Pearson’s chi-squared statistic for such a table can be partitioned in 26 terms as follows:

$$\begin{aligned} \chi_{Total}^{2} =\, & \chi_{{A_{1} A_{2} }}^{2} + \chi_{{A_{1} A_{3} }}^{2} + \chi_{{A_{1} A_{4} }}^{2} + \chi_{{A_{1} A_{5} }}^{2} + \chi_{{A_{2} A_{3} }}^{2} + \chi_{{A_{2} A_{4} }}^{2} + \chi_{{A_{2} A_{5} }}^{2} + \chi_{{A_{3} A_{4} }}^{2} + \chi_{{A_{3} A_{5} }}^{2} + \chi_{{A_{4} A_{5} }}^{2} \\ \quad & + \chi_{{A_{1} A_{2} A_{3} }}^{2} + \chi_{{A_{1} A_{2} A_{4} }}^{2} + \chi_{{A_{1} A_{2} A_{5} }}^{2} + \chi_{{A_{1} A_{3} A_{4} }}^{2} + \chi_{{A_{1} A_{3} A_{5} }}^{2} + \chi_{{A_{1} A_{4} A_{5} }}^{2} + \chi_{{A_{2} A_{3} A_{4} }}^{2} \\ \quad & + \chi_{{A_{2} A_{3} A_{5} }}^{2} + \chi_{{A_{2} A_{4} A_{5} }}^{2} + \chi_{{A_{3} A_{4} A_{5} }}^{2} + \chi_{{A_{1} A_{2} A_{3} A_{4} }}^{2} + \chi_{{A_{1} A_{2} A_{3} A_{5} }}^{2} + \chi_{{A_{1} A_{2} A_{4} A_{5} }}^{2} \\ \quad & + \chi_{{A_{1} A_{3} A_{4} A_{5} }}^{2} + \chi_{{A_{2} A_{3} A_{4} A_{5} }}^{2} + \chi_{{A_{1} A_{2} A_{3} A_{4} A_{5} }}^{2} . \\ \end{aligned}$$
(4)

Each term of this partition can be used to test the statistical significance of the association between each pair, triplet and quartet of variables as well as all five ordinal variables. Observe that, of these 26 terms, \({}^{5}{C}_{2}\) = 10 terms correspond to two-way association, \({}^{5}{C}_{3}\) = 10 terms correspond to three-way association, \({}^{5}{C}_{4}=5\) terms correspond to the four-way association structures and one (\({}^{5}{C}_{5}\)) term reflects the association between all five variables. The formulae for each of these terms are given in the Appendix with a purpose of showing the complexity involved in the higher order terms.

The number of terms, and their calculation, dramatically increases as the number of variables cross-classified to form a contingency table increases; for \(k (>2)\) categorical variables, the partition of Pearson’s chi-squared statistic will consist of

$$\mathop \sum \limits_{l = 2}^{k} \left( {\begin{array}{*{20}c} k \\ l \\ \end{array} } \right) = 2^{k} - \left( {k + 1} \right)$$

terms. Therefore, for a six-way contingency table, the partition of its chi-squared statistic will consist of \({2}^{6}-\left(6+1\right)=57\) terms. In the next section, we present the general steps required to obtain the terms of the partition of the chi-squared statistic for a multi-way contingency table consisting of multiple (more than five) variables.

3.3 Partition for a Multi-way Contingency Table

Consider a sample of \(n\) individuals that is cross-classified according \(k\) categorical variables, \({A}_{1}\), \({A}_{2}\), \(\dots\) and \({A}_{k}\) where the \({r}^{th}\) variable consists of \({j}_{r}\) categories, for \(r=\mathrm{1,2},\dots ,k\). Consider the following notations:

  • \(S=\left\{\mathrm{1,2},\dots ,k\right\}\)

  • \({\underline{i}}_{k}=({i}_{1}{i}_{2}\dots {i}_{k})\), where \({i}_{1},{i}_{2},\dots ,{i}_{k}\in S\), is referred to as a \(k\)-tuple.

  • \({S}_{r}=\left\{{\underline{i}}_{r}={i}_{1}{i}_{2}\dots {i}_{r}\left|{i}_{1}<{i}_{2}<\dots {<i}_{r}\right.,{i}_{r}\in S\right\}\) is a set of strictly increasing \(r\)-tuples \(r\)= 2, 3,\(\dots\),\(k\) (\(S_r\) contains \(^kC_r\) tuples).

  • \({A}_{{\underline{i}}_{r}}={A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{r}}\) is referred to as an \(r\)-variable association term, \({\underline{i}}_{r}\in {S}_{r}\).

  • \({n}_{{\underline{i}}_{k}}\) defines the number of individuals corresponding to \({\underline{i}}_{k}^{th}\) category of variables \(\left\{{A}_{{i}_{1}},{A}_{{i}_{2}},\dots ,{A}_{{i}_{k}}\right\}\).

  • \({p}_{{\underline{i}}_{k}}=\frac{{n}_{{\underline{i}}_{k}}}{n}\) denotes the relative frequency of the \({\underline{i}}_{k}^{th}\) category of the set of variables \(\left\{{A}_{{i}_{1}},{A}_{{i}_{2}},\dots ,{A}_{{i}_{k}}\right\}\)

  • \({p}_{{i}_{r}}^{r}={\sum }_{{i}_{s}:s\in S-\left\{r\right\}}{p}_{\underline{i}}\) is the observed marginal relative frequency of the \({i}_{r}^{th}\) category of \({A}_{r}\), for \({i}_{r}=\mathrm{1,2},\dots ,{j}_{r}\), and \(r=\mathrm{1,2},\dots ,k\).

  • \({p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}}^{{r}_{1}{r}_{2}}={\sum }_{{i}_{s}:s\in S-\{{r}_{1},{r}_{2}\}}{p}_{{\underline{i}}_{k}}\) is the observed joint relative frequency of the two variables \({A}_{{r}_{1}}\) and \({A}_{{r}_{2}}\) for \({i}_{{r}_{1}}=\mathrm{1,2},\dots ,{j}_{{r}_{1}}\) and \({i}_{{r}_{2}}=\mathrm{1,2},\dots ,{j}_{{r}_{2}}\). (This notation can be extended to represent observed joint relative frequency of more than two variables)

Now, the \(k\)-way array \(\boldsymbol{\Pi }=({\pi }_{{\underline{i}}_{k}})\) with \({\pi }_{{\underline{i}}_{k}}=\frac{{p}_{{\underline{i}}_{k}}-{\prod }_{r=1}^{k}{p}_{{i}_{r}}^{r}}{{\prod }_{r=1}^{k}{p}_{{i}_{r}}^{r}}\) can be partitioned into weighted orthogonal components such that

$${\varvec{\varPi}}= \mathop \sum \limits_{{\varvec{\underline {i} }_{2} \in {\varvec{S}}_{2} }}{\varvec{\varPi}}_{{\varvec{\underline {i} }_{2} }} + \mathop \sum \limits_{{\varvec{\underline {i} }_{3} \in {\varvec{S}}_{3} }} {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{\varvec{\underline {i} }_{3} }} + \cdots + \mathop \sum \limits_{{\varvec{\underline {i} }_{{{\varvec{k}} - 1}} \in {\varvec{S}}_{{{\varvec{k}} - 1}} }} {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{\varvec{\underline {i} }_{{{\varvec{k}} - 1}} }} + {}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{\varvec{\underline {i} }_{{\varvec{k}}} }}$$
(5)

where \({\boldsymbol{\Pi }}_{{\underline{i}}_{2}}=({\pi }_{{\underline{i}}_{2}})\), \({}_{\boldsymbol{\alpha }}{\boldsymbol{\Pi }}_{{\underline{i}}_{3}}=({}_{\alpha }{\pi }_{{\underline{i}}_{3}})\), …, \({}_{\boldsymbol{\alpha }}{\boldsymbol{\Pi }}_{{\underline{i}}_{k}}=({}_{\alpha }{\pi }_{{\underline{i}}_{k}})\), \({\pi }_{{i}_{{r}_{1}}{i}_{{r}_{2}}}=\left(\frac{{p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}}^{{r}_{1}{r}_{2}}-{p}_{{i}_{{r}_{1}}}^{{r}_{1}}{p}_{{i}_{{r}_{2}}}^{{r}_{2}}}{{p}_{{i}_{{r}_{1}}}^{{r}_{1}}{p}_{{i}_{{r}_{2}}}^{{r}_{2}}}\right)\), for \(({i}_{{r}_{1}}{i}_{{r}_{2}})\in {S}_{2}\), \({}_{\alpha }{\pi }_{{i}_{{r}_{1}}{i}_{{r}_{2}}{i}_{{r}_{3}}}=\left(\frac{{p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}{i}_{{r}_{3}}}^{{r}_{1}{r}_{2}{r}_{3}}-{}_{\alpha }{p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}{i}_{{r}_{3}}}^{{r}_{1}{r}_{2}{r}_{3}} }{{p}_{{i}_{{r}_{1}}}^{{r}_{1}}{p}_{{i}_{{r}_{2}}}^{{r}_{2}}{p}_{{i}_{{r}_{3}}}^{{r}_{3}}}\right)\) for \(({i}_{{r}_{1}}{i}_{{r}_{2}}{i}_{{r}_{3}})\in {S}_{3}\) and so on.

In general,

$${}_{\alpha }\pi_{{\underline {i}_{j} }} = \left( {\frac{{p_{{\underline {i}_{j} }}^{{\underline {r}_{j} }} - {}_{\alpha }p_{{\underline {i}_{j} }}^{{\underline {r}_{j} }} }}{{\mathop \prod \nolimits_{u = 1}^{j} p_{{i_{{r_{u} }} }}^{{r_{u} }} }}} \right),\;\underline {i}_{j} = \left( {i_{{r_{1} }} i_{{r_{2} }} \ldots i_{{r_{j} }} } \right) \in S_{j} ,j = 3,4, \ldots ,k$$

The weighted norm of \({\boldsymbol{\Pi }}_{{\underline{i}}_{2}}\) is the inertia corresponding to the two-way association terms of \({A}_{{\underline{i}}_{2}}, {\underline{i}}_{2}\in {S}_{2}\) while the weighted norm of \({}_{\boldsymbol{\alpha }}{\boldsymbol{\Pi }}_{{\underline{i}}_{3}}\) is the inertia corresponding to three-way association terms of \({A}_{{\underline{i}}_{3}}, {\underline{i}}_{3}\in {S}_{3}\). We refer to the above method as the traditional method. We demonstrate the complexity in this method through the stepwise algorithm for partitioning the chi-squared statistic for four-way table. This will also help to make the notations more familiar.

Let \({\varvec{N}}=({n}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}})\) and \({p}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}={n}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}/n\) be a \({j}_{1}\times {j}_{2}\times {j}_{3}\times {j}_{4}\) contingency table and array of relative frequencies, respectively. Here \(S=\left\{\mathrm{1,2},\mathrm{3,4}\right\}\) and \({S}_{2},{S}_{3},{S}_{4}\) represent the set of tuples corresponding to two-way, three-way and four-way association terms respectively:

  • \({S}_{2}=\left\{{i}_{1}{i}_{2}, {i}_{1}{i}_{3},{i}_{1}{i}_{4},{i}_{2}{i}_{3},{i}_{2}{i}_{4},{i}_{3}{i}_{4}\right\}\) corresponds to \(\left\{{A}_{1}{A}_{2}, {A}_{1}{A}_{3},{A}_{1}{A}_{4},{A}_{2}{A}_{3},{A}_{2}{A}_{4},{A}_{3}{A}_{4}\right\}\)

  • \({S}_{3}=\left\{{i}_{1}{i}_{2}{i}_{3}, {i}_{1}{i}_{2}{i}_{4}, {i}_{1}{i}_{3}{i}_{4}, {i}_{2}{i}_{3}{i}_{4}\right\}\) corresponds to \(\left\{{A}_{1}{A}_{2}{A}_{3}, {A}_{1}{A}_{2}{A}_{4}, {A}_{1}{A}_{3}{A}_{4}, {A}_{2}{A}_{3}{A}_{4}\right\}\)

  • \({S}_{4}=\left\{{\underline{i}}_{4}={i}_{1}{i}_{2}{i}_{3}{i}_{4}\right\}\) corresponds to \(\left\{{A}_{1}{A}_{2}{A}_{3}{A}_{4}\right\}\)

The marginal relative frequencies for \({A}_{1},{A}_{2},{A}_{3}\) and \({A}_{4}\) are,

$$\begin{gathered} p_{{i_{1} }}^{1} = p_{{i_{1} \ldots }} , i_{1} = 1,2, \ldots ,j_{1} \quad p_{{i_{2} }}^{2} = p_{{.i_{2} ..}} ,i_{2} = 1,2, \ldots ,j_{2} \hfill \\ p_{{i_{3} }}^{3} = p_{{..i_{3} .}} , i_{3} = 1,2, \ldots ,j_{3} \quad p_{{i_{4} }}^{4} = p_{{ \ldots i_{4} }} , i_{4} = 1,2, \ldots ,j_{4} . \hfill \\ \end{gathered}$$

The marginal relative frequencies for all pairs of variables are,

$$\begin{array}{*{20}l} {p_{{i_{1} i_{2} }}^{12} = p_{{i_{1} i_{2} ..}} , \quad i_{1} = 1,2, \ldots ,j_{1} ,\; i_{2} = 1,2, \ldots ,j_{2} ,} \hfill \\ {p_{{i_{1} i_{3} }}^{13} = p_{{i_{1} .i_{3} .}} , \quad i_{1} = 1,2, \ldots ,j_{1} ,\; i_{3} = 1,2, \ldots ,j_{3} ,} \hfill \\ \cdots \hfill \\ {p_{{i_{3} i_{4} }}^{34} = p_{{..i_{3} i_{4} }} ,\quad i_{3} = 1,2, \ldots ,j_{3} ,\; i_{4} = 1,2, \ldots ,j_{4} ,} \hfill \\ \end{array}$$

The marginal relative frequencies for all triplets of variables are

$$\begin{array}{*{20}l} {p_{{i_{1} i_{2} i_{3} }}^{123} = p_{{i_{1} i_{2} i_{3} .}} ,\quad i_{1} = 1,2, \ldots ,j_{1} ,\;i_{2} = 1,2, \ldots ,j_{2} ,\;i_{3} = 1,2, \ldots ,j_{3} ,} \hfill \\ {p_{{i_{1} i_{2} i_{4} }}^{124} = p_{{i_{1} i_{2} .i_{4} }} ,\quad i_{1} = 1,2, \ldots ,j_{1} ,\; i_{2} = 1,2, \ldots ,j_{2} ,\;i_{4} = 1,2, \ldots ,j_{4} ,} \hfill \\ \cdots \hfill \\ {p_{{i_{2} i_{3} i_{4} }}^{234} = p_{{.i_{2} i_{3} i_{4} }} ,\quad i_{2} = 1,2, \ldots ,j_{2} , \;i_{3} = 1,2, \ldots ,j_{3} ,\; i_{4} = 1,2, \ldots ,j_{4} ,} \hfill \\ \end{array}$$

The steps to obtain the partition of Pearson’s chi-squared statistic using traditional method are:

  1. (i)

    Calculate the \({j}_{1}\times {j}_{2}\times {j}_{3}\times {j}_{4}\) array \(\boldsymbol{\Pi }=({\pi }_{{\underline{i}}_{4}})\) where \({\pi }_{{\underline{i}}_{4}}=\frac{{p}_{{\underline{i}}_{4}}}{{p}_{{i}_{1}}^{1}{p}_{{i}_{2}}^{2}{p}_{{i}_{3}}^{3}{p}_{{i}_{4}}^{4}}-1\).

  1. (ii)

    Calculate the 4-way arrays \({\boldsymbol{\Pi }}_{{\underline{i}}_{2}}\) for \({\underline{i}}_{2}\in {S}_{2}\) as follows:

$$\begin{gathered} \left( {{\varvec{\varPi}}_{{i_{1} i_{2} }} } \right)_{{\underline {i}_{4} }} =\, \frac{{p_{{i_{1} i_{2} }}^{12} }}{{p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} }} - 1,\quad \left( {{\varvec{\varPi}}_{{i_{1} i_{3} }} } \right)_{{\underline {i}_{4} }} =\, \frac{{p_{{i_{1} i_{3} }}^{13} }}{{p_{{i_{1} }}^{1} p_{{i_{3} }}^{3} }} - 1, \ldots \hfill \\ \left( {{\varvec{\varPi}}_{{i_{3} i_{4} }} } \right)_{{\underline {i}_{4} }} =\, \frac{{p_{{i_{3} i_{4} }}^{34} }}{{p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} }} - 1,\quad i_{r} =\, 1,2, \ldots ,j_{r} ,\;r = 1,2, \ldots ,4. \hfill \\ \end{gathered}$$
  1. (iii)

    Calculate the 4-way arrays \({{}_{\boldsymbol{\alpha }}\boldsymbol{\Pi }}_{{\underline{i}}_{3}}\) for \({\underline{i}}_{3}\in {S}_{3}\) as follows:

$$\begin{array}{*{20}l} {\left( {{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{i_{1} i_{2} i_{3} }} } \right)_{{\underline {i}_{4} }} = \frac{{p_{{i_{1} i_{2} i_{3} }}^{123} - {}_{\alpha }^{{}} p_{{i_{1} i_{2} i_{3} }}^{123} }}{{p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} }},\;\left( {{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{i_{1} i_{2} i_{4} }} } \right)_{{\underline {i}_{4} }} = \frac{{p_{{i_{1} i_{2} i_{4} }}^{124} - {}_{\alpha }p_{{i_{1} i_{2} i_{4} }}^{124} }}{{p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{4} }}^{4} }},} \hfill \\ \cdots \hfill \\ {\left( {{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{i_{2} i_{3} i_{4} }} } \right)_{{\underline {i}_{4} }} = \frac{{p_{{i_{2} i_{3} i_{4} }}^{234} - {}_{\alpha }^{{}} p_{{i_{2} i_{3} i_{4} }}^{234} }}{{p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} }},\;i_{r} = 1,2, \ldots ,j_{r} ,\;r = 1,2, \ldots ,4.} \hfill \\ \end{array}$$
$$\begin{aligned} {\text{where}}\quad {}_{\alpha }p_{{i_{1} i_{2} i_{3} }}^{123} = & p_{{i_{1} i_{2} }}^{12} p_{{i_{3} }}^{3} + p_{{i_{1} i_{3} }}^{13} p_{{i_{2} }}^{2} + p_{{i_{2} i_{3} }}^{23} p_{{i_{1} }}^{1} - 2p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} , \\ {}_{\alpha }p_{{i_{1} i_{2} i_{4} }}^{124} = & p_{{i_{1} i_{2} }}^{12} p_{{i_{4} }}^{4} + p_{{i_{1} i_{4} }}^{14} p_{{i_{2} }}^{2} + p_{{i_{2} i_{4} }}^{24} p_{{i_{1} }}^{1} - 2p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{4} }}^{4} , \\ {}_{\alpha }p_{{i_{2} i_{3} i_{4} }}^{234} = & p_{{i_{2} i_{3} }}^{23} p_{{i_{4} }}^{4} + p_{{i_{2} i_{4} }}^{24} p_{{i_{3} }}^{3} + p_{{i_{3} i_{4} }}^{34} p_{{i_{2} }}^{2} - 2p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} , \\ {}_{\alpha }p_{{i_{1} i_{3} i_{4} }}^{134} = & p_{{i_{1} i_{3} }}^{13} p_{{i_{4} }}^{4} + p_{{i_{1} i_{4} }}^{14} p_{{i_{3} }}^{3} + p_{{i_{3} i_{4} }}^{34} p_{{i_{1} }}^{1} - 2p_{{i_{1} }}^{1} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} . \\ \end{aligned}$$
  1. (iv)

    Calculate the 4-way array \({{}_{\boldsymbol{\alpha }}\boldsymbol{\Pi }}_{{\underline{i}}_{4}}\) for \({\underline{i}}_{4}\in {S}_{4}\) as follows:

$$\begin{aligned} \left( {{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{i_{1} i_{2} i_{3} i_{4} }} } \right)_{{\underline {i}_{4} }} = & \frac{{p_{{\underline {i}_{4} }} - {}_{\alpha }p_{{i_{1} i_{2} i_{3} i_{4} }}^{1234} }}{{p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} }}, \\ {\text{where}}\quad {}_{\alpha }p_{{i_{1} i_{2} i_{3} i_{4} }}^{1234} = & p_{{i_{1} i_{2} }}^{12} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} + p_{{i_{1} i_{3} }}^{13} p_{{i_{2} }}^{2} p_{{i_{4} }}^{4} + p_{{i_{1} i_{4} }}^{14} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} + p_{{i_{2} i_{3} }}^{23} p_{{i_{1} }}^{1} p_{{i_{4} }}^{4} \\ \quad & + p_{{i_{2} i_{4} }}^{24} p_{{i_{1} }}^{1} p_{{i_{3} }}^{3} + p_{{i_{3} i_{4} }}^{34} p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} + p_{{i_{1} i_{2} i_{3} }}^{123} p_{{i_{4} }}^{4} + p_{{i_{1} i_{2} i_{4} }}^{124} p_{{i_{3} }}^{3} \\ \quad & + p_{{i_{2} i_{3} i_{4} }}^{234} p_{{i_{1} }}^{1} + p_{{i_{1} i_{3} i_{4} }}^{134} p_{{i_{2} }}^{2} + 9p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} . \\ \end{aligned}$$
  1. (xxii)

    Calculate the chi-squared partition as follows:

$$\begin{gathered} \chi_{Total}^{2} = n{\left\|\varvec{\varPi}\right\|}^{2} = n\mathop \sum \limits_{{\underline {i}_{4} }} p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4}{\varvec{\varPi}}_{{\underline {i}_{4} }}^{2} , \hfill \\ \chi_{{A_{1} A_{2} }}^{2} = n\left\|{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2}}}\right\|^{2} = n\mathop \sum \limits_{{\underline {i}_{4} }} p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} \left( {{\varvec{\varPi}}_{{i_{1} i_{2} }} } \right)_{{\underline {i}_{4} }}^{2} , \hfill \\ \chi_{{A_{1} A_{3} }}^{2} = n\left\|{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{3} }}\right\|^{2} = n\mathop \sum \limits_{{\underline {i}_{4} }} p_{{i_{1} }}^{1} p_{{i_{3} }}^{3} \left( {{\varvec{\varPi}}_{{i_{1} i_{3} }} } \right)_{{\underline {i}_{4} }}^{2} , \ldots \hfill \\ \chi_{{A_{3} A_{4} }}^{2} = n\left\|{\varvec{\varPi}}_{{{\varvec{i}}_{3} {\varvec{i}}_{4} }}\right\|^{2} = n\mathop \sum \limits_{{\underline {i}_{4} }} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} \left( {{\varvec{\varPi}}_{{i_{3} i_{4} }} } \right)_{{\underline {i}_{4} }}^{2} , \hfill \\ \chi_{{A_{1} A_{2} A_{3} }}^{2} = n\left\|{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} }}\right\|^{2} = n\mathop \sum \limits_{{\underline {i}_{4} }} p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} \left( {{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} }} } \right)_{{\underline {i}_{4} }}^{2} , \hfill \\ \cdots \hfill \\ \chi_{{A_{1} A_{3} A_{4} }}^{2} = n\left\|{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{3} {\varvec{i}}_{4} }}\right\|^{2} = n\mathop \sum \limits_{{\underline {i}_{4} }} p_{{i_{1} }}^{1} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} \left( {{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{3} {\varvec{i}}_{4} }} } \right)_{{\underline {i}_{4} }}^{2} \hfill \\ {\text{and}}\;\chi_{{A_{1} A_{2} A_{3} A_{4} }}^{2} = n\left\|{}_{{\varvec{\alpha}}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} {\varvec{i}}_{4} }}\right\|^{2} = n\mathop \sum \limits_{{\underline {i}_{4} }} p_{{i_{1} }}^{1} p_{{i_{2} }}^{2} p_{{i_{3} }}^{3} p_{{i_{4} }}^{4} \left( {{}_{{\varvec{\alpha}}}^{{}}{\varvec{\varPi}}_{{{\varvec{i}}_{1} {\varvec{i}}_{2} {\varvec{i}}_{3} {\varvec{i}}_{4} }} } \right)_{{\underline {i}_{4} }}^{2} . \hfill \\ \end{gathered}$$

Observe that the term \({p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}{i}_{{r}_{3}}}^{{r}_{1}{r}_{2}{r}_{3}}\) in \({}_{\alpha }{\pi }_{{i}_{{r}_{1}}{i}_{{r}_{2}}{i}_{{r}_{3}}}\) is simply a marginal of relative frequencies while \({}_{\alpha }{p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}{i}_{{r}_{3}}}^{{r}_{1}{r}_{2}{r}_{3}}\) is a function of all univariate and bivariate marginals. In general, the term \({}_{\alpha }{p}_{{\underline{i}}_{r}}^{{\underline{r}}_{j}}={}_{\alpha }{p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}\dots {i}_{{r}_{j}}}^{{r}_{1}{r}_{2}\dots {r}_{j}}\) in \({}_{\alpha }{\pi }_{{\underline{i}}_{j}}={}_{\alpha }{\pi }_{{i}_{{r}_{1}}{i}_{{r}_{2}}\dots {i}_{{r}_{j}}}\) is based on the sum-of-products of \(j\) univariate, \({}^{j}{C}_{2}\) bivariate up to \({}^{j}{C}_{j-1}\) \((j-1)\)-variate marginal proportions. The explicit form of \({}_{\alpha }{p}_{{\underline{i}}_{r}}^{{\underline{r}}_{j}}\) for \(j\ge 6\) will be far more complex; this is apparent by just observing the case where \(j=4, 5\). A natural question then arises – if one is not able to formulate an expression for \({}_{\alpha }{p}_{{\underline{i}}_{r}}^{{\underline{r}}_{j}}\) for \(j\ge 6\) then how can one quantify the terms and implement the calculation of the partition using software? Another issue is the rapidly increasing number of association terms as the number of categorical variables increases. The partitioning of Pearson’s chi-squared statistic for a multi-way table is theoretically and computationally challenging by the method described above. Section 4 will present a new algorithm for dealing with this complexity.

4 A New Algorithm for Partitioning Pearson Chi-squared Statistic

In this section, we present a new and efficient method of partitioning Pearson’s chi-squared statistic for multi-way tables which overcomes the theoretical complexities and simplifies the computational difficulties described in Sect. 3. The proposed method gives all components of the partition without the need to evaluate the terms of \({}_{\alpha }{p}_{{\underline{i}}_{r}}^{{\underline{r}}_{j}}\) for \(j\ge 3\). We describe this method for a four-way table and demonstrate how it can be extended to multi-way tables formed from the cross-classification of at least five categorical variables. We present the terms of the partition in the form of categorical ANOVA and show that they can be used for testing the significance of association.

4.1 An Algorithm for a Four-Way Contingency Table

Evaluating the terms of the partition of Pearson’s chi-squared statistic for a four-way contingency table involves calculating all 3-way and 4-way association terms of\({}_{\alpha }{p}_{{i}_{1}{i}_{2}{i}_{3}}. , {}_{\alpha }{p}_{{i}_{1}{i}_{2}.{i}_{4}} , {}_{\alpha }{p}_{.{i}_{2}{i}_{3}{i}_{4}} , {}_{\alpha }{p}_{{i}_{1}.{i}_{3}{i}_{4}} , {}_{\alpha }{p}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}\). These terms are functions of the marginal relative frequencies of all univariate, bivariate and trivariate subsets of categorical variables. The calculation of the relative marginal proportions for a given set of variables is a feasible task. However, the calculation of the \({}_{\alpha }p{\prime}s\) is computationally intractable nor is there a mathematical link between \({}_{\alpha }{p}_{{i}_{1}{i}_{2}{i}_{3}}. , {}_{\alpha }{p}_{{i}_{1}{i}_{2}.{i}_{4}} , {}_{\alpha }{p}_{.{i}_{2}{i}_{3}{i}_{4}} , {}_{\alpha }{p}_{{i}_{1}.{i}_{3}{i}_{4}}\) and\({}_{\alpha }{p}_{{i}_{1}{i}_{2}{i}_{3}{i}_{4}}\). We now present an algorithm that will provide an easy and fast means of calculating these terms, thereby providing a more efficient way of partitioning Pearson’s chi-squared statistic.

Calculate the total inertia \({\chi }_{Total}^{2}\) for a four-way contingency table as

$$\chi_{{T,A_{1} A_{2} A_{3} A_{4} }}^{2} = n\mathop \sum \limits_{{i_{1} ,i_{2} ,i_{3} ,i_{4} }}^{{}} \frac{{\left( {p_{{i_{1} i_{2} i_{3} i_{4} }} - \mathop \prod \nolimits_{j = 1}^{4} p_{{i_{j} }}^{j} } \right)^{2} }}{{\mathop \prod \nolimits_{j = 1}^{4} p_{{i_{j} }}^{j} }}.$$

Calculate the inertia values corresponding to all of the two-way association terms \({\chi }_{{A}_{1}{A}_{2}}^{2},{\chi }_{{A}_{1}{A}_{3}}^{2}, {\chi }_{{A}_{1}{A}_{4}}^{2},\) \({\chi }_{{A}_{2}{A}_{3}}^{2},{\chi }_{{A}_{2}{A}_{4}}^{2}\) and \({\chi }_{{A}_{3}{A}_{4}}^{2}\) of the partition using

$$\chi_{{A_{{r_{1} }} A_{{r_{2} }} }}^{2} = n\mathop \sum \limits_{{i_{{r_{1} }} ,i_{{r_{2} }} }}^{{}} \frac{{\left( {p_{{i_{{r_{1} }} i_{{r_{2} }} }}^{{r_{1} r_{2} }} - p_{{i_{{r_{1} }} }}^{{r_{1} }} p_{{i_{{r_{2} }} }}^{{r_{2} }} } \right)^{2} }}{{p_{{i_{{r_{1} }} }}^{{r_{1} }} p_{{i_{{r_{2} }} }}^{{r_{2} }} }},\;\left( {r_{1} , r_{2} } \right) \in S_{2} ;$$
  • Rather than calculating \({}_{\alpha }{p}_{{i}_{1}{i}_{2}{i}_{3}.},{}_{\alpha }{p}_{{i}_{1}{i}_{2}.{i}_{4}}\),\({}_{\alpha }{p}_{.{i}_{2}{i}_{3}{i}_{4}}\) and \({}_{\alpha }{p}_{{i}_{1}.{i}_{3}{i}_{4}}\) when computing \({\chi }_{{A}_{1}{A}_{2}{A}_{3}}^{2},{\chi }_{{A}_{1}{A}_{2}{A}_{4}}^{2},{\chi }_{{A}_{2}{A}_{3}{A}_{4}}^{2}\) and \({\chi }_{{A}_{1}{A}_{3}{A}_{4}}^{2}\), calculate the total inertia values \({\chi }_{T,{A}_{1}{A}_{2}{A}_{3}}^{2}\), \({\chi }_{T,{A}_{2}{A}_{3}{A}_{4}}^{2}\), \({\chi }_{T,{A}_{1}{A}_{3}{A}_{4}}^{2}\) and \({\chi }_{T,{A}_{1}{A}_{2}{A}_{4}}^{2}\) corresponding to all of the three-way association terms where \({\chi }_{T,{A}_{1}{A}_{2}{A}_{3}}^{2}=n\sum_{{i}_{1},{i}_{2},{i}_{3}}\frac{{\left({p}_{{i}_{1}{i}_{2}{i}_{3}.}-{p}_{{i}_{1}}^{1}{p}_{{i}_{2}}^{2}{p}_{{i}_{3}}^{3}\right)}^{2}}{{p}_{{i}_{1}}^{1}{p}_{{i}_{2}}^{2}{p}_{{i}_{3}}^{3}}\), \({\chi }_{T,{A}_{2}{A}_{3}{A}_{4}}^{2}=n\sum_{{i}_{2},{i}_{3},{i}_{4}}\frac{{\left({p}_{.{i}_{2}{i}_{3}{i}_{4}}-{p}_{{i}_{2}}^{2}{p}_{{i}_{3}}^{3}{p}_{{i}_{4}}^{4}\right)}^{2}}{{p}_{{i}_{2}}^{2}{p}_{{i}_{3}}^{3}{p}_{{i}_{4}}^{4}}\) and so on.

  • Now calculate the inertia values corresponding to all the three-way association terms using

    $$\begin{aligned} \chi_{{A_{1} A_{2} A_{3} }}^{2} =\, & \chi_{{T,A_{1} A_{2} A_{3} }}^{2} - \chi_{{A_{1} A_{2} }}^{2} - \chi_{{A_{1} A_{3} }}^{2} - \chi_{{A_{2} A_{3} }}^{2} , \\ \chi_{{A_{2} A_{3} A_{4} }}^{2} =\, & \chi_{{T,A_{2} A_{3} A_{4} }}^{2} - \chi_{{A_{2} A_{3} }}^{2} - \chi_{{A_{2} A_{4} }}^{2} - \chi_{{A_{3} A_{4} }}^{2} , \\ \chi_{{A_{1} A_{3} A_{4} }}^{2} =\, & \chi_{{T,A_{1} A_{3} A_{4} }}^{2} - \chi_{{A_{1} A_{3} }}^{2} - \chi_{{A_{1} A_{4} }}^{2} - \chi_{{A_{3} A_{4} }}^{2} , \\ \chi_{{A_{1} A_{2} A_{4} }}^{2} =\, & \chi_{{T,A_{1} A_{2} A_{4} }}^{2} - \chi_{{A_{1} A_{2} }}^{2} - \chi_{{A_{1} A_{4} }}^{2} - \chi_{{A_{2} A_{4} }}^{2} . \\ \end{aligned}$$
  • Calculate the total inertia corresponding to the four-way association term as,

$$\begin{aligned} \chi_{{A_{1} A_{2} A_{3} A_{4} }}^{2} =\, & \chi_{{T,A_{1} A_{2} A_{3} A_{4} }}^{2} - \left( {\chi_{{A_{1} A_{2} A_{3} }}^{2} + \chi_{{A_{1} A_{2} A_{4} }}^{2} + \chi_{{A_{2} A_{3} A_{4} }}^{2} + \chi_{{A_{1} A_{3} A_{4} }}^{2} } \right) \\ \quad & - \left( {\chi_{{A_{1} A_{2} }}^{2} + \chi_{{A_{1} A_{3} }}^{2} + \chi_{{A_{1} A_{4} }}^{2} + \chi_{{A_{2} A_{3} }}^{2} + \chi_{{A_{2} A_{4} }}^{2} + \chi_{{A_{3} A_{4} }}^{2} } \right) \\ \end{aligned}$$

This algorithm avoids the complexity in the evaluation of the chi-squared partition. We now present the structure of the algorithm for a multi-way contingency table.

4.2 An Algorithm for a Multi-way Contingency Table

Suppose we now consider a \(k\)-way contingency table formed from the cross-classification of the categorical variables\({A}_{1},{A}_{2}, . . . ,{A}_{k}\). An ANOVA-like partition of the chi-squared statistic for such a table is given as follows:

  1. (i)

    Calculate Pearson’s chi-squared statistic \({\chi }_{T}^{2}=n{\Phi }^{2}\) where \({\Phi }^{2}=\sum_{{\underline{i}}_{k}}\frac{{\left({p}_{{\underline{i}}_{k}}-\prod_{j=1}^{k}{p}_{{i}_{j}}^{j}\right)}^{2}}{\prod_{j=1}^{k}{p}_{{i}_{j}}^{j}}\).

  2. (ii)

    Calculate the chi-squared statistic, \({\chi }_{{A}_{{r}_{1}}{A}_{{r}_{2}}}^{2}\) corresponding to all the \({}^{k}{C}_{2}\) two-way contingency tables by considering each pair of variables, such that\({\chi }_{{A}_{{r}_{1}}{A}_{{r}_{2}}}^{2}=n\sum_{{i}_{{r}_{1}},{i}_{{r}_{2}}}\frac{{\left({p}_{{i}_{{r}_{1}}{i}_{{r}_{2}}}^{{r}_{1}{r}_{2}}-{p}_{{i}_{{r}_{1}}}^{{r}_{1}}{p}_{{i}_{{r}_{2}}}^{{r}_{2}}\right)}^{2}}{{p}_{{i}_{{r}_{1}}}^{{r}_{1}}{p}_{{i}_{{r}_{2}}}^{{r}_{2}}}\), \(\left( {r_{1} , r_{2} } \right) \in S_{2}\).

  3. (iii)

    Calculate Pearson’s total chi-squared statistic corresponding to a set of \({}^{k}{C}_{r}\) variables, \(\left\{{A}_{{i}_{1}},{A}_{{i}_{2}},\dots ,{A}_{{i}_{r}}\right\}\) such that \({\chi }_{T,{A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{r}}}^{2}=n\sum_{{\underline{i}}_{r}}\frac{{\left({p}_{{\underline{i}}_{r}}-\prod_{j=1}^{r}{p}_{{i}_{j}}^{j}\right)}^{2}}{\prod_{j=1}^{r}{p}_{{i}_{j}}^{j}}\) for \({\underline{i}}_{r}\in {S}_{r},\) \(r=3, 4,\dots ,k-1\).

  4. (iv)

    Calculate the contribution of \(j\)-way association term \({A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{j}}\) in the partition of Pearson’s chi-squared statistic is given by,

    $$\chi_{{A_{{i_{1} }} A_{{i_{2} }} \ldots A_{{i_{j} }} }}^{2} = \chi_{{T,A_{{i_{1} }} A_{{i_{2} }} \ldots A_{{i_{j} }} }}^{2} - \mathop \sum \limits_{r = 2}^{j - 1} \mathop \sum \limits_{{\underline {i}_{r} \in S_{r} }}^{{}} \chi_{{A_{{i_{1} }} A_{{i_{2} }} \ldots A_{{i_{r} }} }}^{2} ,\;j = 3,4, \ldots ,k - 1.$$

Thus, to calculate the contribution of any of the association terms from the partition of Pearson’s chi-squared statistic, we need to calculate all two-way and higher-way association terms. This task is much simpler than calculating all components of \(\boldsymbol{\Pi }\) separately through \({}_{\alpha }{\pi }_{{\underline{i}}_{j}}\) and \({}_{\alpha }{p}_{{\underline{i}}_{j}}^{{\underline{r}}_{j}}\) for \({\underline{i}}_{j}\in {S}_{j}\) for \(j=\mathrm{3,4},\dots ,k\).

4.3 Categorical ANOVA for a Multi-way Table

Consider a \(k\)-way contingency table consisting of ordered variables. The partition of Pearson’s chi-squared statistic can be presented in the form of categorical ANOVA where the statistical significance of each association term can be tested using a chi-squared test of independence with degrees of freedom dependent on the term under consideration. Table 1 gives the general ANOVA table for the analysis of association for \(k\) categorical variables.

Table 1 Categorical ANOVA for \(k\) variables

The practical implementation of the proposed algorithm can be further simplified using matrix-based software packages such as Matlab and Mathematica. Furthermore, the evaluation of the univariate and all multivariate association terms can be determined using tensors, which are akin to a multi-dimensional array. As we shall see, a \(n\)-mode product of a tensor with a matrix can be evaluated to obtain the \(\boldsymbol{\Pi }\)-arrays and their norms. The tensor product simplifies the implementation of the partitioning algorithm described earlier in this section. In Sect. 5, we shall briefly introduce tensors and tensor products and briefly describe how they can be used to obtain the partition of Pearson’s chi-squared statistic for a multi-way contingency table.

5 Tensor-Matrix Product and the Partition for a Multi-way Table

A tensor decompostion has been widely used in analysis of multi-way data; see, for example Kolda and Bader (2009) and the references mentioned therein. Lathauwer et al. (2000) investigated the problem of generalising the singular value decomposition (SVD) of matrices to higher-order tensors. They do this by defining scalar product of tensors, Frobenius-norm of a tensor and tensor product with a matrix. The \(n\)-mode product of \(N\)-way tensor with a matrix is defined as follows.

Definition.

The \(n\)-mode product of tensor \(\mathcal{A}=({a}_{{i}_{1}{i}_{2}\dots {i}_{n}\dots {i}_{N}})\in {\mathbb{C}}^{{I}_{1} \times {I}_{2} \times \dots \times {I}_{n} \times \dots \times {I}_{N}}\) (i.e. a tensor of dimension \({I}_{1} \times {I}_{2} \times \dots \times {I}_{n} \times \dots \times {I}_{N}\)) by a matrix \({\varvec{B}}=({b}_{j{i}_{n}})\in {\mathbb{C}}^{J \times {I}_{n}}\) is denoted by \(\mathcal{A}{\times }_{n}{\varvec{B}}\), and is an \({I}_{1} \times \dots \times {I}_{n-1} \times J\times {I}_{n+1} \times \dots \times {I}_{N}\)-tensor \(\mathcal{C}=({c}_{{i}_{1}{i}_{2}\dots {i}_{n-1}j{i}_{n+1}\dots {i}_{N}})\) such that

$$c_{{i_{1} i_{2} \ldots i_{n - 1} ji_{n + 1} \ldots i_{N} }} = \mathop \sum \limits_{{i_{n} = 1}}^{{I_{n} }} a_{{i_{1} i_{2} \ldots i_{n} \ldots i_{N} }} b_{{ji_{n} }} .$$

This \(n\)-mode product has two interesting properties that are pertinent to the development of our algorithm:

(a) Given a tensor \(\mathcal{A}\in {\mathbb{R}}^{{I}_{1}\times {I}_{2}\times \dots \times {I}_{N}}\) and the matrices \({\varvec{B}}\in {\mathbb{R}}^{{J}_{n}\times {I}_{n}}\) and \({\varvec{C}}\in {\mathbb{R}}^{{J}_{m}\times {I}_{m}}\),\((n\ne m)\)

$$\left( {{\mathcal{A}} \times_{n} {\varvec{B}}} \right) \times_{m} {\varvec{C}} = \left( {{\mathcal{A}} \times_{m} {\varvec{C}}} \right) \times_{n} {\varvec{B}} = {\mathcal{A}} \times_{n} {\varvec{B}} \times_{m} {\varvec{C}}\varvec{.}$$

(b) Given a tensor \(\mathcal{A}\in {\mathbb{R}}^{{I}_{1}\times {I}_{2}\times \dots \times {I}_{N}}\) and matrices \({\varvec{B}}\in {\mathbb{R}}^{{J}_{n}\times {I}_{n}}\) and \({\varvec{C}}\in {\mathbb{R}}^{{K}_{n}\times {J}_{n}}\),

$$\left(\mathcal{A}{\times }_{n}{\varvec{B}}\right){\times }_{n}{\varvec{C}}=\mathcal{A}{\times }_{n}\left({\varvec{C}}{\varvec{B}}\right)$$

We discuss the tensor, the \(n\)-mode product of a tensor with a matrix and demonstrate how they can be used to evaluate all of the association terms of the partition of Pearson’s chi-squared statistic through \({\varvec{\Pi}}\) and \({{\varvec{\Pi}}}_{{\underline{i}_{j}}}\), \({\underline{i}}_{j}\in {S}_{j}, j=\mathrm{2,3},\dots ,k-1\). The (unweighted) norm of \(\mathcal{A}\) is \(\Vert \mathcal{A}\Vert ={\left(\sum_{{i}_{1},{i}_{2},\dots ,{i}_{k}}{a}_{{i}_{1}{i}_{2}\dots {i}_{n}\dots {i}_{k}}^{2}\right)}^{1/2}\) while, for a \({j}_{1}\times {j}_{2}\times \dots \times {j}_{k}\) tensor \(\mathcal{A}\), we define its weighted norm as

$${\Vert \mathcal{A}\Vert }_{w}={\left(\sum_{{i}_{1},{i}_{2},\dots ,{i}_{k}}\left({a}_{{i}_{1}{i}_{2}\dots {i}_{n}\dots {i}_{k}}^{2}\right){p}_{{i}_{1}}^{1}{p}_{{i}_{2}}^{2}\dots {p}_{{i}_{k}}^{k}\right)}^\frac{1}{2}$$

where \({p}_{{i}_{1}}^{1},{p}_{{i}_{2}}^{2},\dots ,{p}_{{i}_{k}}^{k}\) are the expected values of the joint cell proportions under independence between the variables \({A}_{{i}_{1}},{A}_{{i}_{2}},\dots ,{A}_{{i}_{k}}\).

For \(k\) ordered categorical variables, \({\varvec{N}}\), \({\varvec{P}}\) and \(\widehat{{\varvec{P}}}=\left(\prod_{j=1}^{k}{p}_{{i}_{j}}^{j}\right)\) can all be expressed as a \({j}_{1}\times {j}_{2}\times \dots \times {j}_{k}\) dimensional tensor while \({{\varvec{D}}}_{r}=diag({p}_{1}^{r},{p}_{2}^{r},\dots ,{p}_{{j}_{r}}^{r})\) is a \({j}_{r}\times {j}_{r}\) diagonal matrix for the \({r}^{th}\) variable \({A}_{r}\).

To obtain an additive partition of Pearson’s chi-squared statistic, we provide a simple method to obtain \(\boldsymbol{\Pi }\) and \({\boldsymbol{\Pi }}_{{\underset{\_}{{\varvec{i}}}}_{{\varvec{j}}}}\), for \({\underline{i}}_{j}\in {S}_{j}, j=\mathrm{2,3},\dots ,k-1\) when they can be considered as tensors. The weighted norm of each \({\boldsymbol{\Pi }}_{{\underset{\_}{{\varvec{i}}}}_{{\varvec{j}}}}\) gives the total inertia corresponding to the association \({A}_{{\underline{i}}_{j}}\) which can be further used to obtain inertia corresponding to the association between the variables \({A}_{{i}_{1}},{A}_{{i}_{2}},\dots ,{A}_{{i}_{j}}\). The algorithm can be expressed in the form of tensors, and its properties, as follows:

i) Calculate \(\boldsymbol{\Pi }=\left({\varvec{P}}-\widehat{{\varvec{P}}}\right){\times }_{1}{{\varvec{D}}}_{1}^{-1}{\times }_{2}{{\varvec{D}}}_{2}^{-1}{\times }_{3}\dots {\times }_{k}{{\varvec{D}}}_{k}^{-1}\). Then the total inertia of the contingency table can be expressed as the weighted norm.

$${\Phi }^{2} = \left\|{\varvec{\varPi}}\right\|_{w}^{2} = \left\| {{\varvec{\varPi}}\times_{r = 1}^{k} {\varvec{D}}_{r}^{1/2} } \right\|^{2} .$$

ii) At this step we determine the two-way, three-way, \(. . . , \left( {j - 1} \right)\)-way association terms from the partition. Therefore, set\(j=k-1\). Then a set \({S}_{j}\) consists of \({}^{k}{C}_{j}\) tuples and\({A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{j}}\), \({\underline{i}}_{j}\in {S}_{j}\) is the corresponding association term. Let\({S}_{k}-{S}_{j}=\left\{{i}_{1}{\prime}, {i}_{2}{\prime},\dots ,{i}_{k-j}{\prime}\right|{i}{\prime}\in {S}_{k} but not in {S}_{j}\}\). For each of the\({\underline{i}}_{j}\in {S}_{j}\), determine the \(j\)-dimensional tensor \({N}_{{\underline{i}}_{j}}=N{\times }_{{i}{\prime}\in {S}_{k}-{S}_{j}}{E}_{1{j}_{{i}{\prime}}}\) (tensor of cell frequencies)\(,\) \({P}_{{\underline{i}}_{j}}\) (tensor of relative cell frequencies) and \({\widehat{P}}_{{\underline{i}}_{j}}\) (tensor of expected relative frequencies under complete independence) where \({E}_{mn}\) is \(m\times n\) matrix with all elements 1. Then

$${\Pi }_{{\underline{i}}_{j}}=\left({P}_{{\underline{i}}_{j}}-{\widehat{P}}_{{\underline{i}}_{j}}\right){\times }_{i\in {\underline{i}}_{j}}{D}_{i}^{-1}.$$

iii) From step ii), calculate \({\chi }_{T,{A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{j}}}^{2}={\Vert {\Pi }_{{\underline{i}}_{j}}\Vert }_{w}^{2}={\Vert {\Pi }_{{\underline{i}}_{j}}{\times }_{i\in {\underline{i}}_{j}}{{\varvec{D}}}_{i}^{1/2}\Vert }^{2}\)

iv) Repeat the steps (ii) and (iii) for \(j=2, 3,\dots ,k-2\) and set \({\chi }_{T,{A}_{{i}_{1}}{A}_{{i}_{2}}}^{2}={\chi }_{{A}_{{i}_{1}}{A}_{{i}_{2}}}^{2}\) for \({i}_{1}{i}_{2}\in {S}_{2}\).

v) Now that each two-way, three-way, \(. . . , \left( {j - 1} \right)\)-way association term is calculated using the above steps, the \(j\)-way association term,\({A}_{{i}_{1}}{A}_{{i}_{2}}\dots {A}_{{i}_{j}}\), from the partition of Pearson’s chi-squared statistic can be calculated by

$$\chi_{{A_{{i_{1} }} A_{{i_{2} }} \ldots A_{{i_{j} }} }}^{2} = \chi_{{T,A_{{i_{1} }} A_{{i_{2} }} \ldots A_{{i_{j} }} }}^{2} - \mathop \sum \limits_{r = 2}^{j - 1} \mathop \sum \limits_{{\underline {i}_{r} \in S_{r} }}^{{}} \chi_{{A_{{i_{1} }} A_{{i_{2} }} \ldots A_{{i_{r} }} }}^{2} ,\;j = 3,4, \ldots .,k - 1$$

The next section demonstrates the applicability of this algorithm.

6 Numerical Results

In this section, we present a practical demonstration of the partition of Pearson’s chi-squared statistic for a four-way table and perform tests on the statistical significance of each of the association terms. Matlab code (not given here) is used to execute the tensor based algorithm described in Sect. 5. We also develop Matlab code for the analysis of a four-way and five-way table using the traditional method of partitioning discussed in Sect. 3. Furthermore, we compare the execution time (in seconds) of the traditional method and the new algorithm through empirical and simulated multi-way contingency tables.

6.1 PISA Study

Consider the data summarised in Table 2. It was obtained from the 2003 PISA (Programme for International Student Assessment) study of a student’s gender \((A)\), their country of origin \((B)\) and their response to two survey questions \((C,D)\). The two survey questions are as follows.

Table 2 Four-way contingency table of student responses from the PISA study

Q1. “I am just not good at math” and

Q2.“In math class the teacher continues teaching until the students understand.”

This data was also analysed by Azen and Walker (2011) and consists of the following categorical variables:

Variable label

Variable

No. of categories

Categories of the variable

A

Gender

2

Female, male

B

Country

3

Australia, France, United States

C

Response to Q1

4

Strongly agree, agree, disagree, strongly disagree

D

Response to Q2

4

Every lesson, most lessons, some lessons, hardly/never

Consider the four-way contingency table of Table 2 which is of dimension \(2\times 3\times 4\times 4\). We assume that all the categorical variables are ordered variables.

Pearson’s chi-squared statistic of this table is 1918.2484 and, with 86 degrees of freedom, has an extremely small p-value (< 0.0001). This suggests that there exists an association between at least two of the four variables, although it does not reveal which bivariate, trivariate or four-way association terms are dominant or statistically significant. To examine further the structure of this association, we partition Pearson’s statistic in accordance with (3).

As we discussed in Sect. 5, we use the \(n\)-mode products to obtain all \(\Pi\)-arrays and calculate their weighted norms and do so using Matlab. The 11 terms of (3) are evaluated using the traditional method described in Sect. 3 and the new algorithm described in Sect. 4. Both approaches yield the same terms of the partition (which are summarised in Table 3), however the new algorithm performed the calculations in 0.0320 s while the traditional method took twice as long − 0.0631 s—such timescales may be small, and on the surface insignificant, but it does highlight improvements in the efficiency of the partition of Pearson’s statistic when compared with the procedure in Sect. 3.

Table 3 Categorical ANOVA for contingency table of student responses from the PISA study

Table 3 also summarises the percentage contribution each term makes to the chi-squared statistic, the degrees of freedom (DF) of the term and its \(p\)-value. It shows that, for the variables associated with Table 2, all pair-wise association terms from the partition of its chi-squared statistic are statistically significant, the largest of which is the term CD which describes the association between the responses to Question 1 and Question 2. Such an association contributes to nearly half (42.43%) of the association structure in the contingency table. In fact, the participants’ response to Question 2 is not significantly associated with their gender or country of origin (term ABD) while the only statistically significant trivariate association term is between the gender of those who participated and their response to Question 1 and Question 2 (term ACD). Gaining more insight into how gender and the responses to the questions are associated can be further investigated using CA and, more generally, multi-way data analysis (Greenacre 1984; Lebart et al. 1984; Kroonenberg 2008; Beh and Lombardo 2014).

6.2 Computational Speed

We now turn our attention to assessing the computational speed of the new algorithm when compared to the approach outlined in Sect. 3 and the approach by Loisel and Takane (2016). This is achieved through the analysis of real and simulated contingency tables (or high-dimensional arrays for the purposes of using tensors as described in Sect. 5) that are simulated from a discrete uniform distribution on the interval \([\mathrm{7,100}]\). Such a range is chosen to ensure that each of the expected cell frequencies of the randomly generated contingency table exceeds 5 thereby satisfying Cochran’s rules (Cochran 1952, 1954). These tables were randomly generated using the unidrnd() function in Matlab. For the sake of brevity, we do not summarise the ANOVA output of these partitions (we consider the example in Sect. 6.1 as providing the empirical evidence on their numerical equivalence) but instead record the execution time it takes for the partition to take place using the two approaches. The execution times are given in Table 4 for five real data sets (that are either three-way, four-way and five-way) ranging in dimension from \(3\times 3\times 3\) to \(3\times 5\times 2\times 2\times 2\). We also summarise in Table 4 the execution times of seven randomly generated contingency tables consisting of the cross-classification of five, six and seven categorical variables.

Table 4 Execution time to obtain the partition using traditional method, method by Loisel and Takane (2016) and the new method

Table 4 shows that the new algorithm described in Sect. 5 provides a quicker execution time of the partition of Pearson’s chi-squared statistic than the traditional method of partition and that by Loisel and Takane (2016). This is apparent when comparing the execution times for the larger contingency tables, including the four-way table of Azen and Walker (2011), the five-way table given in Jarausch and Arminger (1989) and the randomly simulated five-way contingency tables. As the execution times for method described by Loisel and Takane (2016) are longer when compared with the new algorithm and traditional method, we present a comparison of a new algorithm with that of the traditional one. In these cases, the new algorithm at least halves the execution time needed for the partition to be performed. The new algorithm was also able to partition the Pearson chi-squared statistic for a six-way and seven-way contingency table; albeit, the calculation time took a little longer for these large tables than it did to partition a three-, four- or five-way contingency table.

The reason behind the longer execution times taken by Loisel and Takane (2016) method lies in the methodology used in the partition. Every chi-squared term is expressed as a quadratic form in an idempotent matrix of size which is product of categories of all variables (i.e. all possible combinations of categories of all variables). For example, in the case of the simulated contingency table of size \(10\times 5\times 5\times 5\times 5\), every chi-squared statistic corresponding to the two-way, three-way, four-way and five-way association terms (in all 26 such terms) is calculated as a quadratic form in a 6250 sized matrix. It may be due to this reason that the program runs out of memory. The methodology given by Loisel and Takane (2016) has a strong theoretical basis but software implementation proves to be very challenging in this case. This problem can be seen to be overcome using the new algorithm presented in this paper.

For the traditional method of partition, calculating the association terms in a six-way, seven-way, or “higher”-way contingency tables are very complex and are not generalisable. As a result, there is no software available to perform a generic partition of Pearson’s chi-squared statistic for multi-way contingency tables. Instead, the analyst is required to develop separate code for the analysis of a three-, four- and “higher”-way contingency table. It is for this reason that no execution time is included in Table 4 for the randomly generated six-way and seven-way tables. However, the new algorithm overcomes this problem; the new algorithm calculates the higher-order terms of the partition of the chi-squared statistic using lower-order (eg two-, or three-, way) association terms.

7 Discussion

This paper develops an algorithm for partitioning Pearson’s chi-squared statistic for four-way and five-way contingency tables and extends to the multi-way case. The traditional approach to partitioning Pearson’s chi-squared, or equivalently \({\Phi }^{2}\), statistic for multi-way tables is computationally complex and has rarely been performed in practice or implemented into current statistical packages. This paper has proposed a new method of partition using tensors that provide the analyst with a means of calculating multi-way sources of association based on the prior calculation of two-, three-, and other “lower”-order association terms. Furthermore, the ANOVA-like partition can be presented in the form of categorical ANOVA which allows for one to test the statistical significance of each term of the partition. Our demonstration of the new algorithm shows that using tensors and tensor products allows one to simply, and quickly, partition Pearson’s statistic. We do acknowledge though that the execution times between the two approaches is in the order of a fraction of a second and therefore may appear, on the surface, insignificant (we alluded to this point in Sect. 6.1). However, we must keep in mind that, in practice, a study generally will consist of more than four or five variables and in the commercial and industrial sectors data is collected on 100 s and even 1000 s of categorical variables. This is certainly true for the analysis of questionnaires and surveys where responders are asked to “tick a box”. For example, the 2016 Australian Census consisted of 51 questions, most of which may be treated as categorical variables. Simultaneously exploring the association between all, or even a subset, of such a large number of categorical variables is almost never performed due, for example, to the computational complexities in doing so. The computational efficiency of the algorithm outlined in Sect. 4 is apparent since the execution time of the partition can be generally at least halved when compared with the traditional method of partition described in Sect. 3. While such efficiencies gained appear small, our demonstrations here suggest that better efficiencies can be gained for the analysis of truly large number of variables.

Further developments of this algorithm can be extended beyond the case of studying symmetric association between categorical variables. That is, rather than just partitioning Pearson’s chi-squared statistic for multi-way contingency tables, this algorithm can be extended to situations where a partition of multi-way version of asymmetric association is required. These may include the partitions of the delta index (Lombardo 2011), the Marcotorchino index (Marcotorchino 1984) and the Gray–Williams index (Gray & Williams 1975) which have been confined to the analysis of asymmetric association among only three categorical variables. Other areas of further investigation include utilising the algorithm in the context of modelling categorical variables using association models, correspondence models and log linear models. We shall leave the development of the algorithm to these cases for future consideration.