Goodness of Fit Tests: Homogeneity Mathematics 47: Lecture 35 Dan Sloughter Furman University May 11, 2006 Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 1 / 13
Testing for homogeneity Suppose we have c random samples from discrete distributions each having the same r possible outcomes. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 2 / 13
Testing for homogeneity Suppose we have c random samples from discrete distributions each having the same r possible outcomes. Let p ij = probability of outcome i for the jth distribution, where i = 1, 2,..., r and j = 1, 2,..., c. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 2 / 13
Testing for homogeneity Suppose we have c random samples from discrete distributions each having the same r possible outcomes. Let p ij = probability of outcome i for the jth distribution, where i = 1, 2,..., r and j = 1, 2,..., c. Let p j = (p 1j, p 2j,..., p rj ) for j = 1, 2,..., c. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 2 / 13
Testing for homogeneity Suppose we have c random samples from discrete distributions each having the same r possible outcomes. Let p ij = probability of outcome i for the jth distribution, where i = 1, 2,..., r and j = 1, 2,..., c. Let p j = (p 1j, p 2j,..., p rj ) for j = 1, 2,..., c. We want to test H 0 : p 1 = p 2 = = p c H A : p j p k for some j k. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 2 / 13
Testing for homogeneity Suppose we have c random samples from discrete distributions each having the same r possible outcomes. Let p ij = probability of outcome i for the jth distribution, where i = 1, 2,..., r and j = 1, 2,..., c. Let p j = (p 1j, p 2j,..., p rj ) for j = 1, 2,..., c. We want to test Let H 0 : p 1 = p 2 = = p c H A : p j p k for some j k. n ij = number of observations of outcome i in sample j n i+ = n i1 + n i2 + + n ic = number of observations of outcome i n +j = n 1j + n 2j + + n rj = size of sample j n = n 1+ + n 2+ + + n r+ = n +1 + n +2 + + n +c = total number of observations. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 2 / 13
Testing for homogeneity (cont d) We may summarize this information in a contingency table as follows. 1 2 c Total 1 n 11 n 12 n 1c n 1+ 2 n 21 n 22 n 2c n 2+........ r n r1 n r2 n rc n r+ Total n +1 n +2 n +c n Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 3 / 13
Testing for homogeneity (cont d) Under H 0, the maximum likelihood estimator of the probability of outcome i is n i+ n. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 4 / 13
Testing for homogeneity (cont d) Under H 0, the maximum likelihood estimator of the probability of outcome i is n i+ n. And so the expected number of observations of outcome i in sample j is e ij = n +j ni+ n = n i+n +j. n Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 4 / 13
Testing for homogeneity (cont d) Under H 0, the maximum likelihood estimator of the probability of outcome i is n i+ n. And so the expected number of observations of outcome i in sample j is e ij = n +j ni+ n = n i+n +j. n We may now evaluate either or 2 log(λ) = 2 Q = r r i=1 j=1 c i=1 j=1 c n ij log (n ij e ij ) 2 e ij. ( nij e ij ) Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 4 / 13
Testing for homogeneity (cont d) Note: We initially have c(r 1) degrees of freedom (adding together r 1 degrees of freedom for each of the c samples) and have estimated r 1 parameters. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 5 / 13
Testing for homogeneity (cont d) Note: We initially have c(r 1) degrees of freedom (adding together r 1 degrees of freedom for each of the c samples) and have estimated r 1 parameters. Hence we have degrees of freedom. c(r 1) (r 1) = (r 1)(c 1) Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 5 / 13
Testing for homogeneity (cont d) Note: We initially have c(r 1) degrees of freedom (adding together r 1 degrees of freedom for each of the c samples) and have estimated r 1 parameters. Hence we have degrees of freedom. c(r 1) (r 1) = (r 1)(c 1) That is, under H 0, both 2 log(λ) and Q are approximately χ 2 ((r 1)(c 1)). Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 5 / 13
Example Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 6 / 13
Example When Jane Austen died in 1817, she left the novel Sanditon unfinished, but with a summary of the rest. This was completed by an admirer, and then published. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 6 / 13
Example When Jane Austen died in 1817, she left the novel Sanditon unfinished, but with a summary of the rest. This was completed by an admirer, and then published. In 1978, A. Q. Morton published some statistical studies comparing the writings of Austen and the person who completed Sanditon. Morton counted the occurrences of a, an, this, that, with, and without in chapters 1 and 3 of Sense and Sensibility; chapters 1, 2, and 3 of Emma; and chapters 1 and 6 of Sanditon (written by Austen), and also the occurrences of these words in chapters 12 and 24 of Sanditon (not written by Austen). Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 6 / 13
Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 7 / 13
The results: Word Austen Imitator Total a 434 83 517 an 62 29 91 this 86 15 101 that 236 22 258 with 161 43 204 without 38 4 42 Total 1017 196 1213 Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 7 / 13
Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 8 / 13
The expected frequencies are e 11 = (1017)(517) 1213 = 433.46, e 12 = (196)(517) 1213 = 83.54, e 21 = (1017)(91) = 76.30, e 22 = (196)(91) = 14.70, 1213 1213 and so on, giving us the following table of expected frequencies: Word Austen Imitator Total a 433.46 83.54 517.00 an 76.30 14.70 91.00 this 84.68 16.32 101.00 that 216.31 41.69 258.00 with 171.04 32.96 204.00 without 35.21 6.79 42.00 Total 1017.00 196.00 1213.00 Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 8 / 13
Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 9 / 13
Evaluating our test statistics, we find either 2 log(λ) = 31.75 or q = 32.83. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 9 / 13
Evaluating our test statistics, we find either 2 log(λ) = 31.75 or q = 32.83. If U is χ 2 (5), we have either p-value = P(U 31.75) = 0.000006583 or p-value = P(U 32.83) = 0.000004068. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 9 / 13
Evaluating our test statistics, we find either 2 log(λ) = 31.75 or q = 32.83. If U is χ 2 (5), we have either p-value = P(U 31.75) = 0.000006583 or p-value = P(U 32.83) = 0.000004068. Hence we may conclude that the imitator has not been successful in imitating this aspect of Austen s style. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 9 / 13
Example (Doll and Hill Cancer Study) Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 10 / 13
Example (Doll and Hill Cancer Study) In a study of patients in London hospitals in 1948 and 1949, Doll and Hill categorized each of 709 lung cancer patients and 709 control patients (that is, patients who did not have lung cancer) as either a smoker or a non-smoker. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 10 / 13
Example (Doll and Hill Cancer Study) In a study of patients in London hospitals in 1948 and 1949, Doll and Hill categorized each of 709 lung cancer patients and 709 control patients (that is, patients who did not have lung cancer) as either a smoker or a non-smoker. Results of the study: Cancer Control Total Non-smoker 21 59 80 Smoker 688 650 1338 Total 709 709 1418 Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 10 / 13
Example (Doll and Hill Cancer Study) In a study of patients in London hospitals in 1948 and 1949, Doll and Hill categorized each of 709 lung cancer patients and 709 control patients (that is, patients who did not have lung cancer) as either a smoker or a non-smoker. Results of the study: Cancer Control Total Non-smoker 21 59 80 Smoker 688 650 1338 Total 709 709 1418 The data raises the following question: Are the 38 additional non-smokers in the control group due to randomness, or to a higher rate of smoking among people with lung cancer than among those without lung cancer? Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 10 / 13
Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 11 / 13
The expected frequencies are: Cancer Control Total Non-smoker 40 40 80 Smoker 669 669 1338 Total 709 709 1418 Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 11 / 13
The expected frequencies are: Cancer Control Total Non-smoker 40 40 80 Smoker 669 669 1338 Total 709 709 1418 And so 2 log(λ) = 19.87802 and q = 19.12922, giving p-values of 0.00000825 and 0.00001222, respectively. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 11 / 13
The expected frequencies are: Cancer Control Total Non-smoker 40 40 80 Smoker 669 669 1338 Total 709 709 1418 And so 2 log(λ) = 19.87802 and q = 19.12922, giving p-values of 0.00000825 and 0.00001222, respectively. Hence we have very strong evidence for rejecting the hypothesis that the rate of smoking among the two groups is the same. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 11 / 13
Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 12 / 13
Note: We could also perform this test as a two-sample test for the equality of the probability of success in two independent Bernoulli populations. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 12 / 13
Note: We could also perform this test as a two-sample test for the equality of the probability of success in two independent Bernoulli populations. That is, let p X be the proportion of non-smokers in the cancer population and let p Y be the proportion of non-smokers in the control population. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 12 / 13
Note: We could also perform this test as a two-sample test for the equality of the probability of success in two independent Bernoulli populations. That is, let p X be the proportion of non-smokers in the cancer population and let p Y be the proportion of non-smokers in the control population. We want to test H 0 : p X = p Y H A : p X p Y. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 12 / 13
Note: We could also perform this test as a two-sample test for the equality of the probability of success in two independent Bernoulli populations. That is, let p X be the proportion of non-smokers in the cancer population and let p Y be the proportion of non-smokers in the control population. We want to test Now H 0 : p X = p Y H A : p X p Y. ˆp X = 21 709 = 0.02962, ˆp Y = 59 80 = 0.08322, ˆp = 709 1418 = 0.05642. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 12 / 13
Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 13 / 13
Hence z = ˆp X ˆp y ˆp(1 ˆp) ( 1 709 + 1 ) = 4.373697. 709 Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 13 / 13
Hence z = ˆp X ˆp y ˆp(1 ˆp) ( 1 709 + 1 ) = 4.373697. 709 This yields a p-value of 0.00001222, the same as for q above. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 13 / 13
Hence z = ˆp X ˆp y ˆp(1 ˆp) ( 1 709 + 1 ) = 4.373697. 709 This yields a p-value of 0.00001222, the same as for q above. Indeed: z 2 = 19.12922 = q. Dan Sloughter (Furman University) Goodness of Fit Tests: Homogeneity May 11, 2006 13 / 13