Pearson's chi-squared test

Often for $Λ$ the generalised likelihood ratio statistic, we obtain $$ \begin{align*} 2\log Λ = 2\sum_{i} O_i \log \frac{O_i}{E_i} \end{align*} $$ where $O_i$ and $E_i$ are the observed and expected counts of $i$, satisfying $\sum_{i} O_i = \sum_{i} E_i$.

Pearson's chi-squared statistic is the approximation $$ \begin{align*} 2\log Λ \approx \sum_{i} \frac{(O_i - E_i)^2}{E_i} \end{align*} $$ valid when $(O_i - E_i)/E_i \approx 0$. (Derivation)

By Wilks' theorem, $2\log Λ \xrightarrow{d} χ^2_d$ under $H_0$ with a certain degree of freedom $d$. So the size $α$ Pearson's chi-squared test rejects $H_0$ if $$ \begin{align*} \sum_{i} \frac{(O_i - E_i)^2}{E_i} > χ^2_d(α). \end{align*} $$

Goodness-of-fit test open_in_new

Suppose $(N_1, \ldots, N_k) \sim \mathrm{Multinomial}(n; p_1, \ldots, p_k)$. Test $H_0: p=p_0(θ)$ for some $θ$ against $H_1: p_i$ unrestricted (but still $p_i\geq 0$ and $\sum_{i} p_i=1$), excluding $H_0$.

Apply Pearson's chi-squared test with $$ \begin{align*} O_i = N_i, \qquad E_i = np_{0i}(\hat θ_{\text{MLE}}), \qquad d = k-1-\op{df}(H_0). \end{align*} $$ where $\hat θ_{\text{MLE}}$ is the maximum likelihood estimator for $θ$ under $H_0$ and $\op{df}(H_0)$ is the degree of freedom of $H_0$. (Derivation)

Test for independence in two-way contingency tables open_in_new

Suppose $(X_1, Y_1), \ldots, (X_n, Y_n) \sim P$ iid, with $X_1\in (1,2,\ldots,r)$ and $Y_1\in (1,2,\ldots,c)$. Test $H_0: X_1$ and $Y_1$ are independent.

Summarise data by a contingency table with entries $N_{xy} = \sum_{i=1}^{n} \mathbb{1}_{\set{X_i = x, Y_i = y}}$. Model as $$ \begin{align*} (N_{11}, \ldots, N_{1c}, \ldots, N_{r1}, \ldots, N_{rc}) \sim \mathrm{Multinomial}(n; p_{11}, \ldots, p_{1c}, \ldots, p_{r 1}, \ldots, p_{rc}). \end{align*} $$ Now

  • $H_0$: $p_{xy} = p_{x+} p_{+y}$ where $p_{x+}, p_{+y}\geq 0$, $\sum_{x} p_{x+} = 1 = \sum_{y} p_{+y}$

  • $H_1$: $p_{xy}$ unrestricted (but still $p_{xy} \geq 0$, $\sum_{x,y} p_{xy} = 1$), excluding $H_0$.

Apply Pearson's chi-squared test with $$ \begin{align*} O_{xy} = N_{xy}, \qquad E_{xy} = \frac{N_{x+} N_{+y}}{n}, \qquad d=(r-1)(c-1). \end{align*} $$ (Derivation)

Test for homogeneity open_in_new

Now for each row $x$, we make a fixed number $n_x$ of samples. Model as $$ \begin{align*} (N_{x1}, \ldots, N_{xc}) \sim \mathrm{Multinomial}(n_x; p_{1\mid x}, \ldots, p_{c\mid x}). \end{align*} $$ Test $H_0:p_{y\mid x}$ does not depend on $x$ against $H_1: p_{y\mid x}$ unrestricted (but still $p_{y\mid x}\geq 0$ and $\sum_{y} p_{y\mid x} = 1$), excluding $H_0$.

The test is the same as the test for independence. (Derivation)