(p(1 - p))

advertisement
Avery I. McIntosh
The Chi-Square Test
Casella/Berger, p. 511
The following problem is taken from Statistical Inf erence by Casella/Berger (2012). It delineates
the basis of the Chi-Square test of independence and the Chi-Square test of homogeneity, how the
tests are derived from first principles, how they are related to standard normal tests, and under
what circumstances one tests is preferable to another. The document then concludes with a famous
example from Joseph Lister, testing the effectiveness of carbolic acid on amputation outcomes.
10.31
Binomial data gathered from more than one population are often presented in a contingency table.
For the case of two populaitons, the table might look like this:
1
Successes S1
Failures F1
Total
n1
2
S2
F2
n2
S = S1 + S2
F = F1 + F2
n = n1 + n2
where population 1 is binomial(n1 , p1 ) with S1 successes and F1 failures, and population 2 is
binomial(n2 , p2 ) with S2 successes and F2 failures. A hypothesis that is usually of interest is H0 :
p1 = p2 vs. H1 : p1 6= p2 .
(a) Show that the test can be based on the statisic
T =
( n11
(p̂1 − p̂2 )2
+ n12 )(p̂(1 − p̂))
where p̂1 = S1 /n1 , p̂2 = S2 /n2 , and p̂ = (S1 + S2 )/(n1 + n2 ). Also show that as n1 , n2 go to infinity,
the distribution of T approaches chi-square (1 df). (This is a special case of a test known as a chi
square test of independence.)
Solution:
Under the null hypothesis, p1 = p2 = p, and thus I can invoke the central limit theorem: under
the null, the difference of p1 and p2 is just 0, and the variance of the sum is just the sum of the
variances (due to independence of the populations under H0 ). Each pi is a an average of indicator
variables, and so can be written
Pni
Xi
p̂i = i=1 ,
Xi ∈ {0, 1}
ni
Similarly, the variance of either population sample proportion is
ni
h Pni X i
1 X
ni
p(1 − p)
i=1 i
V [p̂i ] = V
= 2
V [Xi ] = 2 p(1 − p) =
ni
ni
ni i=1
ni
Avery I. McIntosh
The Chi-Square Test
Casella/Berger, p. 511
and by the central limit theorem it follows that
(p̂1 − p̂2 ) − 0
d
q
→ n(0, 1)
( n11 + n12 )(p̂(1 − p̂))
and by moment generating functions, anything which converges in distribution to a standard normal
random variable, when squared, will converge to a chi-square with 1 degree of freedom. Thus:
T =
( n11
(p̂1 − p̂2 )2
+ n12 )(p̂(1 − p̂))
d
→ χ21
as was to be shown.
(b) Another way of measuring departure from H0 is by calculating an expected f requency table.
This table is constructed by conditioning on the marginal totals and filling in the table according
to H0 : p1 = p2 , that is,
Successes
Failures
Total
Expected
1
n1 S
n1 + n2
Frequencies
2
n2 S
n1 + n2
n1 F
n1 + n2
n2 F
n1 + n2
n1
n2
Total
S1 + S2
F1 + F2
n = n1 + n2
Using the expected frequency table, a statistic T ∗ is computed by going through the cells of the
tables and computing
T∗ =
X (observed − expected)2
expected
=
n1 S 2
)
n1 +n2
n1 S
n1 +n2
(S1 −
+ ... +
n2 F 2
)
n1 +n2
n2 F
n1 +n2
(F2 −
Show algebraically that T ∗ = T , and hence that T ∗ is asymptotically chi squared.
Solution:
Since Si /ni = pi , and Fi /ni = (1 − pˆi ), it follows that in general,
ni S 2
)
n1 +n2
ni S
n1 +n2
(Si −
=
ni (p̂i − p̂)2
p̂
Avery I. McIntosh
The Chi-Square Test
and
ni F
)2
n1 +n2
ni F
n1 +n2
(Fi −
Casella/Berger, p. 511
ni ((1 − p̂i ) − (1 − p̂))2
=
1 − p̂
Thus the T ∗ statistic reduces to
n1 (p̂1 − p̂)2 n2 (p̂2 − p̂)2 n1 ((1 − p̂1 ) − (1 − p̂))2 n2 ((1 − p̂2 ) − (1 − p̂))2
+
+
+
p̂
p̂
1 − p̂
1 − p̂
The terms with n1 combine and simplify to form
n1 [(p̂1 − p̂)2 (1 − p̂) + (p̂1 − p̂)2 p̂]
n1 (p̂1 − p̂)2
=
p̂(1 − p̂)
p̂(1 − p̂)
and the terms with n2 collapse similarly to yield a final statistic of
n1 (p̂1 − p̂)2 n2 (p̂2 − p̂)2
+
p̂(1 − p̂)
p̂(1 − p̂)
Rewritting p̂ as (n1 pˆ1 + n2 p̂2 )/(n1 + n2 ), which follows from the assumption of equal population
proportions under H0 , I can plug that value into the above formula to yield
n1 (p̂1 − p̂)2 n2 (p̂2 − p̂)2
[n2 (p̂1 − p̂)/(n1 + n2 )]2 [n1 (p̂1 − p̂)/(n1 + n2 )]2
+
=
+
=
p̂(1 − p̂)
p̂(1 − p̂)
p̂(1 − p̂)
p̂(1 − p̂)
( n11
(p̂1 − p̂2 )2
=T
+ n12 )(p̂(1 − p̂))
Hence T = T ∗ , and so T ∗ ∼ χ21 .
(c) Another statistic that could be used to test the equality of p1 and p2 is
T ∗∗ = q
p̂1 − p̂2
p̂1 (1−pˆ1 )
n1
+
p̂2 (1−pˆ2 )
n2
Show that under H0 , T ∗∗ is asymptotically n(0,1), and hence its square is asymptotcally chi-square
(1 df). Furthermore, show that (T ∗∗ )2 6= T ∗ .
Solution:
Both p̂i terms are consistent for p under H0 , as E[p̂i ] = p and V[p̂i ] goes to 0 as n goes to infinity. Thus, the terms converge to p in probability. Similarly, we know that the difference
in
p sample proportions converges in distribution to a normal with mean 0 and standard error
p̂(1 − p̂)/n1 + p̂(1 − p̂)/n2 (note the lack of subscripts in the p’s). Furthermore, the ratio of
Avery I. McIntosh
The Chi-Square Test
Casella/Berger, p. 511
p
p
p̂1 (1 − pˆ1 )/n1 + p̂2 (1 − pˆ2 )/n2 to p̂(1 − p̂)/n1 + p̂(1 − p̂)/n2 goes in probability to 1. Thus, by
Slutsky’s Theorem, the product of a random sequence that goes in probability to a constant with a
sequence that goes in distribution to some distribution will itself go in distribution to the original
limiting distribution times that constant. Here, as the limiting constant, the ratio of the standard
deviation to the standard error, is just 1. This is due to the consistency of the estimators (and
by the continuous mapping theorem to include the denominator terms). So it is apparent that the
entire statistic T ∗∗ goes in distribution to a standard normal random variable, as was to be shown.
(d) Under what circumstances is one statistic preferable to the other?
Solution:
T ∗∗ is preferable for confidence intervals, as it incorporates the null and alternative values of the
popuation proportions in the statistic. For strict testing, the original T statistic is more appropriate.
(e) A famous medical experiment was conducted by Joseph Lister in the late 1800s. Mortality associated with surgery was quite high, and Lister conjectured that the use of a disinfectant, carbolic
acid, would help. Over a period of several years Lister performed 75 amputations with and without
using carbolic acid. The data are given below. Use these data to test whether the use of carbolic
acid is associated with patient mortality.
Patient Lived?
Yes
No
Carbolic Acid Used?
Yes
34
6
No
19
16
Solution:
T∗ =
X (observed − expected)2
=
expected
cells
424/15)2
(34 −
424/15
+
(19 − 371/15)2 (6 − 176/15)2 (16 − 154/15)2
+
+
= 8.495
371/15
176/15
154/15
and so I reject H0 , as 8.495 is greater than the 0.05 critical value for a χ21 . The proportion of patient
survival is different between the two treatment regimens.
Download