Until now every test was about a parameter. This chapter asks a different question: is the model itself right? Group the data into classes, compare the observed counts with the counts the model predicts, and measure the disagreement with Karl Pearson's statistic \(\sum(\text{observed}-\text{expected})^2/\text{expected}\). The same statistic tests a fully specified model, a model with estimated parameters, and the independence of two classifications. The book states the key fact, that the statistic is approximately chi-square with \(t-1\) degrees of freedom (and \(t-1-s\) when \(s\) parameters are estimated), without proof. These notes prove it: the multinomial central limit theorem and a projection argument show where every degree of freedom goes, and why the estimated-parameter rule needs a particular estimate. They also show how good the approximation is for small counts, explain Benford's law and the "too good to be true" test, give an exact test for small tables, and correct a case study whose conclusion reverses once a miscounted city is put back in its cell.
Course home Ch. 1 Introduction Ch. 2 Probability Ch. 3 Random variables Ch. 4 Special distributions Ch. 5 Estimation Ch. 6 Hypothesis testing Ch. 7 Normal-based inference Ch. 8 Types of data Ch. 9 Two-sample inference Ch. 10 Goodness of fit Ch. 11 Regression Ch. 12 Analysis of variance Ch. 13 Randomized blocks Ch. 14 Nonparametric statistics
Each Filling the gap box completes a step or a proof the book leaves out, and each selected question asks you to apply the chapter. Try it yourself first. When you are stuck, open Hint 1; the next hint unlocks one minute after you open the previous one, so take one hint at a time and think about it before moving on: the key idea first, then the tools, then the steps, with intermediate results to aim for. The full proof or solution appears after the last hint and unlocks two minutes later: use it to check your own argument. If you use a generative AI assistant, use it the same way: ask for a hint or for the next step only, then check what it says against these notes (why I teach this way). Spotted a mistake? Use the Report an error link at the end of each box: confirmed errors are corrected and listed, with thanks, in the errata.
They follow the book. Sections carry the book's numbers (10.1 to 10.6) and numbered items keep theirs (Theorem 10.3.1, Example 10.2.3, Case Study 10.4.2). Everything is written in new words; the book is cited for each result, example and figure, and displayed equations that the book numbers keep its number, e.g. \((10.3.1)\). The book writes \(t\) for the number of classes and \(\chi^2_{p,\,\nu}\) for the \(p\)-th quantile of the chi-square distribution with \(\nu\) degrees of freedom (so \(\chi^2_{0.95,\,3}=7.815\)); these notes do the same.
Filling the gaps. Wherever the book says "a formal proof lies beyond the scope of this text", "it can be shown", refers to another text, or works an example too fast to follow, an orange Filling the gap box gives the full argument. The central ones are 10.5 and 10.6 (Pearson's theorem) and 10.11, 10.12 (estimated parameters). Proofs and derivations start hidden: open one with its bar, or use the button below. Each gap box and each selected question offers graded hints, one at a time, before the full solution.
Figures and demonstrations. Four figures of the chapter (10.2.2, 10.3.2, 10.3.3 and 10.3.4) are reproduced; three own figures (x10.1 to x10.3) show the geometry of Pearson's statistic and the exact size of the test, the null distribution of the statistic with estimated parameters, and the null distribution of Dixon's outlier ratio. The schematic of \(n\) trials (Figure 10.2.1) and the drawing of the two crustaceans (Figure 10.3.1) are not redrawn. All are computed by the Python code. The ▶ Demo boxes open an interactive demonstration already set to the case being discussed.
R. J. Larsen and M. L. Marx, An Introduction to Mathematical Statistics and Its Applications, 6th edition, Pearson (2018), Chapter 10, pages 483–519. Section, case-study, figure, equation and question numbers below refer to this book. Further reading is listed in the references.
The explanations, derivations, figures and code are my own; equations are cited by their numbers in the book.
Goodness of fit and tests of independence are treated, at other levels and in other words, in companion courses of this site. Where a proof there is complete, these notes give the statement and a short argument and link to it.
New here: the multinomial central limit theorem by moment-generating functions, the route the book points to (Filling the gap 10.5); the projection that removes one degree of freedom for the constraint and one per estimated parameter (10.6, 10.11, 10.12); exact sizes for small expected counts (10.8); the exact first-digit law of the Pareto distribution (10.9); Fisher's exact test applied to a corrected Case Study 10.5.2 (10.17); and the null distribution of Dixon's ratio (10.18).
Notation. \(t\) classes (or ranges) \(r_1,\dots,r_t\) with probabilities \(p_1,\dots,p_t\), \(\sum p_i=1\); \(X_i\) is the number of the \(n\) observations in class \(i\) and \(k_i\) its observed value. Under a null hypothesis the probabilities are \(p_{i0}\) (or \(\hat p_{i0}\) when estimated) and \(np_{i0}\) are the expected frequencies. \(u=(\sqrt{p_1},\dots,\sqrt{p_t})^\T\) is a unit vector, \(\convd\) denotes convergence in distribution and \(\convp\) convergence in probability. Vectors are columns; \(I\) is an identity matrix.
Prerequisites. The binomial law and moment-generating functions (Chapter 3), the central limit theorem and the chi-square law as a gamma law (Theorem 4.3.2, Filling the gap 4.18), maximum likelihood (Chapter 5), the generalized likelihood ratio (Section 6.5) and a little linear algebra: orthonormal bases, orthogonal matrices and projections.
pp. 483–484 The tests of Chapters 6, 7 and 9 concern parameters: is \(\mu=\mu_0\), is \(p=p_0\)? Often the real question is the form of the model. Do the phenotypes of a cross follow Mendel's ratios? Is a random number generator really uniform? Before a \(t\) test, are the data plausibly normal? A goodness-of-fit test decides whether a sample could reasonably have come from a given distribution, or from some member of a given family. The method of this chapter, due to Karl Pearson (1900), always takes the same three steps: group the observations into \(t\) classes, compute how many the model expects in each class, and reject the model if observed and expected counts disagree by more than sampling variation explains.
The chapter has three variants: the model is completely specified (Section 10.3), the model's form is specified but its parameters are estimated from the data (Section 10.4), and the "model" is the independence of two classifications of the same individuals (Section 10.5).
pp. 484–485 The binomial law counts successes in \(n\) independent trials with two outcomes. Allow each trial to end in one of \(t\) mutually exclusive outcomes \(r_1,\dots,r_t\), with \(P(r_i)=p_i\) the same at every trial and \(\sum_ip_i=1\), and let \(X_i\) be the number of trials that end in \(r_i\). Then \(X_1+\dots+X_t=n\).
The vector \((X_1,\dots,X_t)\) has the multinomial distribution
\[ P(X_1=k_1,\dots,X_t=k_t)=\frac{n!}{k_1!\,k_2!\cdots k_t!}\,p_1^{k_1}p_2^{k_2}\cdots p_t^{k_t},\qquad k_i\in\{0,1,\dots,n\},\ \ \sum_{i=1}^tk_i=n. \]The proof is the binomial one: a particular sequence with \(k_i\) outcomes of each type has probability \(\prod p_i^{k_i}\) by independence, and by Theorem 2.6.2 the number of such sequences is the multinomial coefficient \(n!/(k_1!\cdots k_t!)\).
The classes may be single values (the faces of a die) or ranges of a continuous variable; they need only be exhaustive and mutually exclusive. When they are ranges, \(p_i\) is the area under the density over the range.
Example 10.2.1 p. 485. A loaded die has \(P(\text{face } i)=ci\). Since \(\sum_{i=1}^6ci=21c=1\), \(c=1/21\). The probability that twelve throws show every face exactly twice is
\[ \frac{12!}{(2!)^6}\prod_{i=1}^6\Big(\frac i{21}\Big)^2=0.00053, \]which the book rounds to 0.0005.
Example 10.2.2 pp. 485–486. Five observations are drawn from \(f_Y(y)=6y(1-y)\), \(0\le y\le1\), and the unit interval is cut into quarters. With \(F_Y(y)=3y^2-2y^3\), the four probabilities are \(p_1=p_4=5/32\) and \(p_2=p_3=11/32\) (Figure 10.2.2), so
\[ P(X_1=1,X_2=0,X_3=3,X_4=1)=\frac{5!}{1!\,0!\,3!\,1!}\Big(\frac5{32}\Big)^2\Big(\frac{11}{32}\Big)^3=0.0198. \]fig_10_2_2.Three facts the chapter uses without comment. (a) The probabilities of Theorem 10.2.1 sum to 1. (b) If classes are merged (as in Example 10.3.1 and Case Study 10.4.2), the merged counts are multinomial with the summed probabilities. (c) \(X=\sum_{m=1}^n\xi_m\), where \(\xi_m\in\R^t\) is the indicator vector of the outcome of trial \(m\) (a single 1 in the position of the outcome, 0 elsewhere); the \(\xi_m\) are independent and identically distributed with \(\E\xi_m=p\).
Every statement here follows from one picture: each trial produces a vector with a single 1 marking its class. What is the sum of these vectors, and what happens to them when two classes are glued together?
For (a), expand \((p_1+\dots+p_t)^n\) with the multinomial theorem. Aim for: the sum of all the probabilities of Theorem 10.2.1 equals \(1^n\).
For (c), write \(\xi_m\) for the indicator vector of trial \(m\) and compute \(\E\xi_m\) and component \(i\) of \(\sum_m\xi_m\). Aim for: \(\E\xi_m=p\) and \(\sum_m\xi_{mi}=X_i\).
For (b), add the first two components of each \(\xi_m\). Is the result again the indicator of the outcome among fewer classes? Then apply (c) backwards.
(a) By the multinomial theorem (Filling the gap 2.16),
\[ (p_1+\dots+p_t)^n=\sum\frac{n!}{k_1!\cdots k_t!}\,p_1^{k_1}\cdots p_t^{k_t}, \]the sum running over all \((k_1,\dots,k_t)\) with \(\sum k_i=n\). The left side is \(1^n=1\).
(c) Trial \(m\) ends in exactly one class, so \(\xi_m\) has a single 1, in position \(i\) with probability \(p_i\); hence \(\E\xi_m=(p_1,\dots,p_t)^\T=p\). The trials are independent, so the \(\xi_m\) are. Component \(i\) of \(\sum_m\xi_m\) counts the trials ending in \(r_i\), which is \(X_i\).
(b) Merging classes \(r_1\) and \(r_2\), say, replaces each \(\xi_m\) by \(\xi'_m=(\xi_{m1}+\xi_{m2},\xi_{m3},\dots,\xi_{mt})\): still the indicator of the outcome of trial \(m\), now among the \(t-1\) classes \(r_1\cup r_2,r_3,\dots,r_t\), with probabilities \(p_1+p_2,p_3,\dots,p_t\). By (c) read backwards (a sum of iid indicator vectors is multinomial, which is Theorem 10.2.1), \((X_1+X_2,X_3,\dots,X_t)\) is multinomial with \(n\) trials and those probabilities. The same argument with "\(r_i\) or not" gives Theorem 10.2.2. ∎
If \((X_1,\dots,X_t)\) is multinomial with parameters \(n,p_1,\dots,p_t\), then \(X_i\sim\Bin(n,p_i)\). Hence \(\E(X_i)=np_i\) and \(\V(X_i)=np_i(1-p_i)\).
Classify each trial as "\(r_i\)" or "not \(r_i\)": \(X_i\) counts successes in \(n\) independent trials with success probability \(p_i\) (Theorem 3.2.1; also Question 10.2.8 by moment-generating functions).
Example 10.2.3 p. 487. Fifty exam scores are presumed \(\N(80,5^2)\); grades are A for 90 and above, B for 80–89, and so on. The class probabilities are \(P(2\le Z\le4)=0.0228\) (A), 0.4772 (B), 0.4772 (C), 0.0228 (D) and \(P(Z<-4)\approx0.00003\) (F), so the expected numbers of A, B, C, D are 1.14, 23.86, 23.86, 1.14 with variances \(50p_i(1-p_i)=1.11\), 12.47, 12.47, 1.11 (Table 10.2.1 of the book).
The book gives the means and variances of the counts but not how they vary together, which is what the proof of Pearson's theorem needs. For \(i\ne j\),
\[ \Cov(X_i,X_j)=-np_ip_j,\qquad\text{so}\qquad \V(X)=n\,\Sigma,\quad \Sigma=\diag(p)-pp^\T. \]\(\Sigma\) is singular: \(\Sigma\mathbf 1=0\), where \(\mathbf 1=(1,\dots,1)^\T\), which says that \(\sum_iX_i=n\) has variance 0.
One trial cannot land in two classes at once. What does that say about the product of two different components of one indicator vector, and how do covariances of independent trials combine?
For one trial compute \(\E(\xi_i\xi_j)\) for \(i\ne j\) and \(\E(\xi_i^2)\). Aim for: the covariance matrix \(\diag(p)-pp^\T\).
Sum over the \(n\) independent trials. Aim for: \(\Cov(X_i,X_j)=-np_ip_j\).
Compute \(\Sigma\mathbf 1\) using \(p^\T\mathbf 1=1\), and for the rank show \(a^\T\Sigma a>0\) when \(a\perp\mathbf 1\), \(a\ne0\), by reading \(a^\T\Sigma a\) as a variance.
Use the indicator vectors of Filling the gap 10.1(c). For one trial, \(\xi_i\xi_j=0\) when \(i\ne j\) (a trial cannot end in two classes) and \(\xi_i^2=\xi_i\). So \(\E(\xi_i\xi_j)=0\) and \(\Cov(\xi_i,\xi_j)=0-p_ip_j\), while \(\V(\xi_i)=p_i-p_i^2\). In matrix form the covariance of one indicator vector is \(\diag(p)-pp^\T=\Sigma\). The \(n\) trials are independent, so covariances add: \(\V(X)=n\Sigma\), whose off-diagonal entries are \(-np_ip_j\).
Finally \(\Sigma\mathbf 1=p-p(p^\T\mathbf 1)=p-p\cdot1=0\). Equivalently \(\V(\mathbf 1^\T X)=\mathbf 1^\T(n\Sigma)\mathbf 1=0\): the total \(\sum X_i=n\) does not vary. The rank of \(\Sigma\) is exactly \(t-1\) when every \(p_i>0\): for any \(a\perp\mathbf 1\) with \(a\ne0\), \(a^\T\Sigma a=\sum p_ia_i^2-(\sum p_ia_i)^2\) is the variance of a random variable taking the value \(a_i\) with probability \(p_i\), which is not constant, so \(a^\T\Sigma a>0\). ∎
The negative sign is intuitive: with \(n\) fixed, more observations in one class leave fewer for the others. The same matrix is derived in the graduate course in Filling the gap 3.6.
Given observed counts \(k_1,\dots,k_t\) with \(\sum k_i=n\), the likelihood \(\prod_ip_i^{k_i}\) is maximised over all probability vectors by \(\hat p_i=k_i/n\), uniquely. Sections 10.4 and 10.5 rely on this (the row and column proportions of a contingency table are maximum likelihood estimates).
Instead of differentiating under a constraint, compare the log-likelihood of any probability vector \(q\) with that of \(k/n\) directly. Which elementary inequality for the logarithm turns the difference into something obviously non-positive?
Write \(\frac1n\ln\big(\prod q_i^{k_i}/\prod\hat p_i^{k_i}\big)\) as \(\sum\hat p_i\ln(q_i/\hat p_i)\) over the classes with \(k_i>0\).
Apply \(\ln x\le x-1\) term by term. Aim for: the bound \(\sum q_i-1\le0\).
Trace when equality holds in both inequalities, to get uniqueness, including what happens to classes with \(k_i=0\).
Setting a derivative to zero is awkward here (the \(p_i\) are tied by \(\sum p_i=1\), and some \(k_i\) may be 0), so compare directly. Let \(q\) be any probability vector with \(q_i>0\) whenever \(k_i>0\) (otherwise its likelihood is 0). With \(\hat p_i=k_i/n\) and sums over the classes with \(k_i>0\),
\[ \frac1n\ln\frac{\prod q_i^{k_i}}{\prod\hat p_i^{k_i}}=\sum_i\hat p_i\ln\frac{q_i}{\hat p_i}\le\sum_i\hat p_i\Big(\frac{q_i}{\hat p_i}-1\Big)=\sum_iq_i-1\le0, \]using \(\ln x\le x-1\), with equality only at \(x=1\). Equality throughout forces \(q_i=\hat p_i\) for every class with \(k_i>0\), and then \(\sum_{k_i>0}q_i=1\) leaves nothing for the other classes. So \(\hat p\) is the unique maximiser. (The quantity \(\sum\hat p_i\ln(\hat p_i/q_i)\ge0\) is the Kullback–Leibler divergence; this argument is Gibbs' inequality.) ∎
For \(t=2\) this is the familiar \(\hat p=k/n\) of a binomial proportion (first-year Theorem 2.2).
See also (companion courses): Probabilistic Machine Learning, Section 2.5 (categorical and multinomial laws).
pp. 488–489 Suppose the model is completely specified: an exponential density with \(\lambda=6.3\), a normal with \(\mu=500\) and \(\sigma=100\), or simply a list of class probabilities. The hypotheses are
\[ H_0\colon p_1=p_{10},\ \dots,\ p_t=p_{t0}\qquad\text{against}\qquad H_1\colon p_i\ne p_{i0}\text{ for at least one }i, \]where for a continuous model the \(p_{i0}\) are the areas under the presumed density over the classes. Pearson's proposal (1900) is to reject \(H_0\) when the observed counts are far from the expected counts \(np_{i0}\).
(a) If \(X_1,\dots,X_t\) are the class counts of \(n\) independent trials with class probabilities \(p_1,\dots,p_t\), the random variable
\[ D=\sum_{i=1}^t\frac{(X_i-np_i)^2}{np_i} \]has approximately a \(\chi^2\) distribution with \(t-1\) degrees of freedom. For the approximation to be adequate the classes should satisfy \(np_i\ge5\) for all \(i\).
(b) With observed counts \(k_i\), \(H_0\) is rejected at level \(\alpha\) if
\[ d=\sum_{i=1}^t\frac{(k_i-np_{i0})^2}{np_{i0}}\ \ge\ \chi^2_{1-\alpha,\,t-1}. \]The book proves part (a) only for \(t=2\), says the general proof "lies beyond the scope of this text", and indicates that it goes through the limit of the moment-generating function. Part (a) is a limit theorem: "approximately" means that the distribution of \(D\) converges to \(\chi^2_{t-1}\) as \(n\to\infty\) with the \(p_i\) fixed. The four boxes below give the full story: the exact mean, the multinomial central limit theorem, the projection argument that produces \(t-1\), and how close the approximation is for moderate \(n\).
(a) For \(t=2\), \(D=Z_n^2\) exactly, with \(Z_n=(X_1-np_1)/\sqrt{np_1(1-p_1)}\), and \(D\convd\chi^2_1\). (b) For every \(t\) and every \(n\), \(\E(D)=t-1\), the mean of \(\chi^2_{t-1}\).
With two classes, \(X_2-np_2\) is just \(-(X_1-np_1)\). For the mean in general, what is \(\E(X_i-np_i)^2\) when \(X_i\) is binomial?
Substitute \(X_2=n-X_1\) and \(p_2=1-p_1\) and combine the two fractions. Aim for: \(D=(X_1-np_1)^2/(np_1(1-p_1))\).
Write \(P(D\le x)=P(Z_n\le\sqrt x)-P(Z_n<-\sqrt x)\) and squeeze the strict inequality between \(P(Z_n\le-\sqrt x-\varepsilon)\) and \(P(Z_n\le-\sqrt x)\).
Take expectations term by term. Aim for: \(\sum_i(1-p_i)=t-1\).
(a) The book's algebra: with \(X_2=n-X_1\) and \(p_2=1-p_1\), \(X_2-np_2=-(X_1-np_1)\), so
\[ D=(X_1-np_1)^2\Big(\frac1{np_1}+\frac1{n(1-p_1)}\Big)=\frac{(X_1-np_1)^2}{np_1(1-p_1)}=Z_n^2. \]By the De Moivre–Laplace theorem (Theorem 4.3.1), \(P(Z_n\le z)\to\Phi(z)\) for every \(z\). The step the book leaves implicit is from \(Z_n\) to its square. For \(x>0\) write \(c=\sqrt x\); then \(P(D\le x)=P(Z_n\le c)-P(Z_n<-c)\). The first term tends to \(\Phi(c)\). For the second, \(P(Z_n\le-c-\varepsilon)\le P(Z_n<-c)\le P(Z_n\le-c)\) for every \(\varepsilon>0\); the outer terms tend to \(\Phi(-c-\varepsilon)\) and \(\Phi(-c)\), which are as close as we like since \(\Phi\) is continuous. Hence
\[ P(D\le x)\ \to\ \Phi(\sqrt x)-\Phi(-\sqrt x)=P(Z^2\le x), \]and \(Z^2\sim\chi^2_1\) (Filling the gap 4.18, Definition 7.3.1).
(b) By Theorem 10.2.2, \(\E(X_i-np_i)^2=\V(X_i)=np_i(1-p_i)\), so
\[ \E(D)=\sum_{i=1}^t\frac{np_i(1-p_i)}{np_i}=\sum_{i=1}^t(1-p_i)=t-1. \]So \(D\) has exactly the right mean for every sample size; only its shape is approximate. ∎
A longer calculation with the factorial moments \(\E[X_i(X_i-1)\cdots]\) gives the exact variance
\[ \V(D)=2(t-1)+\frac1n\Big(\sum_{i=1}^t\frac1{p_i}-t^2-2t+2\Big), \]which tends to \(2(t-1)\), the variance of \(\chi^2_{t-1}\). The correction is large when some \(p_i\) is small: small expected counts inflate the variance and fatten the right tail. For the 1:2:1 model with \(n=93\) the variance is 3.97 against 4; for the five classes of Example 10.3.1 with \(n=40\) it is 7.94 against 8.
Let \(X\) be multinomial with parameters \(n\) and \(p\), and \(V_n=(X-np)/\sqrt n\in\R^t\). Then \(V_n\convd V\sim\N(0,\Sigma)\) with \(\Sigma=\diag(p)-pp^\T\): for every vector \(s\), \(s^\T V_n\convd\N(0,s^\T\Sigma s)\), and the joint law of \(V_n\) converges to that of the normal vector \(V\) (which may be written \(V=AZ\) with \(Z\) standard normal and \(AA^\T=\Sigma\); it has moment-generating function \(\E e^{s^\T V}=e^{s^\T\Sigma s/2}\)).
The counts are a sum of \(n\) iid indicator vectors, so their joint moment-generating function is an \(n\)-th power. Expand its logarithm to second order in \(1/\sqrt n\): which quadratic form in \(s\) survives?
Compute \(M_n(s)=\E e^{s^\T V_n}\) with \(V_n=(X-np)/\sqrt n\). Aim for: \(e^{-\sqrt n\,s^\T p}\big(\sum p_ie^{s_i/\sqrt n}\big)^n\).
Put \(m_1=\sum p_is_i\), \(m_2=\sum p_is_i^2\) and expand \(\ln M_n(s)\). Aim for: \((m_2-m_1^2)/2+O(n^{-1/2})\), and recognise \(s^\T\Sigma s\).
Fix a direction \(s\) and look at \(M_n(\lambda s)\) as the mgf of the number \(s^\T V_n\). Conclude for every linear combination, then for the vector.
Step 1 (the joint moment-generating function). By Filling the gap 10.1(c), \(s^\T X=\sum_m s^\T\xi_m\) is a sum of \(n\) independent copies of \(s^\T\xi\), which equals \(s_i\) with probability \(p_i\). Hence \(\E e^{s^\T X}=\big(\sum_ip_ie^{s_i}\big)^n\) (the case \(t=3\) is Question 10.2.8), and
\[ \begin{aligned} M_n(s)&=\E e^{s^\T V_n}\\ &=e^{-\sqrt n\,s^\T p}\Big(\sum_{i=1}^tp_ie^{s_i/\sqrt n}\Big)^n. \end{aligned} \]Step 2 (the limit). Fix \(s\) and write \(m_1=\sum p_is_i\), \(m_2=\sum p_is_i^2\). Taylor's theorem gives \(e^{x}=1+x+x^2/2+O(|x|^3)\), so \(\sum_ip_ie^{s_i/\sqrt n}=1+a_n\) with \(a_n=m_1/\sqrt n+m_2/(2n)+O(n^{-3/2})\). Since \(\ln(1+a)=a-a^2/2+O(|a|^3)\) and \(a_n^2=m_1^2/n+O(n^{-3/2})\),
\[ \ln M_n(s)=-\sqrt n\,m_1+n\Big(\frac{m_1}{\sqrt n}+\frac{m_2}{2n}-\frac{m_1^2}{2n}+O(n^{-3/2})\Big)=\frac{m_2-m_1^2}2+O(n^{-1/2}). \]And \(m_2-m_1^2=\sum p_is_i^2-(\sum p_is_i)^2=s^\T\Sigma s\). So \(M_n(s)\to e^{s^\T\Sigma s/2}\) for every \(s\in\R^t\).
Step 3 (from moment-generating functions to distributions). For a fixed direction \(s\), the moment-generating function of the number \(s^\T V_n\) at the point \(\lambda\) is \(M_n(\lambda s)\to e^{\lambda^2s^\T\Sigma s/2}\), the moment-generating function of \(\N(0,s^\T\Sigma s)\). By the continuity theorem for moment-generating functions (the tool used to prove the central limit theorem in Filling the gap 4.9), \(s^\T V_n\convd\N(0,s^\T\Sigma s)\), which is the law of \(s^\T V\). Convergence of every linear combination implies convergence of the vector (the Cramér–Wold device, a standard tool we take for granted here). ∎
Two remarks. The limit is singular (\(\Sigma\mathbf 1=0\), Filling the gap 10.2): \(\mathbf 1^\T V_n=0\) for every \(n\), and so is its limit. And this is the general multivariate central limit theorem for the iid vectors \(\xi_m\), proved in the graduate course as Theorem 5.12.
Assume every \(p_i>0\). Write the Pearson residuals as a vector,
\[ U=\Big(\frac{X_1-np_1}{\sqrt{np_1}},\dots,\frac{X_t-np_t}{\sqrt{np_t}}\Big)^\T,\qquad D=\|U\|^2=U^\T U. \]Then (i) \(U\) is always perpendicular to the unit vector \(u=(\sqrt{p_1},\dots,\sqrt{p_t})^\T\); (ii) \(U\convd\N(0,\,I-uu^\T)\), and \(I-uu^\T\) is the orthogonal projection onto the \((t-1)\)-dimensional subspace \(u^\perp\); (iii) in an orthonormal basis of \(u^\perp\) the coordinates of \(U\) converge to \(t-1\) independent standard normal variables, so \(D\convd\chi^2_{t-1}\).
\(D\) is the squared length of the residual vector \(U\). The constraint \(\sum X_i=n\) forces \(U\) to be perpendicular to one fixed unit vector. In a basis containing that vector, how many coordinates are left, and how do they behave for large \(n\)?
Compute \(u^\T U\) with \(u=(\sqrt{p_i})_i\). Aim for: 0 for every outcome.
Write \(U=P^{-1/2}V_n\) with \(P=\diag(p)\) and find the limiting covariance. Aim for: \(I-uu^\T\), and check it is a projection of rank \(t-1\).
Let \(Q\) be orthogonal with last row \(u^\T\). Compute \(Q(I-uu^\T)Q^\T\) and \(\|QU\|^2\). Aim for: \(\diag(1,\dots,1,0)\) and \(D=W_1^2+\dots+W_{t-1}^2\).
Identify the limit of \((W_1,\dots,W_{t-1})\) and apply the continuous map \(w\mapsto\sum w_j^2\).
(i) \(u^\T U=\sum_i\sqrt{p_i}\,(X_i-np_i)/\sqrt{np_i}=\frac1{\sqrt n}\big(\sum X_i-n\sum p_i\big)=\frac{n-n}{\sqrt n}=0\), for every outcome.
(ii) Let \(P=\diag(p)\). Then \(U=P^{-1/2}V_n\) with \(V_n\) as in Filling the gap 10.5. A fixed linear map preserves convergence in distribution (apply Filling the gap 10.5 to the direction \(P^{-1/2}s\)), so \(U\convd P^{-1/2}V\sim\N(0,\,P^{-1/2}\Sigma P^{-1/2})\), and
\[ P^{-1/2}\Sigma P^{-1/2}=P^{-1/2}(P-pp^\T)P^{-1/2}=I-(P^{-1/2}p)(P^{-1/2}p)^\T=I-uu^\T, \]because \(P^{-1/2}p=(p_i/\sqrt{p_i})_i=u\). Since \(\|u\|^2=\sum p_i=1\), the matrix \(\Pi=I-uu^\T\) satisfies \(\Pi^\T=\Pi\), \(\Pi^2=I-2uu^\T+u(u^\T u)u^\T=\Pi\), \(\Pi u=0\) and \(\Pi w=w\) for \(w\perp u\): it is the orthogonal projection onto \(u^\perp\), of rank \(\tr\Pi=t-\|u\|^2=t-1\).
(iii) Complete \(u\) to an orthonormal basis \(q_1,\dots,q_{t-1},u\) of \(\R^t\) (Gram–Schmidt), and let \(Q\) be the orthogonal matrix with rows \(q_1^\T,\dots,q_{t-1}^\T,u^\T\). Put \(W=QU\), so \(W_j=q_j^\T U\) for \(j\le t-1\) and \(W_t=u^\T U=0\) by (i). As \(Q\) is orthogonal, \(D=\|U\|^2=\|QU\|^2=W_1^2+\dots+W_{t-1}^2\). By (ii), \(W\convd\N(0,Q\Pi Q^\T)\), and since \(Qu=e_t\) (the last basis vector),
\[ Q\Pi Q^\T=QQ^\T-(Qu)(Qu)^\T=I-e_te_t^\T=\diag(1,\dots,1,0). \]So \((W_1,\dots,W_{t-1})\) converges to a normal vector with identity covariance; for jointly normal variables zero covariance means independence (the joint moment-generating function \(e^{\sum s_j^2/2}\) factorises), so the limit is \(t-1\) independent \(\N(0,1)\) variables \(Y_1,\dots,Y_{t-1}\). The map \(w\mapsto w_1^2+\dots+w_{t-1}^2\) is continuous, so by the continuous mapping theorem
\[ D=W_1^2+\dots+W_{t-1}^2\ \convd\ Y_1^2+\dots+Y_{t-1}^2\ \sim\ \chi^2_{t-1}, \]the last step by the definition of the chi-square law as a sum of squared independent standard normals (Definition 7.3.1, Theorem 7.3.1; equivalently, the sum of independent \(\Gam(\frac12,\frac12)\) variables, Filling the gap 4.18). ∎
Why \(t-1\), in one sentence. \(D\) is the squared length of a vector with \(t\) coordinates, but the constraint \(\sum X_i=n\) pins one direction (\(u\)) at exactly zero; in the other \(t-1\) directions the vector behaves like independent standard normals. Figure x10.1(a) shows this for \(t=3\): the residual vectors fill a plane, the cloud is round, and \(D\) is the squared distance from its centre. The same proof appears in the graduate course as Filling the gap 10.10 of Probability and Statistical Inference, with the projection fact in Filling the gap 10.9.
The generalized likelihood ratio for \(H_0\colon p=p_0\) (Definition 6.5.1) is \(\lambda=\prod_i(np_{i0}/X_i)^{X_i}\), so
\[ G=-2\ln\lambda=2\sum_{i=1}^tX_i\ln\frac{X_i}{np_{i0}},\qquad\text{and}\qquad G-D\convp0\ \text{under }H_0. \]So rejecting for large \(D\) and rejecting for small \(\lambda\) are asymptotically the same test, and \(G\convd\chi^2_{t-1}\) as well.
Write each count as its expectation times \(1+x_i\) with \(x_i\) small. Expanding \((1+x)\ln(1+x)\) to second order turns \(G\) into \(D\) plus something negligible. Why do the first-order terms vanish?
Compute \(\lambda\) and \(G=-2\ln\lambda\). Aim for: \(G=2\sum X_i\ln(X_i/(np_{i0}))\).
With \(E_i=np_{i0}\) and \(x_i=(X_i-E_i)/E_i\), write \(G=2\sum E_ih(x_i)\) with \(h(x)=(1+x)\ln(1+x)\) and expand \(h\). Aim for: \(G=2\sum E_ix_i+\sum E_ix_i^2+\text{remainder}\).
Show \(\sum E_ix_i=0\), recognise \(D\), and bound the remainder by \(\sum|X_i-E_i|^3/E_i^2\), of order \(n^{-1/2}\) in probability.
The likelihood is \(\prod p_i^{X_i}\) up to a constant. Under \(H_0\) it equals \(\prod p_{i0}^{X_i}\); its maximum over all \(p\) is at \(\hat p_i=X_i/n\) (Filling the gap 10.3). The ratio is \(\prod(p_{i0}/\hat p_i)^{X_i}=\prod(np_{i0}/X_i)^{X_i}\), which gives the formula for \(G\) (terms with \(X_i=0\) are 0).
Write \(E_i=np_{i0}\) and \(x_i=(X_i-E_i)/E_i\), so \(X_i=E_i(1+x_i)\) and \(G=2\sum_iE_i\,h(x_i)\) with \(h(x)=(1+x)\ln(1+x)\). Taylor's theorem gives, for \(|x|\le\frac12\),
\[ \Big|h(x)-x-\frac{x^2}2\Big|\le C|x|^3 \]for a constant \(C\). Now \(\sum_iE_ix_i=\sum_i(X_i-E_i)=0\) and \(\sum_iE_ix_i^2=\sum_i(X_i-E_i)^2/E_i=D\), so on the event that all \(|x_i|\le\frac12\),
\[ |G-D|\le2C\sum_iE_i|x_i|^3=2C\sum_i\frac{|X_i-E_i|^3}{E_i^2}. \]Each \(X_i-E_i\) has standard deviation of order \(\sqrt n\) (Chebyshev: \(P(|X_i-E_i|>K\sqrt n)\le p_{i0}/K^2\)), while \(E_i^2\) is of order \(n^2\); so the bound is of order \(n^{3/2}/n^2=n^{-1/2}\) with probability as close to 1 as we wish, and the event \(|x_i|\le\frac12\) has probability tending to 1 by the weak law. Hence \(G-D\convp0\), and \(G\) inherits the limit of \(D\) (Slutsky's theorem). ∎
Numerically the two are close for moderate counts: for the frizzle chickens of Question 10.3.10, \(D=0.720\) and \(G=0.737\); for Mendel's peas, \(D=0.470\) and \(G=0.475\). The general version of this equivalence (Wilks' theorem) is Theorem 10.22 of the graduate course, with the comparison in Filling the gap 10.12.
The rule \(np_{i0}\ge5\) is a rule of thumb, not a theorem. For moderate \(n\) the true size of the test, \(P(D\ge\chi^2_{0.95,\,t-1})\) under \(H_0\), can be computed exactly by adding the multinomial probabilities of every outcome in the rejection region. The results show that the rule is cautious: for Example 10.3.1 with its five unmerged classes (two expected counts 4.16) the exact size at \(n=40\) is 0.0486, against the nominal 0.05.
For moderate \(n\) there are only finitely many possible tables. If you could list them all, what would you add up to get the true probability of rejecting a true \(H_0\)?
Count the outcomes for \(t=5\), \(n=40\). Aim for: \(\binom{44}4=135{,}751\), few enough for a computer.
For each outcome compute \(d\) and its probability, and add the probabilities with \(d\ge\chi^2_{0.95,4}\). Aim for: about 0.0486.
Explain small-count failure with the variance formula: which term blows up when some \(np_i\) is small?
The outcomes are the vectors \((k_1,\dots,k_t)\) of non-negative integers with sum \(n\); there are \(\binom{n+t-1}{t-1}\) of them ("stars and bars": choose the positions of \(t-1\) bars among \(n+t-1\) places). For each, compute \(d\) and the probability of Theorem 10.2.1; the exact size is
\[ \alpha_{\rm exact}(n)=\sum_{k:\ d(k)\ge\chi^2_{0.95,\,t-1}}\frac{n!}{k_1!\cdots k_t!}\,p_{10}^{k_1}\cdots p_{t0}^{k_t}. \]For the five classes of Example 10.3.1 and \(n=40\) there are \(\binom{44}4=135{,}751\) outcomes, and the sum is 0.0486; after merging into three classes it is 0.0485. At \(n=10\) (expected counts from 1.04 to 2.96) the five-class test still has size 0.0501, while the three-class test has 0.0353: with so few observations \(D\) takes few distinct values and the size jumps around 0.05 as \(n\) changes (Figure x10.1(c)).
What goes wrong with small expected counts is visible in Filling the gap 10.4: the variance of \(D\) exceeds \(2(t-1)\) by \((\sum1/p_i-t^2-2t+2)/n\), which is large when some \(np_i\) is small, and a single class with a tiny expected count can then produce a huge term \((k_i-np_i)^2/(np_i)\). A frequently quoted refinement (Cochran, 1954) allows a few expected counts between 1 and 5 provided none is below 1 and at most a fifth are below 5. Merging classes, as the book does, is safe; but the merging should be decided from the expected counts, before looking at the observed ones. ∎
fig_x10_1.Unhorned and horned Ceriodaphnia cornuta were put into a tank with a predatory fish in the ratio 3:1. Of the 44 eaten, 40 were unhorned and 4 horned. Under \(H_0\colon p_1=\frac34,\ p_2=\frac14\) (form does not affect the risk) the expected numbers are 33 and 11, and
\[ d=\frac{(40-33)^2}{33}+\frac{(4-11)^2}{11}=1.485+4.455=5.94\ \ge\ \chi^2_{0.95,1}=3.841, \](the book prints 5.93), so \(H_0\) is rejected at \(\alpha=0.05\) (Figure 10.3.2); the p-value is 0.015. With \(t=2\) the test is the two-sided binomial test of Chapter 6 (Filling the gap 10.4(a)), and the exact binomial p-value, \(2P(X\le4)\) for \(X\sim\Bin(44,\frac14)\), is 0.015 as well. The book's "About the Data" is a lesson in interpretation: later experiments showed that the fish were selecting a larger eyespot, not the absence of horns. A goodness-of-fit test says the model is wrong; it does not say why.
fig_10_3_2.In many collections of numbers spanning several orders of magnitude, the first significant digit is \(i\) with probability
\[ p_i=\log_{10}(i+1)-\log_{10}(i),\qquad i=1,\dots,9, \tag{10.3.1} \]so about 30.1% of first digits are 1 and only 4.6% are 9 (Benford's law). Fabricated numbers tend to have first digits spread more evenly, which makes the law an auditing tool. The 355 first digits of an operating budget were 111, 60, 46, 29, 26, 22, 21, 20, 20 for digits 1 to 9. Against the Benford probabilities, \(t=9\) and
\[ d=2.49\quad(\text{book, probabilities rounded to three decimals});\qquad d=2.52\quad(\text{exact }p_i), \]both far below \(\chi^2_{0.95,8}=15.507\); the p-value is 0.96. The budget shows no sign of invented numbers. Why the law holds is the subject of the book's "About the Data" and of Filling the gap 10.9.
(a) Let \(M=\log_{10}Y-\lfloor\log_{10}Y\rfloor\in[0,1)\) be the fractional part of \(\log_{10}Y\). If \(M\sim\Unif(0,1)\), the first digit of \(Y\) follows (10.3.1) exactly. (b) For the Pareto density \(f_Y(y)=ay^{-a-1}\), \(y\ge1\),
\[ P(\text{first digit}=i)=\frac{i^{-a}-(i+1)^{-a}}{1-10^{-a}},\qquad i=1,\dots,9, \]which tends to Benford's \(\log_{10}(1+1/i)\) as \(a\to0\) but is far from it for the two densities of Figure 10.3.3: \(P(\text{first digit}=1)=5/9=0.556\) for \(a=1\) and \(0.758\) for \(a=2\), against 0.301.
The first digit of \(Y\) depends only on the fractional part of \(\log_{10}Y\). For (b), the Pareto tail \(P(Y\ge y)=y^{-a}\) makes the probability of each first digit a geometric series over the powers of ten.
Translate “first digit is \(i\)” into an interval for \(M\) and use uniformity.
Sum \(P(i10^k\le Y<(i+1)10^k)\) over \(k\ge0\). Aim for: \((i^{-a}-(i+1)^{-a})/(1-10^{-a})\).
Expand numerator and denominator to first order in \(a\), then evaluate the formula at \(a=1\), \(i=1\). Aim for: \(\log_{10}(1+1/i)\) and \(5/9\).
(a) The first digit of \(Y\) is \(i\) exactly when \(i\cdot10^k\le Y<(i+1)10^k\) for some integer \(k\), that is when \(\log_{10}i\le M<\log_{10}(i+1)\). If \(M\) is uniform this has probability \(\log_{10}(i+1)-\log_{10}i\). The book's argument (Table 10.3.3) is this one, under the assumption that \(\log Y\) is "approximately uniform" over several cycles; what matters is only that its fractional part is uniform.
(b) \(P(Y\ge y)=y^{-a}\) for \(y\ge1\). The first digit is \(i\) when \(Y\in[i\cdot10^k,(i+1)10^k)\) for some \(k\ge0\), so, summing a geometric series,
\[ P(\text{first digit}=i)=\sum_{k=0}^\infty\big[(i\,10^k)^{-a}-((i+1)10^k)^{-a}\big]=\big(i^{-a}-(i+1)^{-a}\big)\sum_{k=0}^\infty10^{-ak}=\frac{i^{-a}-(i+1)^{-a}}{1-10^{-a}}. \]As \(a\to0\), \(i^{-a}-(i+1)^{-a}=e^{-a\ln i}-e^{-a\ln(i+1)}=a\ln\frac{i+1}i+O(a^2)\) and \(1-10^{-a}=a\ln10+O(a^2)\), so the ratio tends to \(\ln\frac{i+1}i/\ln10=\log_{10}(1+\frac1i)\). For \(a=1\) and \(i=1\): \((1-\frac12)/(1-\frac1{10})=\frac59\). ∎
The lesson: a long tail is not enough; the logarithm of \(Y\) must be spread nearly evenly over many powers of ten, which for the Pareto law means a small exponent (for \(a=0.1\) the first-digit probabilities are 0.326, 0.180, 0.124, ..., already close to Benford's). Data that span many orders of magnitude, such as budgets, populations or river areas, tend to satisfy this; the scores of an exam do not.
fig_10_3_3.A software package produced forty numbers claimed to be a sample from \(f_Y(y)=6y(1-y)\). In five classes of width 0.2 the counts are 8, 8, 14, 5, 5 and the class probabilities \(F_Y(b)-F_Y(a)\) with \(F_Y(y)=3y^2-2y^3\) are 0.104, 0.248, 0.296, 0.248, 0.104, so the expected counts are 4.16, 9.92, 11.84, 9.92, 4.16. Two are below 5, so the book merges the outer pairs: counts 16, 14, 10 against 14.08, 11.84, 14.08, and
\[ d=\frac{(16-14.08)^2}{14.08}+\frac{(14-11.84)^2}{11.84}+\frac{(10-14.08)^2}{14.08}=1.84\ <\ \chi^2_{0.95,2}=5.991. \]The claim is not contradicted (p-value 0.40). Without merging, \(d=6.92\) on 4 degrees of freedom (p-value 0.14), the same conclusion; Filling the gap 10.8 shows that here the unmerged test would have had the right size (0.0486). Merging also loses information: the five-class statistic is larger because the shortage in \([0.6,0.8)\) (5 against 9.92) is partly hidden once it is pooled with the excess in \([0.8,1]\).
p. 496 Rejecting for large \(d\) is natural. But data that agree with a theory too well are also suspicious: fabricated or selectively reported data tend to fit their model more closely than chance would allow. Such data are detected by a left-tailed test: reject if \(d\le\chi^2_{\alpha,\,t-1}\) for a small \(\alpha\).
Of 556 peas from Mendel's dihybrid cross, 315, 108, 101, 32 were round-yellow, round-green, angular-yellow and angular-green, against the expected 312.75, 104.25, 104.25, 34.75 under the ratios 9:3:3:1. Then \(d=0.47\) on 3 degrees of freedom (Figure 10.3.4). In the left tail, \(P(\chi^2_3\le0.47)=0.075\): a fit at least this good happens about once in 13 honest experiments. That is not evidence of anything on its own; the case against Mendel's data (Fisher, 1936) came from many experiments together, as the next box explains.
fig_10_3_4.(a) Under \(H_0\) and for large \(n\), the test "reject if \(d\le\chi^2_{\alpha,\,t-1}\)" has size close to \(\alpha\). (b) If \(D_1,\dots,D_m\) are statistics from independent experiments with \(D_j\) approximately \(\chi^2_{\nu_j}\), then \(D_1+\dots+D_m\) is approximately \(\chi^2_{\nu_1+\dots+\nu_m}\). (c) Consequently many individually unremarkable fits can be jointly incredible: ten independent experiments, each on 3 degrees of freedom with \(d=1.0\) (left-tail probability 0.20 each), give a total of 10 on 30 degrees of freedom, with left-tail probability 0.00023.
Under \(H_0\) the left tail of \(D\) behaves like the left tail of \(\chi^2_{t-1}\). And independent chi-square statistics add up to a chi-square statistic: how do their degrees of freedom combine?
Apply convergence of distribution functions at \(c=\chi^2_{\alpha,\,t-1}\).
Multiply the mgfs of the independent statistics. Aim for: the mgf of \(\chi^2_{\nu_1+\dots+\nu_m}\).
Compute \(P(\chi^2_3\le1)\) and \(P(\chi^2_{30}\le10)\) and compare.
(a) The \(\chi^2_{t-1}\) distribution function \(F\) is continuous, so convergence in distribution gives \(P(D\le c)\to F(c)\) at every \(c\); with \(c=\chi^2_{\alpha,\,t-1}\), \(F(c)=\alpha\).
(b) For exactly chi-square variables: the moment-generating function of \(\chi^2_\nu\) is \((1-2s)^{-\nu/2}\) for \(s<\frac12\) (Filling the gap 4.18), and for independent variables moment-generating functions multiply, \(\prod_j(1-2s)^{-\nu_j/2}=(1-2s)^{-\sum\nu_j/2}\), the moment-generating function of \(\chi^2_{\sum\nu_j}\). For approximately chi-square statistics from independent experiments, the vector \((D_1,\dots,D_m)\) converges jointly to independent chi-square limits (independence is preserved), and the sum is a continuous function of the vector.
(c) \(P(\chi^2_3\le1)=0.199\) and \(P(\chi^2_{30}\le10)=0.00023\). The sum of the statistics is the natural combined measure of fit because, under the hypotheses, it is again chi-square. This is how Fisher (1936) argued that Mendel's reported results, taken over many experiments, agreed with the theory more closely than chance would usually allow. ∎
A left-tailed rejection is not proof of fraud: a very small \(d\) also arises if the trials are not independent, for instance if the counts were adjusted towards expectation or the sampling was more regular than multinomial. It says that the multinomial model, with the stated probabilities, does not describe how the numbers were produced.
See also (companion courses): Probability and Statistical Inference, Section 10.4 (Pearson's test, Mendel's peas, Theorem 10.17); the power of the test against specific alternatives is explored in the chi-square power demo of Statistical Methods for Modern Biology (preset 2).
pp. 498–499 More often the form of the model is specified (binomial, Poisson, normal) but its parameters are not. They are then estimated, "preferably with the method of maximum likelihood", and the expected counts \(n\hat p_{i0}\) computed from the fitted model. For example, if the classes start with \(r_1=[0,1.5)\) and the model is exponential, a known \(\lambda=0.4\) gives \(p_{10}=1-e^{-0.6}=0.45\); if instead \(\lambda\) is estimated by \(\lambda_e=n/\sum y_i=100/200=0.50\), the estimated probability is \(\hat p_{10}=1-e^{-0.75}=0.53\).
Suppose the model has \(s\) unknown parameters and \(\hat p_1,\dots,\hat p_t\) are the class probabilities computed with the parameters replaced by their maximum likelihood estimates. Then (a) the random variable
\[ D_1=\sum_{i=1}^t\frac{(X_i-n\hat p_i)^2}{n\hat p_i} \]has approximately a \(\chi^2\) distribution with \(t-1-s\) degrees of freedom (with \(n\hat p_i\ge5\) for all \(i\)); (b) \(H_0\) is rejected at level \(\alpha\) if \(d_1\ge\chi^2_{1-\alpha,\,t-1-s}\).
The book gives no proof and no condition on the estimate beyond "maximum likelihood". The precise statement needs to say which likelihood. The rule \(t-1-s\) holds when \(\theta\) maximises the likelihood of the grouped counts, \(\sum_ik_i\ln p_i(\theta)\) (or any estimate close enough to it, such as the minimum-\(\chi^2\) estimate). When the classes are the possible values themselves (Case Study 10.4.1) this is the ordinary maximum likelihood estimate. When the data are grouped into ranges or a tail class is pooled, the ordinary estimate from the raw data (\(\bar y\), \(s\)) is a different number, and with it \(D_1\) is slightly larger than \(\chi^2_{t-1-s}\): its limit lies between \(\chi^2_{t-1-s}\) and \(\chi^2_{t-1}\) (Chernoff and Lehmann, 1954). The next two boxes prove both statements.
Let \(p_i(\theta)>0\) be smooth in a scalar \(\theta\) and let \(\theta\) be the true value. Put \(b_i=p_i'(\theta)/\sqrt{p_i(\theta)}\) and \(J=\|b\|^2=\sum_ip_i'(\theta)^2/p_i(\theta)\) (the Fisher information of one grouped observation), assumed positive, and let \(I\ge J\) be the Fisher information of one ungrouped observation. Then
(a) with \(\tilde\theta\), the maximum likelihood estimate from the grouped counts, \(D_1\convd\chi^2_{t-2}\);
(b) with \(\hat\theta\), the maximum likelihood estimate from the raw data, \(D_1\convd\chi^2_{t-2}+\lambda Z^2\), where \(Z\sim\N(0,1)\) is independent of the \(\chi^2_{t-2}\) variable and \(\lambda=1-J/I\in[0,1]\) is the fraction of information lost by grouping.
Replacing \(\theta\) by an estimate shifts the residual vector along one fixed direction \(b\) (perpendicular to \(u\)). The grouped estimate removes that direction entirely; the raw-data estimate removes only part of it. How much variance is left along \(b\)?
Taylor-expand \(p_i(\theta^*)\) in the residuals. Aim for: \(R=U-b\sqrt n(\theta^*-\theta)+o_P(1)\), and show \(u^\T b=0\).
Grouped estimate: write its score as \(\sqrt n\,b^\T U\). Aim for: \(R\approx(I-ee^\T)U\) with covariance \(I-ee^\T-uu^\T\), rank \(t-2\).
Raw estimate: compute \(\Cov(U_i,Z_S)\). Aim for: \(b_i\), then a limiting covariance \(I-uu^\T-(J/I)ee^\T\).
Read off the eigenvalues in the basis \(q_1,\dots,q_{t-2},e,u\), and prove \(J\le I\) class by class.
Tools. Besides Filling the gap 10.6 we use the standard first-order expansion of a maximum likelihood estimate, \(\sqrt n(\hat\theta-\theta)=\frac1{I}\cdot\frac1{\sqrt n}\sum_{m=1}^nS_m+o_P(1)\), where \(S_m\) is the score (the derivative in \(\theta\) of the log-density) of observation \(m\); it comes from a Taylor expansion of the likelihood equation around \(\theta\), and is proved in the graduate course (Theorem 9.18, Filling the gap 9.9). Here \(o_P(1)\) denotes a quantity that tends to 0 in probability.
Step 1 (linearise the residuals). Let \(U\) be the residual vector with the true \(p_i(\theta)\), as in Filling the gap 10.6, and \(R\) the residual vector with an estimate \(\theta^*\) in place of \(\theta\). A first-order Taylor expansion \(p_i(\theta^*)=p_i(\theta)+p_i'(\theta)(\theta^*-\theta)+O((\theta^*-\theta)^2)\), with \(\theta^*-\theta=O_P(n^{-1/2})\) and \(n\hat p_i/(np_i)\convp1\) in the denominators, gives
\[ R_i=\frac{X_i-np_i(\theta^*)}{\sqrt{np_i(\theta^*)}}=U_i-b_i\,\sqrt n(\theta^*-\theta)+o_P(1). \]Also \(b\perp u\), because \(u^\T b=\sum_ip_i'(\theta)=\frac{\d}{\d\theta}\sum_ip_i(\theta)=0\). Let \(e=b/\|b\|\).
Step 2 (a): grouped estimate. The grouped log-likelihood \(\sum_iX_i\ln p_i(\theta)\) has score \(\sum_iX_ip_i'/p_i=\sum_i(X_i-np_i)p_i'/p_i=\sqrt n\,b^\T U\) (we subtracted \(n\sum p_i'=0\)), and information \(nJ\) per sample; its expansion is \(\sqrt n(\tilde\theta-\theta)=b^\T U/J+o_P(1)\). So
\[ R=U-\frac{bb^\T}{J}U+o_P(1)=(I-ee^\T)U+o_P(1)\ \convd\ (I-ee^\T)Y,\qquad Y\sim\N(0,I-uu^\T). \]Its covariance is \((I-ee^\T)(I-uu^\T)(I-ee^\T)=I-ee^\T-uu^\T\), using \(e\perp u\): the projection onto the \((t-2)\)-dimensional subspace perpendicular to both \(u\) and \(e\). As in Filling the gap 10.6 (an orthonormal basis \(q_1,\dots,q_{t-2},e,u\)), \(D_1=\|R\|^2\convd\chi^2_{t-2}\).
Step 3 (b): raw-data estimate. Now \(\sqrt n(\hat\theta-\theta)=Z_S/I+o_P(1)\) with \(Z_S=n^{-1/2}\sum_mS_m\). The pair \((U,Z_S)\) is a normalised sum of iid vectors, so by the multivariate central limit theorem it converges jointly to a normal vector, with \(\V(Z_S)=I\) and
\[ \Cov(U_i,Z_S)=\Cov\Big(\frac{\one\{Y\in r_i\}-p_i}{\sqrt{p_i}},S\Big)=\frac{\E[\one\{Y\in r_i\}\,S]}{\sqrt{p_i}}=\frac{p_i'(\theta)}{\sqrt{p_i}}=b_i, \]because \(\E[\one_AS]=\int_A\partial_\theta f=\frac{\d}{\d\theta}P(A)\) (differentiation under the integral) and \(\E S=0\). Then \(R=U-bZ_S/I+o_P(1)\) has limiting covariance
\[ (I-uu^\T)-\frac{2bb^\T}{I}+\frac{bb^\T}{I^2}\,I=I-uu^\T-\frac JIee^\T=(I-uu^\T-ee^\T)+\lambda\,ee^\T,\qquad\lambda=1-\frac JI. \]In the basis \(q_1,\dots,q_{t-2},e,u\) this is \(\diag(1,\dots,1,\lambda,0)\): \(t-2\) independent standard normal coordinates, one coordinate with variance \(\lambda\) (that is, \(\sqrt\lambda Z\)), and zero. So \(D_1\convd\chi^2_{t-2}+\lambda Z^2\).
Step 4 (\(0\le\lambda\le1\)). By the Cauchy–Schwarz inequality applied within each class, \(\big(\E[\one_{r_i}S]\big)^2\le\E[\one_{r_i}]\,\E[\one_{r_i}S^2]=p_i\,\E[\one_{r_i}S^2]\), so \(J=\sum_i(\E[\one_{r_i}S])^2/p_i\le\sum_i\E[\one_{r_i}S^2]=\E S^2=I\): grouping cannot create information. ∎
What it means. Estimating \(\theta\) from the counts moves the fitted model towards the data along the direction \(e\) and removes that direction completely: one degree of freedom. The raw-data estimate is not chosen to fit the counts, so it removes only the part \(1-\lambda\) of that direction. When the classes are the values themselves, \(J=I\) and \(\lambda=0\) (Case Study 10.4.1); when the classes are fine, \(\lambda\) is tiny; with four coarse classes for a normal model it reaches 0.63 (Figure x10.2(c)).
Let \(\theta\in\R^s\), let the \(t\times s\) matrix \(B\) have entries \(B_{ir}=\partial_{\theta_r}p_i(\theta)/\sqrt{p_i(\theta)}\) and rank \(s<t-1\), let \(J=B^\T B\) and let \(I\) be the full-data information matrix. (a) With the grouped maximum likelihood estimate, \(D_1\convd\chi^2_{t-1-s}\). (b) With the raw-data estimate, \(D_1\convd\chi^2_{t-1-s}+\sum_{j=1}^s\lambda_jZ_j^2\), where the \(\lambda_j\in[0,1]\) are the eigenvalues of \(I_s-I^{-1/2}JI^{-1/2}\) and the \(Z_j\) are independent \(\N(0,1)\). Hence the limit lies, in distribution, between \(\chi^2_{t-1-s}\) and \(\chi^2_{t-1}\), and the correct p-value is between the two chi-square p-values.
It is the one-parameter argument with matrices: the estimate moves the residuals inside the column space of \(B\). Which projection removes that space, and what is left when the raw-data estimate removes it only partially?
Show the columns of \(B\) are perpendicular to \(u\) by differentiating \(\sum p_i(\theta)=1\).
Grouped estimate. Aim for: limiting covariance \(I-P_B-uu^\T\), of rank \(t-1-s\).
Raw estimate. Aim for: \(I-uu^\T-BI^{-1}B^\T\); write \(B=EL\) and relate the eigenvalues inside the column space to those of \(I^{-1/2}JI^{-1/2}\).
Use \(0\le\lambda_j\le1\) to sandwich the limit between \(\chi^2_{t-1-s}\) and \(\chi^2_{t-1}\).
The argument of Filling the gap 10.11 goes through with matrices. The columns of \(B\) are perpendicular to \(u\) (differentiate \(\sum_ip_i(\theta)=1\)). Let \(P_B=B(B^\T B)^{-1}B^\T\), the projection onto the column space of \(B\).
(a) The grouped estimate satisfies \(\sqrt n(\tilde\theta-\theta)=J^{-1}B^\T U+o_P(1)\), so \(R=(I-P_B)U+o_P(1)\), with limiting covariance \((I-P_B)(I-uu^\T)(I-P_B)=I-P_B-uu^\T\), a projection of rank \(t-1-s\) (its trace is \(t-s-1\)). The orthonormal-basis argument of Filling the gap 10.6 gives \(\chi^2_{t-1-s}\).
(b) Now \(\sqrt n(\hat\theta-\theta)=I^{-1}Z_S+o_P(1)\) with \(\Cov(U,Z_S)=B\), \(\V(Z_S)=I\), so the limiting covariance of \(R=U-BI^{-1}Z_S\) is \(I-uu^\T-BI^{-1}B^\T\). Let the columns of \(E\) be an orthonormal basis of the column space of \(B\), so \(B=EL\) with \(L=E^\T B\) invertible and \(J=L^\T L\). Then
\[ I-uu^\T-BI^{-1}B^\T=(I-uu^\T-EE^\T)+E\big(I_s-LI^{-1}L^\T\big)E^\T. \]The first part is a projection of rank \(t-1-s\); the second acts inside the column space of \(B\), with eigenvalues those of \(I_s-LI^{-1}L^\T\). The matrix \(LI^{-1}L^\T\) has the same eigenvalues as \(I^{-1/2}L^\T LI^{-1/2}=I^{-1/2}JI^{-1/2}\), which lie in \([0,1]\) because \(J\le I\) (the matrix form of Step 4 above: \(a^\T Ja\le a^\T Ia\) for every \(a\), by the same Cauchy–Schwarz argument applied to \(a^\T S\)). Diagonalising gives \(\chi^2_{t-1-s}+\sum\lambda_jZ_j^2\) with \(0\le\lambda_j\le1\). Since \(0\le\sum_j\lambda_jZ_j^2\le\sum_jZ_j^2\), the limit is stochastically between \(\chi^2_{t-1-s}\) and \(\chi^2_{t-1}\). ∎
In practice the difference is usually small: for the 13 one-inch classes of Case Study 10.4.3 the two weights are 0.020 and 0.049. The rank condition (the parameters are identifiable from the class probabilities) matters: estimating a parameter that does not change the \(p_i\) costs no degree of freedom. The same theorem, with a different proof sketch, is Theorem 10.29 and Filling the gap 10.15 of the graduate course.
In 4096 player-games with exactly four official at-bats, the numbers of hits 0 to 4 occurred 1280, 1717, 915, 167, 17 times. Under a \(\Bin(4,p)\) model the maximum likelihood estimate is the overall hit rate, \(p_e=4116/16384=0.2512\) (Example 5.1.1). The estimated expected frequencies are 1287.6, 1728.0, 869.6, 194.5, 16.3 (the book's 1289.1, 1728.0, 868.6, 194.0, 16.3 use \(p=0.251\)), and
\[ d_1=\frac{(1280-1287.6)^2}{1287.6}+\dots+\frac{(17-16.3)^2}{16.3}=6.40\ <\ \chi^2_{0.95,3}=7.815, \]with \(t-1-s=5-1-1=3\) degrees of freedom (p-value 0.094). The binomial model is not rejected. Here the classes are the possible values themselves, so the grouped and raw-data estimates coincide and Theorem 10.4.1 applies exactly (\(\lambda=0\) in Filling the gap 10.11). The book's "About the Data" notes that the binomial assumptions (the same \(p\) for every player and at-bat, independence) are surely false; not rejecting a model is not proof that it is right, only that these data, at this sample size, cannot see the difference.
Over 1096 days the numbers of death notices of women over eighty in a newspaper were 0, 1, ..., 9, 10+ on 162, 267, 271, 185, 111, 61, 27, 8, 3, 1, 0 days. The maximum likelihood estimate of the Poisson mean is the average, \(\lambda_e=2364/1096=2.157\). The expected frequencies \(1096e^{-2.157}2.157^i/i!\) for 7, 8, 9 and 10+ are 5.5, 1.5, 0.4, 0.1, so these classes are pooled into "7+" (observed 12, expected 7.4), leaving \(t=8\) classes and \(8-1-1=6\) degrees of freedom:
\[ d_1=25.91\ \ge\ \chi^2_{0.95,6}=12.592 \](book: 25.98, which uses the pooled expected count 7.3, the sum of its rounded entries, instead of 7.4); the p-value is 0.0002, and the Poisson model is rejected. The discrepancies are an excess of days with no deaths (162 against 126.8) and of days with five or more (100 against 74.4): more spread than a Poisson law with a constant rate allows, as one would expect if the rate varied over the three years (epidemics, seasons).
(a) Computing the last expected frequency "by subtracting the sum of all the others from \(n\)" gives exactly \(n\,P(X\ge\text{last value})\) under the fitted model, so it is the correct class probability, not an adjustment. (b) After pooling into "7+", the maximum likelihood estimate from the eight counts is not the sample mean but the root of
\[ \sum_{i=0}^6k_i\Big(\frac i\lambda-1\Big)+k_{7+}\,\frac{\lambda^6e^{-\lambda}/6!}{P(X\ge7)}=0, \]which is \(\tilde\lambda=2.1561\) for these data (against \(\bar x=2.1569\)), giving \(d_1=25.92\). (c) The Chernoff–Lehmann weight of Filling the gap 10.11 is \(\lambda=1-J/I=0.0013\): using the sample mean is harmless here.
The pooled class has a probability like any other, \(P(X\ge7)\). Its derivative in \(\lambda\) telescopes. Why does the raw mean then fail to be the root of the grouped likelihood equation?
Show that \(n\) minus the other expected counts equals \(nP(X\ge m)\).
Differentiate the grouped log-likelihood. Aim for: \(T'(\lambda)=e^{-\lambda}\lambda^6/6!\) and the displayed equation; then compare with the equation for unpooled data.
Compute \(I=1/\lambda\) and \(J=\sum p_i'^2/p_i\) over the eight classes at \(\lambda=2.157\).
(a) The Poisson probabilities sum to 1, so \(n-\sum_{i<m}n\,p(i)=n\sum_{i\ge m}p(i)=n\,P(X\ge m)\).
(b) The grouped log-likelihood is \(\ell(\lambda)=\sum_{i=0}^6k_i(i\ln\lambda-\lambda)+k_{7+}\ln T(\lambda)+\text{const}\), with \(T(\lambda)=P(X\ge7)=1-\sum_{i=0}^6e^{-\lambda}\lambda^i/i!\). Differentiating the sum term by term telescopes: \(\frac{\d}{\d\lambda}\sum_{i=0}^6e^{-\lambda}\lambda^i/i!=-e^{-\lambda}\lambda^6/6!\), so \(T'(\lambda)=e^{-\lambda}\lambda^6/6!\), and \(\ell'(\lambda)=0\) is the displayed equation. If the pooled class held the exact values, \(k_{7+}T'/T\) would be replaced by \(\sum_{i\ge7}k_i(i/\lambda-1)\) and the root would be \(\bar x\); pooling replaces the unknown values by their conditional expectation given \(X\ge7\) under the model. Solving numerically (Newton's method from \(\bar x\)) gives 2.1561.
(c) Per observation, the full-data information is \(I=1/\lambda\) and the grouped information is \(J=\sum_ip_i'(\lambda)^2/p_i(\lambda)\) over the eight classes; at \(\lambda=2.157\), \(1-J/I=0.0013\). Almost all the information about \(\lambda\) is in the counts 0 to 6. ∎
Pooling should depend on the expected counts only (decided before looking at the data), as here: pooling chosen to make the fit look good changes the null distribution in ways the theory does not cover.
Quetelet's chest circumferences of 5738 Scottish soldiers, recorded to the nearest inch from 33 to 48, are grouped into 13 classes: \(y<34.5\), \([34.5,35.5)\), ..., \([44.5,45.5)\), \(y\ge45.5\), with observed counts 21, 81, 185, 420, 749, 1073, 1079, 934, 658, 370, 92, 50, 26. From the recorded values, \(\bar y=39.83\) and \(s=2.050\) (the book prints \(\mu_e=3.98\), a slip for 39.8, and \(\sigma_e=2.044\)). With \(s=2\) estimated parameters there are \(13-1-2=10\) degrees of freedom and \(\chi^2_{0.95,10}=18.307\). The book's expected counts (from \(\mu=39.8\), \(\sigma=2.044\) and \(z\) values rounded to two decimals) give \(d_1=37.26\); the unrounded estimates give expected counts 26.6, 72.5, 199.3, 433.8, 747.6, 1020.1, 1102.2, 943.1, 639.0, 342.8, 145.6, 49.0, 16.3 and \(d_1=35.2\). Either way the p-value is about 0.0001 and normality is rejected; about two thirds of \(d_1\) comes from the classes \([43.5,44.5)\) (92 against 146) and \(y\ge45.5\) (26 against 16), which, as the book remarks, may reflect recording errors as much as non-normality.
The grouped maximum likelihood estimates are \(\tilde\mu=39.83\) and \(\tilde\sigma=2.030\), giving \(d_1=35.5\). The grouped \(\sigma\) is smaller than the raw one: rounding to whole inches adds about \(h^2/12=1/12\) to the variance (Sheppard's correction), and \(\sqrt{2.049^2-1/12}=2.029\). The Chernoff–Lehmann weights are 0.020 and 0.049, so the raw estimates are acceptable here (Figure x10.2(b)).
fig_x10_2.See also (companion courses): Probability and Statistical Inference, Section 10.8 (goodness-of-fit tests, with an exponential example and the Chernoff–Lehmann range of p-values).
pp. 507–509 A third use of the same statistic: testing whether two classifications of the same individuals are independent. Take two traits \(A\) (categories \(A_1,A_2\)) and \(B\) (\(B_1,B_2\)). By the definition of independence, \(A\) and \(B\) are independent when
\[ P(A_i\cap B_j)=P(A_i)P(B_j)\qquad\text{for all }i,j, \tag{10.5.2} \]equivalently \(P(A_i\given B_j)=P(A_i)\) (10.5.1). A sample of \(n\) individuals gives the counts \(n_{ij}\) of a contingency table, with row totals \(R_i\) and column totals \(C_j\). Under independence the expected count of cell \((i,j)\) is \(nP(A_i)P(B_j)\); the probabilities are estimated by the sample proportions \(\hat P(A_i)=R_i/n\), \(\hat P(B_j)=C_j/n\) (10.5.3), so the estimated expected count is
\[ n\cdot\frac{R_i}n\cdot\frac{C_j}n=\frac{R_iC_j}n. \tag{10.5.4} \]Under \(H_0\colon p_{ij}=p_iq_j\), the likelihood of the table \(k_{ij}\) is maximised by \(\hat p_i=R_i/n\) and \(\hat q_j=C_j/n\), as the book asserts.
Under independence the likelihood of the table splits into a factor that involves only the row probabilities and a factor that involves only the column probabilities. Each factor is a likelihood you have already maximised.
Rewrite the null likelihood. Aim for: \(\prod_ip_i^{R_i}\prod_jq_j^{C_j}\).
Maximise each factor separately and explain why that maximises the product.
The table is multinomial with \(rc\) cells. Under \(H_0\) its likelihood is, up to the multinomial coefficient,
\[ \prod_{i,j}(p_iq_j)^{k_{ij}}=\prod_ip_i^{\sum_jk_{ij}}\prod_jq_j^{\sum_ik_{ij}}=\Big(\prod_ip_i^{R_i}\Big)\Big(\prod_jq_j^{C_j}\Big). \]The two factors involve separate parameters, each constrained only to be a probability vector, so the product is maximised by maximising each factor. Each is a multinomial likelihood (with counts \(R_i\), respectively \(C_j\), summing to \(n\)), maximised by the sample proportions (Filling the gap 10.3). ∎
pp. 509–510 In general, \(A_1,\dots,A_r\) and \(B_1,\dots,B_c\) partition the sample space, \(X_{ij}\) counts the individuals in \(A_i\cap B_j\), and \(p_i=P(A_i)\), \(q_j=P(B_j)\). The \(rc\) counts are multinomial, and each is \(\Bin(n,p_{ij})\).
(a) The random variable \(D_2=\sum_{i=1}^r\sum_{j=1}^c(X_{ij}-np_{ij})^2/(np_{ij})\) is approximately \(\chi^2\) with \(rc-1\) degrees of freedom (provided \(np_{ij}\ge5\)). (b) To test \(H_0\): the \(A_i\) are independent of the \(B_j\), compute
\[ d_2=\sum_{i=1}^r\sum_{j=1}^c\frac{(k_{ij}-n\hat p_i\hat q_j)^2}{n\hat p_i\hat q_j},\qquad n\hat p_i\hat q_j=\frac{R_iC_j}n, \]and reject at level \(\alpha\) if \(d_2\ge\chi^2_{1-\alpha,\,(r-1)(c-1)}\) (assuming every \(n\hat p_i\hat q_j\ge5\)).
Part (a) is Theorem 10.3.1 for the \(rc\) cells. For part (b) the book counts parameters: \(rc\) classes, \(r-1\) free \(p_i\) and \(c-1\) free \(q_j\) estimated, so \(rc-1-(r-1)-(c-1)=(r-1)(c-1)\) degrees of freedom. When expected counts are well below 5, rows or columns should be merged.
The parameter count is right, and it is justified by Filling the gap 10.12: the null model has \(s=(r-1)+(c-1)\) parameters, its maximum likelihood estimates (Filling the gap 10.14) are computed from the cell counts themselves, so they are the grouped estimates the degree-of-freedom rule requires, and \(d_2\convd\chi^2_{rc-1-s}=\chi^2_{(r-1)(c-1)}\) under \(H_0\), provided all \(p_i,q_j>0\). The lost dimensions can be seen directly: the residuals \(R_{ij}=(k_{ij}-E_{ij})/\sqrt{E_{ij}}\) satisfy \(r+c-1\) independent linear constraints.
The independence model is a smooth model with \((r-1)+(c-1)\) free parameters, estimated from the cell counts themselves. So the general rule applies. Can you also see the lost dimensions as linear constraints on the residual table?
Parameterise the null model and check that different \((p,q)\) give different tables and that no direction leaves all \(p_iq_j\) unchanged to first order.
Show each row and each column of \(\sqrt{E_{ij}}R_{ij}\) sums to zero. Aim for: \(r+c\) constraints.
Find the single dependency among them and subtract. Aim for: \(rc-(r+c-1)=(r-1)(c-1)\).
The conditions of Filling the gap 10.12. Parameterise the null model by \(\theta=(p_1,\dots,p_{r-1},q_1,\dots,q_{c-1})\), with \(p_r=1-\sum_{i<r}p_i\) and \(q_c=1-\sum_{j<c}q_j\); the cell probabilities \(p_iq_j\) are smooth in \(\theta\). The rank condition holds: the map \(\theta\mapsto(p_iq_j)_{i,j}\) is one-to-one (the margins of the table \(p_iq_j\) recover every \(p_i\) and \(q_j\)), and its derivative has full rank \(s\), because summing the derivative of \(p_iq_j\) over \(j\) gives the derivative of \(p_i\), and over \(i\) that of \(q_j\), so no non-zero direction \(\delta\theta\) leaves all cell probabilities unchanged to first order. The estimates of Filling the gap 10.14 maximise the likelihood of the cell counts. So the projection argument applies with \(t=rc\) and \(s=r+c-2\).
The constraints, directly. Since \(\sum_jE_{ij}=\sum_jR_iC_j/n=R_i\), each row of residuals satisfies
\[ \sum_{j=1}^c\sqrt{E_{ij}}\,R_{ij}=\sum_j(k_{ij}-E_{ij})=R_i-R_i=0, \]and likewise each column: \(\sum_i\sqrt{E_{ij}}R_{ij}=0\). These are \(r+c\) linear constraints on the \(rc\) residuals, with exactly one dependency (the sum of the row constraints equals the sum of the column constraints, both being \(\sum_{ij}(k_{ij}-E_{ij})=0\)), so \(r+c-1\) independent ones. That leaves \(rc-(r+c-1)=(r-1)(c-1)\) free directions, the degrees of freedom. ∎
A self-contained proof of the limit, in which the limiting covariance of the residual table is shown to be the Kronecker product of two projections \((I_r-aa^\T)\otimes(I_c-bb^\T)\) of rank \((r-1)(c-1)\), is in the graduate course: Theorem 15.9 and Filling the gap 15.7 of Probability and Statistical Inference.
Two film critics rated 160 films down, sideways or up. Rows Siskel, columns Ebert:
| down | sideways | up | total | |
|---|---|---|---|---|
| down | 24 (11.8) | 8 (8.4) | 13 (24.8) | 45 |
| sideways | 8 (8.4) | 13 (6.0) | 11 (17.6) | 32 |
| up | 10 (21.8) | 9 (15.6) | 64 (45.7) | 83 |
| total | 42 | 30 | 88 | 160 |
Estimated expected counts \(R_iC_j/n\) are in parentheses (e.g. \(45\cdot42/160=11.8\)). Then \(d_2=45.36\) on \((3-1)(3-1)=4\) degrees of freedom, far beyond \(\chi^2_{0.99,4}=13.277\) (p-value \(3\times10^{-9}\)): their ratings were strongly associated. The excess is on the diagonal (24, 13 and 64 against 11.8, 6.0 and 45.7): despite their on-air disputes, the two critics agreed far more often than independent raters would.
For 25 cities, \(x\) is the number of suicides per 100,000 and \(y\) a mobility index (smaller \(y\) means a more transient population). Splitting each variable at its sample mean (\(\bar x=20.76\), \(\bar y=55.99\), printed as 20.8 and 56.0) turns the pairs into a \(2\times2\) table. The book's Table 10.5.8 has 7, 4 in the high-suicide row and 3, 11 in the low-suicide row, and gives \(d_2=4.57\ge3.841\): reject independence.
But one city is in the wrong cell. Cleveland, with \(x=20.1\) (below 20.8) and \(y=52.2\) (below 56.0), is a low-suicide, low-mobility-index city, and the low-suicide row is then New York, Chicago, Detroit and Cleveland (4) against 10, not 3 against 11. The correct table, its expected counts and statistic are
\[ \begin{pmatrix}7&4\\4&10\end{pmatrix},\qquad \begin{pmatrix}4.84&6.16\\6.16&7.84\end{pmatrix},\qquad d_2=3.07\ <\ 3.841, \]with p-value 0.080: at \(\alpha=0.05\) independence is not rejected, and the book's conclusion does not stand. (The suspicion may still be right; 25 cities, cut into a \(2\times2\) table, carry little information, as Filling the gap 10.17 shows.) Dichotomising at the means also throws away most of the information in the measurements; a correlation-based analysis of the 25 pairs would be the natural alternative.
Of 185 people accused of witchcraft in 1692–93, 141 were women (14 executed) and 44 men (5 executed). As a contingency table (rows executed / not, columns female / male), the expected counts are 14.5, 4.5, 126.5, 39.5, and \(d_2=0.0749\) on 1 degree of freedom: no evidence that the outcome depended on sex. As a two-sample comparison of the proportions executed, \(14/141=0.099\) against \(5/44=0.114\), the pooled \(z\) statistic of Theorem 9.4.1 is \(z=-0.274\), and \(z^2=0.0749=d_2\) (unrounded \(z=-0.2737\)). The book states that this is no coincidence: Filling the gap 10.16 proves it.
For the table \(\begin{pmatrix}a&b\\c&d\end{pmatrix}\) with row totals \(R_1,R_2\), column totals \(C_1,C_2\) and \(n=a+b+c+d\),
\[ d_2=\frac{n(ad-bc)^2}{R_1R_2C_1C_2}=z^2,\qquad z=\frac{a/C_1-b/C_2}{\sqrt{\bar p(1-\bar p)\big(\frac1{C_1}+\frac1{C_2}\big)}},\quad\bar p=\frac{R_1}n. \]So the chi-square test at level \(\alpha\) (reject if \(d_2\ge\chi^2_{1-\alpha,1}=z_{\alpha/2}^2\)) and the two-sided \(z\) test at level \(\alpha\) (reject if \(|z|\ge z_{\alpha/2}\)) make the same decision for every table.
In a \(2\times2\) table all four observed-minus-expected differences have the same size. Find that size, and then the \(z\) statistic's numerator turns out to be the same quantity over a different denominator.
Compute \(a-R_1C_1/n\). Aim for: \((ad-bc)/n\).
Sum \(1/E_{ij}\) over the four cells. Aim for: \(d_2=n(ad-bc)^2/(R_1R_2C_1C_2)\).
Simplify the numerator and denominator of \(z\) and square. Then compare critical values: \(\chi^2_{0.95,1}\) against \(1.96^2\).
The closed form. Every cell has the same \(|k_{ij}-E_{ij}|\): for the top-left cell, \(a-R_1C_1/n=\frac{a(a+b+c+d)-(a+b)(a+c)}n=\frac{ad-bc}n\), and the other cells differ from it only in sign, because each row and each column of \(k-E\) sums to zero. Hence
\[ d_2=\frac{(ad-bc)^2}{n^2}\sum_{i,j}\frac1{E_{ij}}=\frac{(ad-bc)^2}{n^2}\cdot n\Big(\frac1{R_1}+\frac1{R_2}\Big)\Big(\frac1{C_1}+\frac1{C_2}\Big)=\frac{(ad-bc)^2}{n}\cdot\frac{n}{R_1R_2}\cdot\frac n{C_1C_2}, \]using \(\sum_{ij}\frac n{R_iC_j}=n\big(\sum_i\frac1{R_i}\big)\big(\sum_j\frac1{C_j}\big)\) and \(\frac1{R_1}+\frac1{R_2}=\frac n{R_1R_2}\). This is \(n(ad-bc)^2/(R_1R_2C_1C_2)\).
The \(z\) statistic. The numerator is \(\frac a{C_1}-\frac b{C_2}=\frac{a(b+d)-b(a+c)}{C_1C_2}=\frac{ad-bc}{C_1C_2}\). In the denominator, \(\bar p(1-\bar p)=R_1R_2/n^2\) and \(\frac1{C_1}+\frac1{C_2}=\frac n{C_1C_2}\). So
\[ z^2=\frac{(ad-bc)^2/(C_1C_2)^2}{R_1R_2\,n/(n^2C_1C_2)}=\frac{n(ad-bc)^2}{R_1R_2C_1C_2}=d_2. \]Finally \(\chi^2_{1-\alpha,1}=z_{\alpha/2}^2\) because \(Z^2\sim\chi^2_1\): \(P(Z^2\ge z_{\alpha/2}^2)=P(|Z|\ge z_{\alpha/2})=\alpha\). ∎
The equivalence is with the two-sided \(z\) test. The chi-square statistic cannot tell the direction of a difference, so a one-sided question ("is the treatment better?") needs \(z\). For the witches,
\[ \frac{185\,(14\cdot39-5\cdot127)^2}{19\cdot166\cdot141\cdot44}=0.0749. \]Under independence, the conditional distribution of a \(2\times2\) table given both of its margins does not depend on any unknown parameter: the top-left count \(a\) is hypergeometric,
\[ P(a\given R_1,R_2,C_1,C_2)=\frac{\binom{C_1}a\binom{C_2}{R_1-a}}{\binom n{R_1}}. \]This gives an exact p-value with no large-sample approximation: add the conditional probabilities of all tables with the same margins that are no more probable than the observed one. For the corrected suicide table it is 0.116 (and 0.049 for the book's miscounted table).
Under independence, row labels and column labels are drawn independently. Given both sets of totals, the table is like choosing which individuals of each column fall in row 1. What distribution counts such choices?
Write the probability of the table and of each set of margins. Aim for: a ratio of factorials free of \(p\) and \(q\).
Rewrite that ratio with binomial coefficients. Aim for: \(\binom{C_1}a\binom{C_2}{R_1-a}/\binom n{R_1}\).
For the corrected table (margins 11, 14 both ways), list the probabilities for \(a=0,\dots,11\) and add those not larger than \(P(a=7)\).
Under \(H_0\) each individual's row and column are independent, with probabilities \(p_i\) and \(q_j\). By Theorem 10.2.1 the table has probability \(\frac{n!}{a!\,b!\,c!\,d!}\,p_1^{R_1}p_2^{R_2}q_1^{C_1}q_2^{C_2}\) (collecting the powers as in Filling the gap 10.14). The row totals depend only on the row labels and the column totals only on the column labels; the two sequences of labels are independent, so \((R_1,R_2)\) and \((C_1,C_2)\) are independent binomials with probabilities \(\frac{n!}{R_1!R_2!}p_1^{R_1}p_2^{R_2}\) and \(\frac{n!}{C_1!C_2!}q_1^{C_1}q_2^{C_2}\). The table determines its margins, so dividing,
\[ P(\text{table}\given\text{margins})=\frac{R_1!\,R_2!\,C_1!\,C_2!}{n!\,a!\,b!\,c!\,d!}=\frac{\binom{C_1}a\binom{C_2}{b}}{\binom n{R_1}},\qquad b=R_1-a, \]free of \(p\) and \(q\). (Directly: choose which \(a\) of the \(C_1\) column-1 individuals and which \(b\) of the \(C_2\) column-2 individuals are in row 1, out of \(\binom n{R_1}\) equally likely choices.) Since the null conditional law is known exactly, \(P(\text{p-value}\le\alpha\given\text{margins})\le\alpha\) for every set of margins, hence also unconditionally. ∎
Case Study 10.5.2. The corrected table has margins 11, 14 (rows) and 11, 14 (columns), so \(a\) ranges over 0 to 11 with hypergeometric probabilities; the observed \(a=7\) has probability 0.074, and the tables at least as improbable (\(a\ge7\) and \(a\le2\)) have total probability 0.116. The exact test agrees with the corrected chi-square test (p-value 0.080): no significant association at the 5% level. For the book's table (margins 11, 14 and 10, 15) the exact p-value is 0.049, against 0.032 from \(\chi^2_1\); the chi-square approximation is somewhat liberal with an expected count of 4.4, which is why Cochran's rule and the exact test exist.
pp. 517–519 A goodness-of-fit question can also be asked about a single observation. Twenty laboratory measurements range from 15.6 to 91.6, plus one value of 127.6, separated from the rest by an empty stretch of 30 units. Is 127.6 just the largest value of a normal sample, or a mistake? Dixon's test assumes normal data and uses, for a suspiciously large value,
\[ r=\frac{y'_n-y'_{n-1}}{y'_n-y'_1} \](the book calls it \(r_{01}\); for a suspiciously small value the analogous ratio is \((y'_2-y'_1)/(y'_n-y'_1)\)), where \(y'_1\le\dots\le y'_n\) are the ordered observations: the gap between the two largest values as a fraction of the range. Here \(r=(127.6-91.6)/(127.6-15.6)=0.321\). The distribution of \(r\) has no closed form; its percentiles are computed numerically. For \(n=20\), 0.321 lies between the 95th percentile, 0.300, and the 98th, 0.356 (Figure x10.3): suspicious, but not dramatic. The book's advice is sound: discard an observation only with a physical reason, because the observations that do not fit a model are sometimes the first sign that the model is wrong.
(a) \(r\) does not change when every observation is replaced by \(\alpha+\beta y_i\) with \(\beta>0\). Hence, for a sample from \(\N(\mu,\sigma^2)\), the distribution of \(r\) is the same for all \(\mu\) and \(\sigma\): that of \(r\) for a standard normal sample of the same size. (b) Its percentiles can therefore be computed once, by simulating standard normal samples; 400,000 samples of size 20 give the 95th and 98th percentiles 0.300 and 0.356 and the p-value \(P(r\ge0.321)=0.036\).
The ratio compares two differences of ordered observations. What happens to it if every observation is shifted and stretched by the same positive factor, and what does that imply for normal samples with different \(\mu\) and \(\sigma\)?
Substitute \(\alpha+\beta y_i\) into the ratio and simplify.
Explain why simulating standard normal samples suffices, and estimate the standard error of a simulated tail probability near 0.036 from 400,000 samples.
(a) The map \(y\mapsto\alpha+\beta y\) with \(\beta>0\) preserves order, so the ordered values become \(\alpha+\beta y'_i\), and
\[ \frac{(\alpha+\beta y'_n)-(\alpha+\beta y'_{n-1})}{(\alpha+\beta y'_n)-(\alpha+\beta y'_1)}=\frac{\beta(y'_n-y'_{n-1})}{\beta(y'_n-y'_1)}=r. \]If \(Y_i=\mu+\sigma Z_i\) with \(Z_i\) iid \(\N(0,1)\), then \(r(Y)=r(Z)\) for every outcome, so the two have the same distribution, whatever \(\mu\) and \(\sigma>0\) are.
(b) Simulate \(m\) standard normal samples of size \(n\), compute \(r\) for each, and take empirical percentiles. By the weak law (applied to indicators), the empirical proportion of simulated values at or above 0.321 converges to the true \(P(r\ge0.321)\), with standard error \(\sqrt{0.036\cdot0.964/400000}=0.0003\). ∎
Two cautions. The test assumes that the other observations are normal; with heavy-tailed data large gaps are common. And a second large value can mask the first: if two values were near 127, \(y'_n-y'_{n-1}\) would be small and \(r\) would not flag either. Dixon (1950) proposed ratios that skip the second most extreme value for larger samples for this reason.
fig_x10_3.From the data of Table 10.5.7, Cleveland (\(x=20.1<20.8\), \(y=52.2<56.0\)) belongs to the low-suicide, low-mobility-index cell, so Table 10.5.8 should read 7, 4 / 4, 10 rather than 7, 4 / 3, 11 (the low-suicide cities with \(y<56.0\) are New York, Chicago, Detroit and Cleveland). The expected counts become 4.84, 6.16, 6.16, 7.84 and \(d_2=3.07<3.841\), p-value 0.080; Fisher's exact test gives 0.116. Independence is not rejected at \(\alpha=0.05\), contrary to the book's conclusion (see the case study and Filling the gap 10.17).
The text prints \(\mu_e=3.98\); the computation that follows uses 39.8, which is right (39.83). The sample standard deviation of the 5738 recorded values is 2.050, not 2.044. With the unrounded estimates and exact normal probabilities \(d_1=35.2\) rather than 37.26 (the printed expected counts come from \(z\) values rounded to two decimals); the conclusion is unchanged. More generally, Theorem 10.4.1's \(t-1-s\) is exact (in the limit) for estimates computed from the grouped counts; with \(\bar y\) and \(s\) from the raw data the statistic is slightly larger (Filling the gap 10.12). For this case study the difference is negligible.
After saying that each estimated parameter removes a degree of freedom, the book adds, "as we have seen in other hypothesis testing situations," that fewer degrees of freedom mean less power. For a chi-square test at a fixed departure from \(H_0\) the opposite holds: with noncentrality 10, the power of the 0.05 test is 0.761, 0.716 and 0.677 on 3, 4 and 5 degrees of freedom; fewer degrees of freedom mean a lower critical value and more power. The real price of estimating parameters is different: the fitted model is pulled towards the data and absorbs part of the departure (the component of the departure along the directions \(B\) of Filling the gap 10.12 is lost), so the noncentrality falls. Losing degrees of freedom is the compensation for that pull, not its cost.
The book presents the Pareto family as an example of distributions with "the extremely long tail necessary for Benford's law to be applicable", next to Figure 10.3.3 with \(a=1\) and \(a=2\). For those two densities the probability that the first digit is 1 is \(5/9=0.556\) and \(0.758\), not 0.301; the Pareto law approaches Benford's only as \(a\to0\) (Filling the gap 10.9).
(1) Case Study 10.3.1: \(d=1.485+4.455=5.94\) (printed 5.93). (2) Case Study 10.3.2: \(d=2.49\) comes from the Benford probabilities rounded to three decimals; the exact probabilities give 2.52. (3) Case Study 10.4.1: the expected frequencies use \(p=0.251\) rather than the computed 0.2512 (1287.6 rather than 1289.1 for no hits), and \(d_1\) is 6.40 from the book's rounded entries and 6.42 from exact counts with \(p=0.251\) (6.40 with 0.2512). (4) Case Study 10.4.2: \(d_1=25.91\) (printed 25.98, from a pooled expected count of 7.3 that adds rounded entries). (5) Case Study 10.5.3: the text compares "14/144" with 5/44, for 14/141; and \(d_2=0.0749=(-0.2737)^2\), not "0.0745 = (0.273)\(^2\)". (6) Example 10.2.1: the probability is 0.00053, printed 0.0005. None changes a conclusion.
Nine of the book's questions, restated in my own words and covering Sections 10.2 to 10.5, with complete solutions (hidden). Numbers were cross-checked with the book's answers to the odd-numbered questions; differences of rounding are noted in the solutions.
Question 10.2.7 (grouping a sample from \(3y^2\)). Fifty observations are drawn from \(f_Y(y)=3y^2\), \(0\le y\le1\), and \(X_1,\dots,X_4\) count those in \([0,\frac14)\), \([\frac14,\frac12)\), \([\frac12,\frac34)\), \([\frac34,1]\). (a) Write a formula for \(P(X_1=3,X_2=7,X_3=15,X_4=25)\). (b) Find \(\V(X_3)\).
Each class probability is an area under \(3y^2\), easy with the cdf \(y^3\). Then part (a) is Theorem 10.2.1 and part (b) Theorem 10.2.2.
Compute the four class probabilities. Aim for: \(1/64,7/64,19/64,37/64\).
Write the multinomial probability for \((3,7,15,25)\), then the variance of the binomial \(X_3\). Aim for: \(\V(X_3)\approx10.44\).
The cdf is \(F_Y(y)=y^3\), so the class probabilities are \(F(\frac14)=\frac1{64}\), \(F(\frac12)-F(\frac14)=\frac7{64}\), \(F(\frac34)-F(\frac12)=\frac{19}{64}\), \(1-F(\frac34)=\frac{37}{64}\) (they add to 1).
(a) By Theorem 10.2.1,
\[ \begin{aligned} &P(X_1=3,X_2=7,X_3=15,X_4=25)\\ &\quad=\frac{50!}{3!\,7!\,15!\,25!}\Big(\frac1{64}\Big)^3\Big(\frac7{64}\Big)^7\Big(\frac{19}{64}\Big)^{15}\Big(\frac{37}{64}\Big)^{25}\\ &\quad=0.00049. \end{aligned} \](b) By Theorem 10.2.2, \(X_3\sim\Bin(50,\frac{19}{64})\), so \(\V(X_3)=50\cdot\frac{19}{64}\cdot\frac{45}{64}=10.44\), as in the book's answer. The expected counts are \(50p_i=0.78\), 5.47, 14.84, 28.91: the first class would have to be merged before a goodness-of-fit test.
Question 10.2.8 (the trinomial moment-generating function). Let \((X_1,X_2,X_3)\) be trinomial with parameters \(n,p_1,p_2,p_3\). Show that its moment-generating function is
\[ M(t_1,t_2,t_3)=\E\,e^{t_1X_1+t_2X_2+t_3X_3}=(p_1e^{t_1}+p_2e^{t_2}+p_3e^{t_3})^n, \]and deduce that \(X_1\sim\Bin(n,p_1)\).
The expectation is a sum over all trinomial outcomes, and each term has the shape of one term of the multinomial expansion of a power. Alternatively, write the exponent as a sum over the \(n\) independent trials.
Write \(M(t_1,t_2,t_3)\) as a sum and absorb \(e^{t_ik_i}\) into \(p_i^{k_i}\). Aim for: \((p_1e^{t_1}+p_2e^{t_2}+p_3e^{t_3})^n\).
Set \(t_2=t_3=0\) and use \(p_2+p_3=1-p_1\).
By the multinomial theorem. By definition and Theorem 10.2.1,
\[ \begin{aligned} M(t_1,t_2,t_3)&=\sum_{k_1+k_2+k_3=n}\frac{n!}{k_1!k_2!k_3!}(p_1e^{t_1})^{k_1}(p_2e^{t_2})^{k_2}(p_3e^{t_3})^{k_3}\\ &=(p_1e^{t_1}+p_2e^{t_2}+p_3e^{t_3})^n, \end{aligned} \]the last step by the multinomial theorem (Filling the gap 2.16) with the three numbers \(p_ie^{t_i}\).
By indicators (the route of Filling the gap 10.5). \(t_1X_1+t_2X_2+t_3X_3=\sum_{m=1}^n(t_1\xi_{m1}+t_2\xi_{m2}+t_3\xi_{m3})\), a sum of \(n\) independent terms each equal to \(t_i\) with probability \(p_i\); each has moment-generating function factor \(\sum_ip_ie^{t_i}\), and independence multiplies them.
The marginal (Question 10.2.9). Setting \(t_2=t_3=0\),
\[ \E e^{t_1X_1}=M(t_1,0,0)=(p_1e^{t_1}+p_2+p_3)^n=(1-p_1+p_1e^{t_1})^n, \]the moment-generating function of \(\Bin(n,p_1)\). Moment-generating functions that exist near 0 determine the distribution, so \(X_1\sim\Bin(n,p_1)\), which is Theorem 10.2.2.
Question 10.3.1 (a computing formula). Show that \(\displaystyle\sum_{i=1}^t\frac{(X_i-np_i)^2}{np_i}=\sum_{i=1}^t\frac{X_i^2}{np_i}-n\).
Expand the square and use the two facts that the counts add to \(n\) and the probabilities add to 1.
Split \((X_i-np_i)^2/(np_i)\) into three sums. Aim for: \(\sum X_i^2/(np_i)-2n+n\).
Expand the square and use \(\sum_iX_i=n\) and \(\sum_ip_i=1\):
\[ \sum_i\frac{X_i^2-2np_iX_i+n^2p_i^2}{np_i}=\sum_i\frac{X_i^2}{np_i}-2\sum_iX_i+n\sum_ip_i=\sum_i\frac{X_i^2}{np_i}-2n+n. \]The right-hand side needs one subtraction instead of \(t\), and it is also the starting point for the exact mean: \(\E(X_i^2)=np_i(1-p_i)+n^2p_i^2\) gives \(\E(D)=\sum_i(1-p_i+np_i)-n=t-1\) (Filling the gap 10.4). Numerically it is less stable when \(n\) is large, because it subtracts two nearly equal large numbers.
Questions 10.3.4 and 10.3.5 (births in the small hours). Of 2650 births in a year at a maternity hospital, 494 occurred between midnight and 4 a.m. (a) Test at \(\alpha=0.05\) whether births are spread uniformly over the six four-hour periods of the day, using the goodness-of-fit test with the two classes "midnight to 4 a.m." and "other times". (b) Analyse the same data with the large-sample test for a binomial proportion of Section 6.3, and relate the two statistics.
With two classes, Pearson's \(d\) is the square of the binomial \(z\) statistic. Compute both and compare.
Expected counts under \(p=1/6\) are 441.67 and 2208.33. Aim for: \(d\approx7.44\).
Compute \(z=(494-441.67)/\sqrt{2650\cdot\frac16\cdot\frac56}\). Aim for: \(z\approx2.73\); then check \(z^2\) against \(d\) and \(1.96^2\) against 3.841.
(a) Under uniformity \(p_{10}=\frac16\), so the expected counts are \(2650/6=441.67\) and \(2208.33\); the observed are 494 and 2156. Then
\[ d=\frac{(494-441.67)^2}{441.67}+\frac{(2156-2208.33)^2}{2208.33}=6.201+1.240=7.44\ \ge\ \chi^2_{0.95,1}=3.841, \]so uniformity is rejected (p-value 0.0064): more births than expected in the small hours.
(b) Theorem 6.3.1 tests \(H_0\colon p=\frac16\) with
\[ z=\frac{494-2650/6}{\sqrt{2650\cdot\frac16\cdot\frac56}}=\frac{52.33}{19.18}=2.73, \]beyond 1.96, as in the book's answer. And \(z^2=7.44=d\): with two classes, \(d\) is exactly the square of the binomial \(z\) (Filling the gap 10.4(a)), and \(\chi^2_{0.95,1}=1.96^2\), so the chi-square test and the two-sided \(z\) test are the same test. Only the \(z\) version can be made one-sided ("more births at night").
Question 10.3.7 (the colours of M&M's). The company stated that 30% of its sweets were brown, 20% each yellow and red, and 10% each orange, blue and green. A consumer counted 455 brown, 343 yellow, 318 red, 152 orange, 130 blue and 129 green. Test at \(\alpha=0.05\) whether the counts agree with the stated proportions.
The stated percentages are a fully specified null model with six classes: compute the expected counts and Pearson's statistic.
Find \(n\) and the expected counts. Aim for: \(n=1527\), expected brown 458.1.
Add the six terms. Aim for: \(d\approx12.23\). Then say which colours drive the result.
Here \(n=1527\) and the expected counts are \(1527\times(0.3,0.2,0.2,0.1,0.1,0.1)=458.1\), 305.4, 305.4, 152.7, 152.7, 152.7. The six terms of \(d\) are 0.021, 4.629, 0.520, 0.003, 3.375, 3.678, so
\[ d=12.23\ \ge\ \chi^2_{0.95,5}=11.070, \]and \(H_0\) is rejected (p-value 0.032), as in the book's answer. The disagreement comes from three colours: too many yellow (343 against 305.4) and too few blue and green (130 and 129 against 152.7). Note what the test does and does not say: the counts are unlikely under the stated proportions if the sweets in three pounds are like a random sample, but sweets are packed in batches by colour mixture, so the multinomial (independent trials) model may itself be the weak point.
Question 10.4.2 (Supreme Court vacancies). In the 96 years 1837–1932 there were 48 vacancies on the US Supreme Court; the numbers of years with 0, 1, 2, 3 and 4 or more vacancies were 59, 27, 9, 1, 0. Test at \(\alpha=0.01\) whether the number of vacancies per year is Poisson.
Estimate the Poisson mean, compute expected counts, and pool the classes whose expected counts are small before testing. Then count the degrees of freedom carefully.
Compute \(\lambda_e\) and the expected frequencies. Aim for: \(\lambda_e=0.5\); 58.23, 29.11, 7.28, 1.21, 0.17.
Pool into 0, 1, 2+ and compute \(d_1\) with \(3-1-1\) degrees of freedom. Aim for: \(d_1\approx0.37\).
The maximum likelihood estimate is the mean, \(\lambda_e=48/96=0.5\). The expected frequencies \(96e^{-0.5}0.5^k/k!\) are 58.23, 29.11, 7.28, 1.21, and 0.17 for "4 or more" (by subtraction). The last three are small, so pool them into "2 or more": observed 10, expected 8.66. With \(t=3\) classes and \(s=1\) estimated parameter there is \(3-1-1=1\) degree of freedom, and
\[ d_1=\frac{(59-58.23)^2}{58.23}+\frac{(27-29.11)^2}{29.11}+\frac{(10-8.66)^2}{8.66}=0.010+0.153+0.208=0.37\ <\ \chi^2_{0.99,1}=6.635. \]The Poisson model fits well (p-value 0.54). Two remarks: the sample mean is the raw-data estimate; after pooling, the maximum likelihood estimate from the three counts is \(\tilde\lambda=0.509\), giving \(d_1=0.35\), and the Chernoff–Lehmann weight is only 0.035 (Filling the gap 10.13), so the choice does not matter here. And with only one degree of freedom left, the test has little power: it checks one aspect of the shape (the share of years with two or more vacancies), not the whole distribution.
Question 10.4.5 (days between shutdowns of a press). The numbers of workdays between successive shutdowns of a printing press were grouped as 0–1, 1–2, ..., 7–8 days, with counts 130, 41, 25, 8, 2, 3, 1, 1. Fit an exponential model and test it at \(\alpha=0.05\).
Only grouped data are available, so the rate must be estimated from the class counts. The book uses class midpoints; the estimate Theorem 10.4.1 assumes maximises the likelihood of the counts.
Midpoint estimate: \(\hat\lambda=1/\bar y\). Aim for: 0.823.
Use classes \([0,1)\), \([1,2)\), \([2,3)\), \([3,4)\), \([4,\infty)\). Aim for: expected 118.3, 52.0, 22.8, 10.0, 7.9 and \(d_1\approx4.18\) on 3 df.
Maximise \(\sum k_i\ln p_i(\lambda)\) numerically and recompute \(d_1\). Aim for: \(\tilde\lambda\approx0.886\).
The book's route (midpoints). Only grouped data are available. Replacing each value by its class midpoint gives \(\bar y=256.5/211=1.2156\) days and \(\hat\lambda=1/\bar y=0.823\), the estimate in the book's answer. With the classes \([0,1)\), \([1,2)\), \([2,3)\), \([3,4)\) and \([4,\infty)\) (the last pooled because its expected count is small), the class probabilities \(e^{-\lambda a}-e^{-\lambda b}\) give expected counts 118.3, 52.0, 22.8, 10.0, 7.9 against the observed 130, 41, 25, 8, 7, and
\[ d_1=4.18\ <\ \chi^2_{0.95,3}=7.815\qquad(5-1-1=3\text{ df}), \]as in the book's answer: the exponential model is not rejected (p-value 0.24).
The better estimate. The midpoint is a poor summary of an exponential class (the density is decreasing, so most of the mass of \([0,1)\) is below 0.5), and the midpoint estimate is not the one Theorem 10.4.1 assumes (Filling the gap 10.11). The maximum likelihood estimate from the five grouped counts, found by Fisher scoring, is \(\tilde\lambda=0.886\); the expected counts become 124.0, 51.1, 21.1, 8.7, 6.1 and \(d_1=3.21\) (p-value 0.36). (With unit classes all the way, the grouped likelihood is geometric and \(\tilde\lambda=\ln\frac{n+S}S\) with \(S=\sum(\text{lower class end})\times\text{count}=151\), giving 0.874.) The conclusion is the same, with a better fit: the data are consistent with shutdowns that occur at a constant rate.
Question 10.5.3 (birth order and delinquency). Of 1154 high-school girls, 111 were classed as delinquent. By birth order (oldest, in between, youngest, only child) the delinquent counts were 24, 29, 35, 23 and the others 450, 312, 211, 70. At \(\alpha=0.01\), are birth order and delinquency related?
This is a \(4\times2\) contingency table: estimated expected counts are row total times column total over \(n\), with \((4-1)(2-1)\) degrees of freedom.
Compute the totals and the expected delinquent counts. Aim for: 45.59, 32.80, 23.66, 8.95.
Compute \(d_2\). Aim for: about 42.2. Then find the cells with the largest contributions.
Row totals 474, 341, 246, 93; column totals 111 and 1043. The expected delinquent counts \(R_i\cdot111/1154\) are 45.59, 32.80, 23.66, 8.95 (and the non-delinquent ones 428.41, 308.20, 222.34, 84.05); all exceed 5. Then
\[ d_2=42.24\ \ge\ \chi^2_{0.99,3}=11.345\qquad((4-1)(2-1)=3\text{ df}), \](the book's answer: 42.25), p-value \(4\times10^{-9}\): reject independence. The cell contributions show where: only children (23 delinquent against 8.95, contribution 22.1) and youngest children (35 against 23.7, 5.4) are over-represented, oldest children under-represented (24 against 45.6, 10.2). The delinquency rates are 5.1%, 8.5%, 14.2% and 24.7%. Association is not causation: family size, parental age and other factors differ systematically between these groups.
Question 10.5.5 (aspirin and breast cancer). Among 1442 women with breast cancer, 301 had used aspirin regularly the year before diagnosis; among 1420 matched controls without breast cancer, 345 had. Set up and carry out a test at \(\alpha=0.05\).
Two groups (cases and controls) and one yes/no variable: a \(2\times2\) table, testable either as independence or as equality of two proportions.
Build the table: users 301 and 345, non-users 1141 and 1075. Aim for: expected users 325.5 and 320.5.
Compute \(d_2\) by the closed form. Aim for: \(d_2\approx4.79\); then the proportions 20.9% and 24.3% and \(z\).
State the conclusion carefully: what does a case-control comparison allow you to say about aspirin?
Arrange the data as a \(2\times2\) table, rows aspirin user / non-user, columns cases / controls: \(\begin{pmatrix}301&345\\1141&1075\end{pmatrix}\), \(n=2862\). \(H_0\): aspirin use and disease status are independent (equivalently, the proportion of users is the same among cases and controls). Expected counts: 325.5, 320.5, 1116.5, 1099.5. By Filling the gap 10.16,
\[ d_2=\frac{2862\,(301\cdot1075-345\cdot1141)^2}{646\cdot2216\cdot1442\cdot1420}=4.79\ \ge\ 3.841, \](book: 4.80), p-value 0.029: reject \(H_0\). The two-proportion form: 20.9% of cases against 24.3% of controls used aspirin, \(z=-2.19\), and \(z^2=4.79\). Regular aspirin use is less common among women with breast cancer, which is consistent with a protective effect. But this is a case-control study: the evidence is an association, open to confounding (aspirin users may differ in other health behaviours) and to recall differences between cases and controls; it is not proof that aspirin prevents the disease.
Each demonstration runs in the browser and links back to these notes. The ▶ Demo boxes above open them already set to the case under discussion.
| Demonstration | What you can see | Sections and results |
|---|---|---|
| Why t − 1 degrees of freedom | Simulated multinomial samples under a goodness-of-fit null: the Pearson residual vector in coordinates of the subspace perpendicular to \(u\), the eigenvalues of its covariance (\(t-1\) ones and a zero), the distribution of \(D\) against \(\chi^2_{t-1}\) and \(\chi^2_t\), the exact mean, variance and size. Presets: 1 1:2:1, \(n=93\); 2 \(n=12\); 3 Example 10.3.1, five classes; 4 Mendel's peas; 5 Benford's law. | Sections 10.2, 10.3; 10.4–10.6, 10.8 |
| What an estimated parameter costs | Data simulated from the fitted model of a case study, grouped, and tested with the true parameters, the grouped maximum likelihood estimate and the raw-data estimate; rejection rates, Chernoff–Lehmann weights, and both fits of the book's data. Presets: 1 Case Study 10.4.1; 2 Case Study 10.4.2; 3 Case Study 10.4.3; 4 four coarse classes, raw-data estimate; 5 the same with the grouped estimate. | Section 10.4; 10.11–10.13 |
Related demonstrations elsewhere: in the graduate course, the chi-square test of independence (Section 10.5); in Statistical Methods for Modern Biology, the Pearson statistic demo (Sections 10.3 and 10.4) and the chi-square power demo (Section 10.3).