Download AMS 572 Lecture Note 7

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
AMS 572 Lecture Notes #11
October 31st, 2011
Ch. 9. Categorical Data Analysis
Exact test on one population proportion:
Data: sample of n, X are # of “Successes”, n-X are # of “Failures”
n
X ~ B(n, p) , P( X  x)    p x (1  p)n  x , x  0,1, 2,
 x
,n
 H 0 : p  p0
 H a : p  p0
(1) 
n
n
p  value  P( X  x | H 0 : p  p0 )     p0i (1  p0 ) n i
ix  i 
 H 0 : p  p0
 H a : p  p0
(2) 
x
n
p  value  P( X  x | H 0 : p  p0 )     p0i (1  p0 ) n i
i 0  i 
 H 0 : p  p0
 H a : p  p0
(3) 
p  value  2*min{P( X  x | H 0 ), P( X  x | H 0 )} .
1
Inference on Two Population Proportions: p ,
1
p2
Independent samples, both are large
e.g. Suppose we wish to compare the proportions of smokers among male
and female students in SBU.
Two large independent samples:
Population 1: p1
Population 2: p2
Sample 1: n1 , x1 , n1  x1
Sample 2: n2 , x2 , n2  x2
( x1  5, n1  x1  5 , x2  5, n2  x2  5 )
① Point estimator: pˆ1  pˆ 2 
② By CLT,
pˆ1 ~ N ( p1 ,
X1 X 2

n1 n2
p1 (1  p1 )
)
n1
pˆ 2 ~ N ( p2 ,
p2 (1  p2 )
)
n2
Two samples are independent
p1 (1  p1 ) p2 (1  p2 )

)
n1
n2
 pˆ1  pˆ 2 ~ N ( p1  p2 ,
③ P.Q. for p1  p2 :
Z
Z* 
pˆ1  pˆ 2  ( p1  p2 )
~ N (0,1)
p1 (1  p1 ) p2 (1  p2 )

n1
n2
pˆ1  pˆ 2  ( p1  p2 )
~ N (0,1)
pˆ1 (1  pˆ1 ) pˆ 2 (1  pˆ 2 )

n1
n2
not P.Q.
 P.Q.
④ 100(1-)% large samples CI for p1  p2 :
1    P( Z   Z *  Z  )  P( pˆ1  pˆ 2  Z   S  p1  p2  pˆ1  pˆ 2  Z   S )
2
2
2
2
2
pˆ1 (1  pˆ1 ) pˆ 2 (1  pˆ 2 )

n1
n2
Here, S 
⑤ Test
 H : p  p2  
General case:  0 1
 H a : p1  p2  
T0 : Z 0 
H0
pˆ1  pˆ 2  
~ N (0,1)
pˆ1 (1  pˆ1 ) pˆ 2 (1  pˆ 2 )

n1
n2
p-value=P(Z≥ Z 0 )
At the significance level  , we reject H 0 if Z0  Z and p-value<α.
When  =0, one often uses the following test statistic
Z* 
H0
pˆ1  pˆ 2  0
~ N (0,1)
1 1
pˆ (1  pˆ )(  )
n1 n2
here pˆ 
n1 pˆ1  n2 pˆ 2 X 1  X 2

n1  n2
n1  n2
Example 1. A random sample of Democrats and a random sample of Republicans were
polled on an issue. Of 200 Republicans, 90 would vote yes on the issue; of 100
democrats, 58 would vote yes. Let p1 and p2 denote respectively the proportions of all
Democrats or all Republicans who would vote yes on this issue.
(a) Construct a 95% confidence interval for (p1 - p2)
(b) Can we say that more Democrats than Republicans favor the issue at the 1%
level of significance? Please report the p-value.
(c) Please write up the entire SAS program necessary to answer question raised in
(b). Please include the data step.
Solution:
58
 0.58, n1  100, x1  58, n1  x1  42.
(a) Democrats: pˆ1  100
90
 0.45, n2  200, x2  90, n2  x2  110.
Republicans: pˆ 2  200
3
The 100(1-α)% confidence interval for (p1 - p2) is

 pˆ 1  pˆ 2  Z 

2

pˆ 1 1  pˆ 1  pˆ 2 1  pˆ 2 

, pˆ 1  pˆ 2  Z 
n1
n2
2
pˆ 1 1  pˆ 1  pˆ 2 1  pˆ 2  



n1
n2

After plugging in Z0.025 = 1.96 etc., we found the 95% CI to be [0.01, 0.25]
(b) Hypotheses are H 0 : p1  p2 v.s H a : p1  p2 .
z0 
pˆ 
x1  x2
58  90

.
n1  n2 100  200
pˆ1  pˆ 2
0.58  0.45

 2.12 .
pˆ (1  pˆ )(1/ n1  1/ n2 )
0.49  0.51(1/100  1/ 200)
p  value  P( z  z0 )  0.017  0.01 .
We cannot reject H 0 at   0.01 . Therefore, Democrats favor the issue as same as
Republicans at the 1% significance level.
(c) SAS code:
Data Poll;
Input Party $ outcome $ count;
Datalines;
Republican yes 90
Republican no 110
Democrats yes 58
Democrats no 42
;
Run;
Proc freq data=poll;
Tables party*outcome/chisq;
Weight count;
Run;
Output:
The SAS System
The FREQ Procedure
Table of Party by outcome
Party
outcome
Frequency‚
4
Percent
‚
Row Pct
‚
Col Pct
‚no
‚yes
‚
Total
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Democrat ‚
42 ‚
58 ‚
100
‚
14.00 ‚
19.33 ‚
33.33
‚
42.00 ‚
58.00 ‚
‚
27.63 ‚
39.19 ‚
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Republic ‚
110 ‚
90 ‚
200
‚
36.67 ‚
30.00 ‚
66.67
‚
55.00 ‚
45.00 ‚
‚
72.37 ‚
60.81 ‚
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Total
152
148
300
50.67
49.33
100.00
Statistics for Table of Party by outcome
Statistic
DF
Value
Prob
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Chi-Square
1
4.5075
0.0337
Likelihood Ratio Chi-Square
1
4.5210
0.0335
Continuity Adj. Chi-Square
1
4.0024
0.0454
Mantel-Haenszel Chi-Square
1
4.4924
0.0340
Phi Coefficient
Contingency Coefficient
Cramer's V
-0.1226
0.1217
-0.1226
5
Fisher's Exact Test
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Cell (1,1) Frequency (F)
42
Left-sided Pr <= F
0.0226
Right-sided Pr >= F
0.9877
Table Probability (P)
0.0103
Two-sided Pr <= P
0.0377
Sample Size = 300
6
Inference on several proportions—the Chi-square test
(large sample)
Def. Multinomial Experiment.
We have a total of n trials (sample size=n)
① For each trial, it will result in 1 of k possible outcomes.
② The probability of getting outcome i is pi , and
k
 p =1
i 1
i
③ These trials are independent.
Example 2. Previous experience indicates that the probability of obtaining 1 healthy calf
from a mating is 0.83. Similarly, the probabilities of obtaining 0 and 2 healthy calves are
0.15 and 0.02 respectively. If the farmer breeds 3 dams from the herd, find the probability
of getting exact 3 health calves.
Def. Multinomial Distribution
Let X i be the number of trials resulted in i-th category out of a total of n trials and pi
be the probability of getting i-th category outcome, then
P( X 1  x1 , X 2  x2 ,..., X k  xk ) 
n!
p1x1 ... pk xk
x1 ! x2 !...xk !
Solution:
P(exact 3 health calves)= P( X1  1, X 2  1, X 3  1) + P( X1  0, X 2  3, X 3  0)
=0.015+0.572=0.59
*Relations to the Binomial Distribution (k=2)
Category
1
2
Probability
p1 =p
p2 =1-p
# trials
X1 =x
X 2 =n-x
7
 P( X 1  x, X 2  n  x) 
n!
p1x1 p2 x2  ( nx ) p x (1  p) n x
x !(n  x)!
Chi-square goodness of fit test
Example 3. Gregor Mendel (1822-1884) was an Austrian monk whose genetic theory is
one of the greatest scientific discovery of all time. In his famous experiment with garden
peas, he proposed a genetic model that would explain inheritance. In particular, he
studied how the shape (smooth or wrinkled) and color (yellow or green) of pea seeds are
transmitted through generations. His model shows that the second generation of peas
from a certain ancestry should have the following distribution.
wrinkledgreen
Theoretical
probabilities
p1 
1
16
wrinkledyellow
p2 
3
16
smoothgreen
p3 
3
16
smoothyellow
p4 
9
16
n=556
General test:
Test whether the theoretical probability is correct
0
0
0
 H 0 : p1  p1 , p2  p2 ,..., pk  pk

 H a : H 0 is not true
k
T.S
W0  
i 1
( xi  ei ) 2 H0 2
~  k 1
ei
where xi is the observed number of observations in category i
ei is the expected count of the i-th category , ei  n  pi 0
At the significance level α, reject H 0 iff W0  k21,upper ,
8
Solution:
wrinkled-green
Theoretical
probabilities
p1 
Observed count out
of 556
X1 =31
Expected counts
wrinkledyellow
1
16
e1  556 
p2 
1
=34.75
16
3
16
smoothgreen
p3 
3
16
smoothyellow
p4 
9
16
X 2 =102
X 3 =108
X 4 =315
e2 =104.25
e3 =104.25
e4 =312.75
1
3
3
9

 H 0 : p1  , p2  , p3  , p4 
16
16
16
16

 H a : H 0 is not true
k
T.S
W0  
i 1
( xi  ei ) 2 H0 2
~  k 1
ei
2
=7.815
 0.604 < 3,0.05,upper
 At significance level 0.05, we cannot reject H 0
SAS Code:
DATA GENE;
INPUT @1 COLOR $13. @15 NUMBER 3.;
DATALINES;
YELLOWSMOOTH 315
YELLOWWRINKLE 102
GREENSMOOTH
108
GREENWRINKLE 31
;
* HYPOTHESIZING A 9:3:3:1 RATIO;
PROC FREQ DATA=GENE ORDER=DATA; WEIGHT NUMBER;
TITLE3 'GOODNESS OF FIT ANALYSIS';
TABLES COLOR / CHISQ NOCUM TESTP=(0.5625 0.1875 0.1875 0.0625);
RUN;
The SAS System
GOODNESS OF FIT ANALYSIS
The FREQ Procedure
Test
9
COLOR
Frequency
Percent
Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
YELLOWSMOOTH
315
56.65
56.25
YELLOWWRINKLE
102
18.35
18.75
GREENSMOOTH
108
19.42
18.75
GREENWRINKLE
31
5.58
6.25
Chi-Square Test
for Specified Proportions
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Chi-Square
0.6043
DF
3
Pr > ChiSq
0.8954
Sample Size = 556
Example 4. A classic tale involves four car-pooling students who missed a test and gave
as an excuse of a flat tire. On the make-up test, the professor asked the students to
identify the particular tire that went flat. If they really did not have a flat tire, would they
be able to identify the same tire?
To mimic this situation, 40 other students were asked to identify the tire they would
select.
The data are:
Tire
Left front
Right front
Left rear
Right rear
11
15
8
6
Frequency
At α=0.05, please test whether each tire has the same chance to be selected?
Solution:
1

 H 0 : p1  p2  p3  p4 
4

 H a : H 0 is not true
n=40, ei =n pi =10
( xi  ei )2
2
W0  
 4.6  3,0.05,
upper  7.81
ei
i 1
k
 Fail to reject H 0 .
10
11
The chi-square goodness of fit test is an extension of the Z-test
for one population proportion.
Data: sample size n, x: successes with probability p
n-x: failures with probability 1-p
TS. Z 0 
pˆ  p0 H 0
~ N (0,1)
p0 (1  p0 )
n
At α, reject H 0 iff | Z0 | Z /2
Success
p1  p0
Expected
Observed
W0 
Failure
e1  np0
p2  1  p0
e2  n(1  p0 )
X2  n  x
X 1 =x
( x  np0 )2 [n  x  n(1  p0 )]2 ( x  np0 )2 ( p0  1  p0 )]2
=

np0
n(1  p0 )
np0 (1  p0 )
x
(  p0 ) 2
( x  np0 ) 2
=
 n
 Z02
np0 (1  p0 ) p0 (1  p0 ) / n
iid
k
Recall: If Z1, Z 2, ....Z n ~ N (0,1) , then W   Z i 2 ~  k 2 .
1
When k=1, W  Z 2 ~ 12
Let Z~N(0,1), then W  Z 2 ~ 12
P(| Z | Z /2 )  P( Z 2  Z2 /2 )   = P(W  1,2 ,upper )
 The two tests are identical.
12
Exact Tests for Inference on Two Population Proportions
1. Fisher’s exact test:
A little bit of history (Fisher’s Tea Drinker): R.A. Fisher described
the following experiment. Muriel Bristol, his colleague, claimed that
when drinking tea, she could distinguish whether milk or tea was added
to the cup first (she preferred milk first). To test her claim, Fisher
designed an experiment with 8 cups of tea – 4 with milk added first and
4 with tea added first. Muriel was told that there were 4 cups of each
type, and was asked to predict which four had the milk added first. The
order of presenting the cups to her was randomized. It turned out that
Muriel correctly identified 3 from each type. Now we are testing the
null hypothesis that she did so by pure guessing, versus the
alternative hypothesis that she could do better than pure guessing. The
p-value of the test is derived as follows:
p  value  P( X  3 | X  Y  8)  P( X  3 | X  Y  8)  P( X  4 | X  Y  8)

(34 )(14 ) (44 )(04 )
 8  0.229  0.014  0.243
(84 )
(4 )
Since the p-value is large, we could not reject the null hypothesis. It means that it is possible
that she chose 3 correctly by pure guessing.
Inference on 2 population proportions, 2 independent samples
Example 5. The result of a randomized clinical trial for comparing Prednisone and
Prednisone+VCR drugs, is summarized below. Test if the success and failure
probabilities are the same for the two drugs.
Drug
Success
Failure
Row total
Pred
14
7
n1 =21
PVCR
38
4
n2 =42
m=52
n-m=11
n=63
General setting:
13
“S”
“F”
Total
Sample1
x
n1 -x
n1
Sample2
y
n2 -y
n2
m=x+y
n-m
n
 H 0 : p1  p2

 H a : p1  p2
p  value  pU  P( X  x | X  Y  m)  
 H 0 : p1  p2

 H a : p1  p2
p  value  pL  P( X  x | X  Y  m)  
 H 0 : p1  p2

 H a : p1  p2
p  value  2  min( PU , PL )
(nk1 )(mn2k ) min( m ,n1 ) (kn1 )(mn2k )
 
(nm )
(nm )
k x
k x
x
( nk1 )(nm2 k )
(kn1 )(mn2 k )


( nm )
(nm )
kx
k  max(0,m  n2 )
Solution:
 H 0 : p1  p2

 H a : p1  p2
p  value 
42
42
14
(21
( 21
k )(52  k )
k )(52  k )


 (63 )  0.016 <0.05
63
(52
)
k  max(0,52  42)
k 10
52
14
 Reject H 0
SAS code:
Data trial;
input drug $ outcome$ count;
datalines;
pred S 14
pred F 7
PVCR S 38
PVCR F 4
;
run;
proc freq data=trial;
tables drug*outcome/chisq;
weight count;
run;
14
2. McNemar’s test
Inference on 2 population proportions- paired samples
Example 6. A preference poll of a panel of 75 voters was conducted before and after a TV
debate during the campaign for the 1980 presidential election between Jimmy Carter and
Ronald Reagan. Test whether there was a significant shift from Carter as a result of the
TV debate.
Preference
Preference after
before
Carter
Reagan
Carter
28
13
Reagan
7
27
General setting:
Condition1
Condition2 response
response
Yes
No
Yes
A=a,
PA
B=b,
PB
No
C=c,
PC
D=d,
PD
PA + PB + PC + PD =1,
A+B+C+D=n, (A, B, C, D)~Multinomial
P1  PA  PB , P2  PA  PC
H 0 : p1  p2
 H 0 : pB  pC
P(B=k| B+C=m)~Bin(m,p=
pB
)
pB  pC
1
2
Under H 0 : p  , P(B=k| B+C=m)~Bin(m,p=1/2)
15
1

 H 0 : p  2
 H 0 : p1  p2
① 

 H a : p1  p2
H : p  1
 a
2
1 m
p  value  pU  P( B  b | B  C  m)  ( )m  (mk )
2 k b
1

H
:
p

0

H : p  p
2
②  0 1 2  
 H a : p1  p2
H : p  1
 a
2
1 b
p  value  pL  P ( B  b | B  C  m)  ( )m  (km )
2 k 0
1

H0 : p 

H : p  p
2
③  0 1 2  
 H a : p1  p2
H : p  1
 a
2
p  value  2  min( PL , PU )
Solution:
1

H
:
p

0

 H 0 : p1  p2
2


 H a : p1  p2
H : p  1
 a
2
1 20
p  value  ( ) 20  ( 20
k )  0.1316
2 k 13
SAS code:
Data election;
input before $ after $ count;
datalines;
Carter Carter 28
Carter Reagan 13
Reagan Reagan 27
Reagan Carter 7
;
run;
proc freq data=election;
16
exact agree;
tables before*after/agree;
weight count;
run;
The SAS System
21:15 Saturday, November 6, 2010
2
The FREQ Procedure
Table of before by after
before
after
Frequency‚
Percent ‚
Row Pct ‚
Col Pct ‚Carter ‚Reagan ‚ Total
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Carter
‚
28 ‚
13 ‚
41
‚ 37.33 ‚ 17.33 ‚ 54.67
‚ 68.29 ‚ 31.71 ‚
‚ 80.00 ‚ 32.50 ‚
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Reagan
‚
7 ‚
27 ‚
34
‚
9.33 ‚ 36.00 ‚ 45.33
‚ 20.59 ‚ 79.41 ‚
‚ 20.00 ‚ 67.50 ‚
ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Total
35
40
75
46.67
53.33
100.00
Statistics for Table of before by after
McNemar's Test
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Statistic (S)
1.8000
DF
1
Asymptotic Pr > S
0.1797
Exact
Pr >= S
0.2632
(= 2*0.1316)
Simple Kappa Coefficient
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Kappa (K)
0.4700
ASE
0.1003
95% Lower Conf Limit
0.2734
95% Upper Conf Limit
0.6666
Test of H0: Kappa = 0
ASE under H0
Z
One-sided Pr > Z
Two-sided Pr > |Z|
Exact Test
One-sided Pr >= K
Two-sided Pr >= |K|
0.1140
4.1225
<.0001
<.0001
3.614E-05
5.847E-05
Sample Size = 75
17
Related documents