A Note on 3-by-3 Tables

Math: linear algebra exercises

Recently, at work, I have used contingency tables several times. Although the tables themselves were 2-by-2, once the row totals, column totals, and grand total were included, I was effectively working with 3-by-3 tables.

Consider the following 3-by-3 table:

C1 C2 Rt
R1 $a$ $d$ $g$
R2 $b$ $e$ $h$
Ct $c$ $f$ $i$

where C and R denote column and row, respectively, and t denotes total. We can arrange the nine numbers, denoted by $ a,\ b,\ \ldots, h,\ i $, into a vector $\boldsymbol{x}$, which belongs to the vector space $\mathbb{R}^9$. However, these values are subject to total constraints. Specifically, the entries in the last column are equal to the sums of the corresponding entries in the first two columns, and the entries in the last row are equal to the sums of the corresponding entries in the first two rows. Therefore, the elements of $\boldsymbol{x}$ satisfy

$$ \boldsymbol{Ax} = \boldsymbol{0}, $$

where

$$ \boldsymbol{A} = \left[ \begin{array}{ccccccccc} 1 & 0 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\ 0 & 1 & 0 & 0 & 1 & 0 & 0 & -1 & 0 \\ 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & -1 \\ 1 & 1 & -1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 & -1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & -1 \end{array} \right]. $$

The rank of $ \boldsymbol{A} $ is $ 5 $. Consequently, all vectors corresponding to 3-by-3 tables that satisfy the total constraints lie in a 4-dimensional subspace of $ \mathbb{R}^9 $.

This led me to ask the following question:

If we select any four cells in a 3-by-3 table and assign values to them that are consistent with the total constraints, can the remaining five cells always be determined?

The answer is yes, although the nature of the solution depends on the positions of the four selected cells. In some cases, the solution is unique; in others, there are infinitely many solutions.

I asked an AI system to provide a mathematical proof of this result, and it did. The key ideas are:

  • The entire 3-by-3 table is determined by only four degrees of freedom (for example, the four entries in the upper-left 2-by-2 block).
  • Assigning values to four selected cells effectively produces a system of four equations in these four underlying degrees of freedom.
  • A solution always exists, provided that the assigned values themselves satisfy the relevant total constraints.

Remark: If we want to guarantee a unique solution, then we must specify values in at least six cells. In fact, the following theorem shows that six is the smallest number for which this is always possible.

Theorem: Let $\boldsymbol{B}$ be the $9 \times 4$ real matrix whose rows consist of:

  1. The four standard basis vectors of $\mathbb{R}^4$: $\boldsymbol{e}_1, \boldsymbol{e}_2, \boldsymbol{e}_3, \boldsymbol{e}_4.$
  2. Four of their pairwise sums: $\boldsymbol{e}_1+\boldsymbol{e}_2, ; \boldsymbol{e}_3+\boldsymbol{e}_4, ; \boldsymbol{e}_1+\boldsymbol{e}_3, ; \boldsymbol{e}_2+\boldsymbol{e}_4.$
  3. The sum of all four basis vectors: $\boldsymbol{e}_1+\boldsymbol{e}_2+\boldsymbol{e}_3+\boldsymbol{e}_4.$

Explicitly,

$$ \boldsymbol{B} = \left[ \begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 1 & 1 & 1 \end{array} \right] $$

If $\boldsymbol{C}$ is any $6 \times 4$ submatrix obtained by selecting any six rows of $\boldsymbol{B}$, then

$$ \hbox{rank}(\boldsymbol{C}) = 4 $$

A game

With the above insights, I invented a game called Find Five. You can play it here: Find Five.

Credits: The idea is mine; the code was generated by AI.

Lingyun Zhang (张凌云)
Lingyun Zhang (张凌云)
Design Analyst

I have research interests in Statistics, applied probability and computation.