of observations in one cell of the K x K cluster crosstable. The first step in calculating χ 2is to calculate for each cell the number of expected counts ˆnk,l under the assumption of independence:

$${\hat{n}}_{k,l}=p_{k}\cdot p_{l}\cdot N={\frac{n_{k}\cdot n_{l}}{N}}$$

N(1)
Then, we transform the matrix of raw counts in Equation 1 into a matrix of normalized squared deviations dk,l from the null model:

$$d_{k,l}={\frac{(n_{k,l}-{\hat{n}}_{k,l})^{2}}{{\hat{n}}_{k,l}}}$$
$$\left(1\right)$$

$\left(3\right)$. 
$$\left(2\right)$$

The χ 2-value is defined as the sum of Equation 2 over all cells. If we restore the sign in Equation 2, we get:

$$s_{k,l}=s i g n(n_{k,l}-{\hat{n}}_{k,l})\cdot d_{k,l}$$
sk,l = sign(nk,l − nˆk,l) · dk,l (3)
In order to cope with unequal cluster sizes, we suggest basing cluster matching on maximizing the trace of sk,l rather than on maximizing the trace of nk,l. And in order to avoid any systematic not based on the data, we add a probabilistic component to the matching algorithm. Consequently we define the *truematch algorithm* as:
1. Randomly permute rows and columns of the matching table

2. Transform the matching table counts nk,l to signed normalized squared deviations sk,l using Equation 3 3. Apply a trace maximization algorithm like the Hungarian method to maximize the trace (in fact the Hungarian method minimizes −sk,l)
4. Order the resulting row/column pairs descending by sk,l breaking ties at random
If no trace maximization algorithm like the Hungarian method is available, the matching can easily be done using the *truematch heuristic* similar to the heuristic suggested by Dimitriadou et al. (2002):

1. Calculate signed normalized squared deviations sk,l for all *remaining* cells of the matching table 2. Order all cells descending by sk,l and by nk,l (breaking ties by random) and denote the first cell as the *target cell* 3. Match the row of the target cell to the column of the target cell 4. Remove the row and the column of the target cell from the matching table 5. If both the number of remaining rows and columns is at least two, repeat from step 1