Why the Choice of Margins Matters
A multiway table can contain several kinds of association at once. In a three-way table, for example, \(A\) and \(B\) may be associated within levels of \(C\), while the strength of that association may itself vary with \(C\). An exact test must specify which of these features is under examination. The choice of margins to fix is not merely a computational convenience: it determines which nuisance parameters are removed and which association remains available to vary.
The key idea is to condition on margins that are sufficient for the nuisance parameters under the null model. The resulting conditional reference distribution is then calculated over tables with those margins. Sparse tables are well suited to this approach because the conditional distribution is based on the stated model and margins, rather than on a large-sample approximation.
The Conditional Distribution for a Loglinear Model
Let \(n_r\) be the observed count in cell \(r\) of a table with a finite number \(q\) of cells. Suppose the cell counts are independent Poisson variables with means \(\mu_r\), and suppose the null loglinear model has the form \(\log \mu_r=a_r^\mathsf{T}\beta\), where \(a_r\) is a known vector of cell indicators and \(\beta\) is a vector of model parameters. Define the sufficient statistic \(T(n)=\sum_r a_r n_r\). Its components are the margins or other linear combinations of counts represented by the model terms.
The factorial weights follow directly from the independent Poisson likelihood. The conditioning removes the unknown parameters because all tables in the sample space have the same value of \(T(n)\).
The formula applies whether or not the conditional sample space is finite. Its denominator is finite automatically: since the sample space is a subset of all nonnegative integer \(q\)-vectors,
Thus even an infinite conditional sample space has a well-defined normalizing sum for a finite table.
Proof. The joint probability of a table \(n\) under independent Poisson sampling is
On the event \(T(N)=m\), the first factor is constant across all tables, and the numerator of the exponential factor is \(\exp(\beta^\mathsf{T}m)\), also constant. Dividing each joint probability by the sum of joint probabilities over tables with \(T(n)=m\) therefore leaves the factorial weights normalized by their sum. The bound above establishes that this sum is finite; it is positive because \(m\) is attainable. \(\square\)
Conditional Independence in a Stratified Two-by-Two Table
Consider a three-way table with variables \(A\), \(B\), and \(C\), where \(A\) and \(B\) are binary and \(C\) indexes strata. The loglinear model \([AC][BC]\) represents the null hypothesis \(A\perp B\mid C\): within each level of \(C\), the distribution of \(A\) does not depend on \(B\). Its sufficient margins are the \(AC\) and \(BC\) margins, \(n_{i+k}\) and \(n_{+jk}\). Fixing them leaves the within-stratum association free to vary.
For one stratum, write the \(2\times2\) table as \(\left(\begin{smallmatrix}x&r-x\\c-x&N-r-c+x\end{smallmatrix}\right)\), where \(r\) is the first-row total, \(c\) is the first-column total, and \(N\) is the stratum total. Under conditional independence, its conditional distribution is hypergeometric:
The strata are conditionally independent given their separate margins under this null, so their reference distributions can be combined to form a test statistic for the stratified association.
Worked Example: An Exact Test of Conditional Independence
Suppose a study records a binary exposure \(A\), a binary outcome \(B\), and a two-level stratum \(C\). In stratum \(C=0\), the observed table has rows \(A=1,0\) and columns \(B=1,0\):
| \(C=0\) | \(B=1\) | \(B=0\) | Total |
|---|---|---|---|
| \(A=1\) | 2 | 1 | 3 |
| \(A=0\) | 0 | 2 | 2 |
| Total | 2 | 3 | 5 |
For \(C=1\), let the corresponding table be \(\left(\begin{smallmatrix}1&1\\0&2\end{smallmatrix}\right)\), with row totals 2 and 2, column totals 1 and 3, and total 4. Under \(A\perp B\mid C\), the first cell count \(X_0\) in the first stratum has \(r=3,c=2,N=5\). Therefore
In the second stratum, \(X_1\) has \(r=2,c=1,N=4\), so
The observed statistic \(S=X_0+X_1\) equals \(2+1=3\). Convolving the two distributions gives \(P(S=0,1,2,3)=(0.05,0.35,0.45,0.15)\). For a one-sided alternative of positive association, larger values of \(S\) are evidence against the null, and the exact conditional p-value is \(P(S\geq3)=0.15\). This tail probability is computed with both sets of stratum margins fixed; it does not rely on a large-sample chi-square approximation.
Which Interaction Does the Conditioning Test?
The same logic applies to other loglinear null models, but the margins change with the model. For example, the model \([AB][AC][BC]\) contains all two-factor terms but omits the three-factor \(ABC\) interaction. Conditioning on all three two-way margins removes the parameters for those terms. The remaining variation in the conditional sample space concerns the highest-order interaction. Consequently, a test based on those margins is not a general test of whether \(A\) and \(B\) are associated within levels of \(C\); it tests whether the three-way interaction is needed after the two-way associations are allowed.
More generally, suppose a model adds an interaction parameter \(\gamma\) with cell contribution \(\gamma u_r\), while the nuisance part has sufficient statistic \(T(n)\). Conditional on \(T(n)=m\), the distribution becomes an exponential tilt of the factorial weights:
Under the null \(\gamma=0\), this reduces to the factorial-weighted distribution in the theorem. This expression explains the interpretation of a conditional test: the null reference distribution describes variation in the interaction statistic \(U\) after the nuisance margins have been held fixed.
Worked Example: Fixing Pairwise Margins Tests the Three-Way Interaction
Take a \(2\times2\times2\) table with all eight cell counts equal to 1. Each cell in every two-way marginal table is 2. Under the null model \([AB][AC][BC]\), fix these pairwise margins. Starting from the all-ones table, the only possible changes that preserve every two-way margin add \(t\) to cells \(111,122,212,221\) and subtract \(t\) from cells \(112,121,211,222\). Nonnegative integer counts require \(t\in\{-1,0,1\}\), so the conditional sample space has three tables.
For \(t=0\), the factorial weight is 1. For either \(t=1\) or \(t=-1\), four cells are 0 and four are 2, giving weight \(1/(2!)^4=1/16\). The normalizing sum is \(1+1/16+1/16=9/8\). Thus the probabilities of the three tables are \(8/9,1/18,1/18\). The only variation here is the three-way interaction: the pairwise margins are identical in all three tables. In particular, these margins cannot be used to claim a test of conditional independence \(A\perp B\mid C\), since that hypothesis concerns pairwise association within strata.
Worked Example: A Conditional Test of Mutual Independence
Let \(A,B,C\) each be binary, and observe two individuals: one in cell \(000\) and one in cell \(111\). Test the null model of mutual independence, \([A][B][C]\), by fixing the one-way margins. Each variable has one observation at level 0 and one at level 1. The possible tables consist of a pair of complementary cells: \(000\) with \(111\), \(001\) with \(110\), \(010\) with \(101\), or \(011\) with \(100\).
Each table has two cells with count 1 and all other counts 0, so every table has weight \(1/(1!1!)=1\). The conditional distribution is uniform over the four tables. For the directional statistic \(U=n_{000}+n_{111}\), the observed value is 2; it is 0 for the other three tables. Hence the exact upper-tail probability is \(P(U\geq2)=1/4\). This illustrates the distinct role of fixing one-way margins: under \([A][B][C]\), all associations are excluded under the null, so deviations can reflect pairwise as well as three-way association. The chosen statistic targets one pattern of departure; a broader test would use an appropriately chosen omnibus statistic.
Exact P-Values and a Common Pitfall
An exact conditional p-value is a tail probability calculated under the null conditional distribution, using the observed margins. The test statistic and the tail must match the scientific alternative. A one-sided test can use an ordered statistic, as in the stratified example. For a two-sided test in a discrete distribution, different defensible orderings can give different p-values; the ordering rule should be stated rather than treating “two-sided” as uniquely defined.
- Pitfall: fixing margins without naming the null. “We fixed the margins and tested association” is incomplete. Pairwise margins in a three-way table remove two-factor nuisance terms and leave the three-way interaction to vary; margins involving \(AC\) and \(BC\) instead support a test of \(A\perp B\mid C\).
- Pitfall: assuming an infinite sample space cannot be normalized. Here the factorial-weight sum over any conditional sample space is at most \(e^q\) for \(q\) cells, so it is finite even if the space contains infinitely many tables.
- Pitfall: treating “exact” as synonymous with “two-sided.” Exactness describes the reference distribution, not a unique choice of statistic or tail ordering. State how extremeness is defined.
The practical workflow is to write down the null loglinear model, identify its sufficient margins, condition on those margins, and then choose a statistic that measures departure in the interaction of interest. This makes the reference distribution and the scientific interpretation agree.
Check Your Understanding
Use the null model and the margins—not just the table dimensions—to answer each question.
- For a three-way table, which margins are fixed to test \(A\perp B\mid C\) under the loglinear model \([AC][BC]\)?
- What association remains available to vary when all three two-way margins are fixed under \([AB][AC][BC]\)?
- Why does the factorial-weighted conditional distribution have a finite normalizing constant even if its sample space is infinite?
- In the stratified example, what is the one-sided exact p-value for a positive association, and which statistic defines its tail?
- Why would fixing all pairwise margins be the wrong choice if the scientific null is conditional independence of \(A\) and \(B\) given \(C\)?