4.4 Testing for no association

The chi-squared test

Proposition 4.4.1. For a \(2 \times 2\) table, Pearson’s statistic \(X^2 = \sum (O - E)^2/E\), with expected counts \(E\) computed from the margins, is \[ X^2 = \frac {n(ad - bc)^2}{n_1 n_0 m_1 m_0} , \] and it equals \(z^2\), where \(z = (\hat p_1 - \hat p_0)/\sqrt {\hat p(1 - \hat p)(1/n_1 + 1/n_0)}\) is the two-sample test statistic for proportions with pooled \(\hat p = m_1/n\).

Proof. The expected count in the exposed-case cell is \(n_1 m_1/n\), and \[ a - \frac {n_1 m_1}{n} = \frac {a(a + b + c + d) - (a + c)(a + b)}{n} = \frac {ad - bc}{n} . \] Since the margins of \(O\) and \(E\) agree, the other three deviations are \(\pm (ad - bc)/n\) too. Hence \(X^2 = \{(ad - bc)/n\}^2 \sum 1/E\), and \begin {align*} \sum \frac {1}{E} &= n\Bigl (\frac {1}{n_1 m_1} + \frac {1}{n_1 m_0} + \frac {1}{n_0 m_1} + \frac {1}{n_0 m_0}\Bigr ) \\ &= \frac {n(n_0 + n_1)(m_0 + m_1)}{n_1 n_0 m_1 m_0} = \frac {n^3}{n_1 n_0 m_1 m_0} . \end {align*}

For the second claim, \(\hat p_1 - \hat p_0 = a/n_1 - b/n_0 = (an_0 - bn_1)/(n_1 n_0) = (ad - bc)/(n_1 n_0)\), and \(\hat p(1 - \hat p)(1/n_1 + 1/n_0) = m_1 m_0 n/(n^2 n_1 n_0)\). Squaring and dividing gives \(n(ad - bc)^2/(n_1 n_0 m_1 m_0)\). □

Under no association \(X^2\) is approximately \(\chi ^2_1\). In Example 4.2.3, \(X^2 = 24.7\) (\(P < 0.0001\)), and in Example 4.3.2, \(X^2 = 16.1\) (\(P = 0.00006\)). The approximation needs expected counts that are not too small; a common rule is all four at least \(5\).

The conditional distribution and Fisher’s exact test

Theorem 4.4.2. In a cohort study with \(p_1 = p_0\), the conditional distribution of \(a\) given the total number of cases \(m_1\) is hypergeometric: \[ P(a = k \mid m_1) = \frac {\binom {n_1}{k}\binom {n_0}{m_1 - k}}{\binom {n}{m_1}} , \] with mean \(n_1 m_1/n\) and variance \(n_1 n_0 m_1 m_0/\{n^2(n - 1)\}\). The same distribution holds in a case-control study under \(q_1 = q_0\), conditioning on \(n_1\).

Proof. With common risk \(p\), \(P(a = k,\ b = m_1 - k) = \binom {n_1}{k}\binom {n_0}{m_1 - k} p^{m_1}(1 - p)^{n - m_1}\), and \(m_1 \sim \text {Bin}(n, p)\) has probability \(\binom {n}{m_1}p^{m_1}(1 - p)^{n - m_1}\). The ratio is the stated probability, free of \(p\). It is the distribution of the number of exposed people among \(m_1\) drawn without replacement from \(n\) of whom \(n_1\) are exposed, whose mean and variance are the standard hypergeometric moments. The case-control statement is the same argument with the roles of exposure and disease exchanged. □

Conditioning removes the unknown common risk, so the distribution can be used exactly. Fisher’s exact test computes the \(P\)-value as the conditional probability of a table at least as extreme as the one observed. The hypergeometric mean and variance are the building blocks of the Mantel–Haenszel test, later in the course.

Example 4.4.3. In a small outbreak investigation, \(6\) of \(10\) people who ate a dish became ill, against \(2\) of \(12\) who did not. Here \(n = 22\), \(n_1 = 10\), \(m_1 = 8\), and \(\widehat {\OR } = (6 \times 10)/(2 \times 4) = 7.5\). Given \(8\) cases, the number among the \(10\) who ate the dish is hypergeometric with probabilities

\(k\) 0 1 2 3 4 5 6 7 8
\(P\) .0016 .0248 .1300 .2972 .3251 .1734 .0433 .0045 .0001

The one-sided \(P\)-value is \(P(a \geq 6) = 0.0433 + 0.0045 + 0.0001 = 0.048\). The two-sided value, adding the probabilities of all tables no more probable than the observed one (\(k = 0, 1, 6, 7, 8\)), is \(0.074\). The chi-squared test gives \(X^2 = 4.43\), \(P = 0.035\), too small, because three expected counts are under \(5\).

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.