1G89.2228 Lect 6b
G89.2228Lecture 6b
• Generalizing from tests of quantitative variables to tests of categorical variables
• Testing a hypothesis about a single proportion– “Exact” binomial test
– Large sample test: Normal
– Chi Square test
– Making the Binomial and Large sample tests agree
• Confidence Bound on proportion– symmetric bound
– nonsymmetric bound
• Differences in proportions– Large sample test
– Confidence bounds
– Chi Square test (2 2 table)
2G89.2228 Lect 6b
Generalizing from tests of quantitative variables to
tests of categorical variables
• Binary variables (X=0 or X=1) resemble quantitative variables in several ways
• The mean or E(X) is in the range (0,1)– It is interpreted as a probability p
• The variance of X, computed the usual way, turns out to be: p(1-p)
• The sample mean, is itself normally distributed for large sample sizes
• The logic for tests of binary means works in large samples the same way it does for continuous means
pX ˆ
3G89.2228 Lect 6b
Binomial Variation
• If we know E(X) we know V(X)A B C D E F G H I
1 1 1 1 1 1 1 1 1 12 0 1 1 1 1 1 1 1 13 0 0 1 1 1 1 1 1 14 0 0 0 1 1 1 1 1 15 0 0 0 0 1 1 1 1 16 0 0 0 0 0 1 1 1 17 0 0 0 0 0 0 1 1 18 0 0 0 0 0 0 0 1 19 0 0 0 0 0 0 0 0 1
10 0 0 0 0 0 0 0 0 0MEAN 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9VARP 0.09 0.16 0.21 0.24 0.25 0.24 0.21 0.16 0.09
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Binomial Variation
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Underlying p
Va
ria
nc
e
4G89.2228 Lect 6b
Testing a hypothesis about a single proportion,
H0: E(X)=p=k• Example: Whether a population of
musicians has the same proportion of left handed people as the population at large.– Sample 20 Juilliard musicians, and find that 5
are left-handed (fictional data)
– If X=0 for right-handed and X=1 for left-handed, then X=5/20=.25.
– If p=.1, then is 5/20 an unusual event?
• Exact test: Application of binomial
=1-(.122+.270+.285+.190+.09) =.043
• One tailed inference would call H0 in question, but not two-tailed inference, although there are no relevant possibilities in the other tail!
Pr(r 5 | p .10) 1 20
r
r0
4 (.1)r (.9)20 r
5G89.2228 Lect 6b
Large sample test: Normal• While we can work with 20 subjects and
5 positive cases, what about 36, 48 or 180 subjects? Binomial calculations are often tedious.
• How about using the central limit theorem to test a z statistic?
Assuming H0 is true, we know that
• Z=.15/.067=2.24. Under the null hypothesis, such an extreme z would be observed only 13 times out of 1000 for a one tailed test, or 25 out of 1000 for a two-tailed test.
067.20
3. and 3. Thus,
09.9.*1.)1(2
XX
X pp
20/
1.25.
XX
Xz
6G89.2228 Lect 6b
Chi Square test• Z2=(2.24)2=5.0 can also be evaluated
as 2(1). On page 672 of Howell we see that this value corresponds to a p of .025. Squaring the Z makes it implicitly a two-tailed test.
• Pearson showed that this same statistic can be computed by comparing the observed values, 5,15, to the expected frequencies under H0, 2,18. Let Oi represent the observed frequency and Ei be the expected frequency.
• Pearson’s Goodness of fit Chi Square is:
0.5
18
1815
2
25 22
1
22
i i
ii
E
EO
7G89.2228 Lect 6b
Making the Binomial and Large sample tests agree
• The one tailed p value for the binomial test was .043, while for the z (or 2), it was .013. Why the difference?
• The binomial has discrete jumps in probability as we consider the possibility of 0, 1,…,5 left-handed persons out of 20. The z and 2 tests make use of continuous distributions
• Yates suggested a correction
The p value for this corrected z (one-tailed) is .031. It is called a “correction for continuity”, but its use is somewhat controversial.
86.120/3.
40/11.25.
/)1(
2/1
npp
npXZY
8G89.2228 Lect 6b
Confidence Bound on binomial proportion
• What procedure can be used to define a bound on µ that will contain the parameter 95% of the time it is used?
• So far, we have considered symmetric bounds of the form, where is the estimate of the parameter value .
• This general form does not always work well on parameters that are bounded, such as the mean of a binary variable.
• If p is in the range (.2,.8), we can usually get by with the symmetric form
• The continuity correction expands the bounds by 1/2n: (.06-.025,.44+.025)(.035, .465).
ˆˆ sz
)44,.06(.0968.*96.125.
20/)25.1(25.96.125./)ˆ1(ˆ96.1ˆ
nppp
9G89.2228 Lect 6b
A nonsymmetric CI for p
• Fleiss (1981) Statistical Methods for Rates and Proportions, 2nd Edition, gives better expressions for continuity-corrected bounds
where q=1-p and k=1.96 for 95% bounds.
• Applying these formulas gives the bounds (.096, .49)
• Which bounds to use? Simulations show Fleiss’s to be best, but they are not necessarily most often used.
PL 2np k2 1 k k2 2 1/ n 4 p(nq 1)
2(n k2 )
PU 2np k 2 1 k k2 2 1/ n 4p(nq 1)
2(n k2 )
10G89.2228 Lect 6b
Difference in proportions from independent samples
• Henderson-King & Nisbett had a binary outcome that is most appropriately analyzed using methods for categorical data. Consider their question, is choice to sit next to a Black person different in groups exposed to disruptive Black vs. White?
• In their study and . Are these numbers consistent with the same population mean?
• Consider the general large sample test statistic, which will have N(0,1), when the sample sizes are large:
2ˆ
2ˆ
21
21
ˆˆ
pp
ppz
37/11ˆ1 p 35/16ˆ 2 p
11G89.2228 Lect 6b
Differences in proportions• Under the null hypothesis, the standard
errors of the means are and , where is the population standard deviation.
• Under the null hypotheses, the common proportion is estimated by pooling the data:
The common variance is
• The Z statistic is then,
The two-tailed p-value is .16.• A 95% CI bound on the difference is
.160±(1.96)(.114) = (-.06, .38). It includes the H0 value of zero.
1/ n
2/ n
375.72
27
3537
1611ˆ
p
234.)375.1(375.ˆˆ qp
4.1114.
16.
)35/234(.)37/234(.
457.297.
z
12G89.2228 Lect 6b
Pearson Chi Square for2 2 Tables
• The z test statistic (e.g. for the difference of two proportions) is a standard normal
• z2 is distributed as 2 with 1 degree of freedom
• From the example, 1.42=1.96, p is between .1 and .25, and this is effectively a 2-tailed test
• Pearson’s calculation for this test statistic is:
where Oi is an observed frequency and Ei is the expected frequency given the null hypothesis of equal proportions.
n
i i
ii
E
EO
1
22
13G89.2228 Lect 6b
Expected values for no association
• From the example: p1=11/37=.297, and
p2=16/35=.457
• The expected frequencies are based on a pooled
p=(11+16)/(37+35)=.375
14G89.2228 Lect 6b
Chi square test of independence vs.
association, continuedObserved FrequencyExpected FrequencyJoint probability
BlackConfederate
WhiteConfederate
Chose Black 1113.875.193
1613.125.182
27.375
Avoided Black 2623.125.321
1921.875.304
45.625
37.514
35.486
72
• Marginal probabilities = pooled
• Expected joint probabilities|H0 = product of marginals (e.g. .193 =.375*.514)
• Ei = expected joint probability * n (e.g. 13.875 = .193*72=27*37/72)