Chapter 12 Inference about two probabilities -...
Transcript of Chapter 12 Inference about two probabilities -...
Chapter 12
Inference about twoprobabilities
In this chapter, we discuss inferences about proportions in two populationsin two ways:
1. inferences about independence
2. inferences about two populations - difference in probabilities
12.1 Contingency tables -Tests of indepen-
dence
These tests occur with two measurements on the same person, for example,smoking; respiratory infection (including chest cold). Both measurementsare binary, in this case Y and N
The question is: Are these measurements related?
In general, the results are reported as a two-by-two table.They are sometimes called a fourfold table, a cross-tabulation tables or,most often, a contingency table, where one measurement is contingent (de-pendent) on the other.
1
2 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
The general form of the contingency table is
Table 12.1: A typical contingency table
Characteristic BCharacteristic A Yes No TotalYes a b r1No c d r2Total c1 c2 T
As an example consider a study looking at the relationship between smok-ing and respiratory illness, referred to as a cold.
Table 12.2: A study of smoking and colds
Had a cold this yearSmoked this year Yes No TotalYes 15 8 23No 10 12 22Total 25 20 45
The traditional null and alternative hypotheses are quite vagueHo : smoking and colds are not related (12.1)that is, smoking and colds are independent
HA : smoking and colds are related
Despite the vagueness of the null hypothesis, we can, under this hypoth-esis, compute expected probabilities, for example,
Pr(Smoked this year AND had a cold) = Pr(smoked this year)Pr(had a cold this year)
=23
45
25
45
=23
81= 0.2839
12.1. CONTINGENCY TABLES -TESTS OF INDEPENDENCE 3
We can also compute the expected number of smokers with a cold
45
(
23
45
25
45
)
=23(25)
45= 12.7777
In general we have Eij =ricjT
Table 12.3: Resulting table of Expected values
study of smoking and coldsHad a cold this year
Yes 12.78 10.22 23No 12.22 9.78 22Total 25 20 45
The test statistic is Pearsons test of association SP (after Karl Pearson,1900)
SP =2∑
i=1
2∑
j=1
(Oij − Eij)2
Eij
=(15− 12.7778)2
12.7778+
(8− 10.2222)2
10.2222
+(10− 12.2222)2
12.2222+
(12− 9.7778)2
9.7778= 4.9382(0.3602)
= 1.7786
pvalue = Pr(SP > 1.7786)
= 2Pr(ZN > 1.3336)
= 2(.0912)
= 0.1824
4 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
There is a continuity-corrected version suggested by Frank Yates (1934)
SY =2∑
i=1
2∑
j=1
(|Oij − Eij| − 0.5)2
Eij
=(|15− 12.78| − 0.5)2
12.78+
(|8− 10.22| − 0.5)2
10.22
+(|10− 12.22| − 0.5)2
12.22+
(|12− 9.78| − 0.5)2
9.78
=2.9660
0.3602= 1.0668
pvalue = Pr(SY > 1.0683)
= 2Pr(ZN > 1.0336)
= 2(.1506)
= 0.3012
12.1. CONTINGENCY TABLES -TESTS OF INDEPENDENCE 5
12.1.1 alternative presentation of statistics
These are called the epidemiological version of the test statistics:
1. Pearson’s test
SP = T(ad− bc)2
c1c2r1r2
= 45(15(12)− 8(10))2
23(22)(25)(20)
= 45
(
1002
253000
)
=450
253= 1.7786
2. Yates’ version
SY = T(|ad− bc| − T/2)2
c1c2r1r2
= 45(|15(12)− 8(10)| − 22.5)2
23(22)(25)(20)
= 45
(
77.52
253000
)
= 1.0683
6 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.1.2 exact test
Meanwhile, in 1922, Ronald Fisher had suggested an exact test:
• fix column and row totalsthese are denoted in Table 12.1 as c1, c2, r1, r2, T
• given we have c1 items of the total T in column 1calculate the probability of gettinga of r1 in row 1c of r2 in row 2this comes from the hypergeometric distribution, and is written as
(
r1a
)(
r2c
)
(
Tc1
)
• calculate for observed data
(
2315
)(
2210
)
(
4525
)
= 0.100023
• repeat for all tableswith smaller probability!!!
For this particular data, p-value = 0.2361889, that is, 0.2362
12.1. CONTINGENCY TABLES -TESTS OF INDEPENDENCE 7
12.1.3 Summary of contingency table tests
This table gives the summary of the results of three possible statistical testsof Independence:
Method p-value commentFisher 0.2362 exactPearson 0.1824 anticonservativeYates 0.3012 conservative
This table demonstrates the method of testing hypotheses like (12.1)
1. where possible, use Fisher’s exact test;
2. when necessary, use SY , Yates’s continuity-corrected test statistic
12.1.4 Hypotheses about differences in probabilities
If we selected a 23 smokers and 22 non-smokers, and followed them for ayear to see who got colds, we would be using the study design called a cohort
study by epidemiologists. Here are the results of such a study:
Table 12.4: cohort study of smoking and colds
Had a cold during yearSmoker at beginning of year Yes No TotalYes 15 8 23No 10 12 22Total 25 20 45
As with the hypothesis test methodology already discussed, we can think ofthis data as coming from two populations, smokers and non-smokers, eachwith probability, πi, of getting a cold
Here are the possible null and alternative hypotheses for this situation:Ho : π1 = π2(12.2)HA : π1 6= π2
8 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
Any of the approaches to hypothesis testing would use a statistic of theform
p1 − p2√
p1(1−p1)n1
+ p2(1−p2)n2
(12.3)
It can be shown that :
1. the square of the test statistic (12.3) is equivalent to SP , the Pearsontest statistic described in the previous section(this equivalence is proved at the end of this chapter)
2. there is a continuity-corrected version of (12.3), and it can the shownthat the square of this statistic is equivalent to SY , the Yates teststatistic.
Hence SP and/or SY can be used to test hypotheses given in (12.2), andthere is no need for use of the statistic (12.3).
Hence for testing hypotheses such as those given in (12.2)
1. use Fisher’s exact test, when available;
2. otherwise, use SY , Yates continuity-corrected test
WHAT about ESTIMATION
12.2. CONFIDENCE INTERVALS FORDIFFERENCES IN PROBABILITIES9
12.2 Confidence Intervals for differences in
probabilities
1. for large samplesnipi > 5, i = 1, 2
(p1 − p2)± zα/2
√
(
p1(1− p1)
n1
+p2(1− p2)
n2
)
(12.4)
2. small samples Iuse Continuity correction for each sample
(p1 − p2)±(
12r1
+ 12r2
)
+ zα/2
√
(
p1(1−p1)n1
+ p2(1−p2)n2
)
3. small samples IIusing intervals from each sample, according to either WIlson/Score orWald Adjusted methods, then combining them in a special way;
4. small samples IIIalternative due to Zou and Donner (2004)
12.2.1 Newcombe’s (1998) method
1. use Wilson or Wald Adjusted to get(l1, u1) for π1
(l2, u2) for π2
2. compute
(p1 − p2)− zα/2
√
l1(1− l1)
n1
+u2(1− u2)
n2
(12.5)
(p1 − p2) + zα/2
√
u1(1− u1)
n1
+l2(1− l2)
n2
(12.6)
or
(p1 − p2)−√
(p1 − l1)2 + (u2 − p2)2(12.7)
(p1 − p2) +√
(p2 − l2)2 + (u1 − p1)2(12.8)
10 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.2.2 example
12.2.2.1 Continuity correction
1. since this is a small sample,we don’t use the large sample method, butinstead, use the Continuity correctionFirst wee need point estimates:p1 = 15/23 = 0.6522, p2 = 10/22 = 0.4545
2. construct the 95% confidence interval
(0.6522− 0.4545)
±[
1
46+
1
44+ 1.96
√
0.6522(0.3478)
23+
0.4545(0.5455)
22
]
= (0.1977)± (0.0445 + 1.96√0.009862 + 0.011270)
= 0.1977± [0.0445 + 1.96(0.1454)]
= 0.1977± 0.3294
that is, (-0.132,0.527), a very wide interval.
12.2.2.2 using adjusted wald
1. need point estimatesp1 = (15 + 2)/(23 + 4) = 0.6296p2 = (10 + 2)/(22 + 4) = 0.4615
2. construct first 95% CI
0.6296± 1.96
√
0.6296(0.3704)
27
= 0.6296± 1.96√0.00864
= 0.6296± 1.96(0.09293) = 0.6296± 0.1821
= (0.4475, 0.8118)
12.2. CONFIDENCE INTERVALS FORDIFFERENCES IN PROBABILITIES11
3. construct second 95% confidence interval
0.4615± 1.96
√
0.4615(0.5385)
26
= 0.4615± 1.96√0.009558
= 0.4615± 1.96(0.09776) = 0.6296± 0.1916
= (0.2699, 0.6532)
(p1 − p2)−√
(p1 − l1)2 + (u2 − p2)2
= (0.6522− 0.4545)
−√
(0.6522− 0.4475)2 + (0.6532− 0.4545)2
= 0.1977−√0.20472 + 0.19872
= 0.1977−√0.08138378 = 0.1977− 0.2853 = −0.0876
(p1 − p2) +√
(p2 − l2)2 + (u1 − p1)2
= (0.6522− 0.4545)
−√
(0.4545− 0.2699)2 + (0.8118− 0.6522)2
= 0.1977 +√0.18462 + 0.15962
= 0.1977 +√0.05954932 = 0.1977 + 0.2440 = 0.4417
Hence interval is (-0.0876,0.4417)
12 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.2.2.3 Advantages of Newcombe’s method
1. narrower than Continuity corrected interval
2. shifted away from 0
3. asymmetric around point estimate 0.1977
12.2.2.4 The origins of Newcombe’s formulae
The lower bound of the confidence interval for the difference in probabilitiesis give by
(p1 − p2)− zα/2
√
σ2p1+ σ2
p2(12.9)
In the usual (large sample) method, the ”overall” estimates of σ2p1
and σp2
are used, that is, p1(1−p1)n1
and p2(1−p2)n2
, respectivelyThese are used in equation (12.9) to get equation (12.4).
However, as Newcombe suggested, at the lower and upper bounds of the in-terval, there are better estimates of the variances
At the lower bound, we want the smallest value of π̂1 − π̂2; this occurs whenwe use l1 and u2.For example, if the 95%CI for π1 is (0.4,0.5) and the 95% Ci for π2 is (0.2,0.3),the the difference π̂1 − π̂2 if minimized if we use l1 = 0.4 and u2 = 0.3 to get0.4− 0.2 = 0.1Similarly, the difference is maximized it we use u1 and l2, for example,0.5− 0.1 = 0.4.
12.2. CONFIDENCE INTERVALS FORDIFFERENCES IN PROBABILITIES13
Returning to the formula, when we plug l1 and u2 into (12.4) or (12.9) toget (12.5), namely,
(p1 − p2)− zα/2
√
l1(1− l1)
n1
+u2(1− u2)
n2
Similarly, plug plug u1 and l2 into (12.4) or (12.9) to get (12.6) namely,
(p1 − p2) + zα/2
√
u1(1− u1)
n1
+l2(1− l2)
n2
Now for the other equations:l1 is the lower bound of the interval estimate of π1. It is calculated asl1 = p1 − zα/2σMoving terms around = sign, this becomeszα/2σ = p1 − l1Thus p1 − l1 is an estimate of zα/2σp1
Similarly u2 − p2 is an estimate of zα/2σp2
Plug p1 − l1 and u2 − p2 into (12.4) above to get (12.7)
Similarly at upper bound we plug u1−p1 and p2− l2 into (12.4) to get (12.8).
14 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.3 Using SAS for contingency tables
Now we look at Proc FREQ and its use with count data (rather than rawdata) to produce the analysis of contingency tables.
12.3.1 Simple SAS program
Here is a sample SAS program for contingency table analyses:
title ’simple contingency table’;
proc format;
yesno 0=’yes’ 1=’no’;
DATA marj;
INPUT r o freq;
format r yesno. o yesno.;
DATALINES;
0 0 15
0 1 8
1 0 10
1 1 12
;
The SAS commands for contingency table analysis have to a repeatedRISKDIFF for each method:
PROC FREQ;
WEIGHT freq;
TABLES r*o/ NOROW NOCOL NOPERCENT CHISQ RISKDIFF;
TABLES r*o/ NOROW NOCOL NOPERCENT RISKDIFF(CORRECT);
TABLES r*o/ NOROW NOCOL NOPERCENT
RISKDIFF(METHOD=NEWCOMBE);
quit;
12.3. USING SAS FOR CONTINGENCY TABLES 15
Here is the output, first the contingency table:
simple contingency table
The FREQ Procedure
Table of r by o
Frequency
| yes| no| Total
---------+--------+--------+
yes| 15 | 8 | 23 |
---------+--------+--------+
no| 10 | 12 | 22 |
---------+--------+--------+
Total 25 20 45
and next the tests of the null hypothesis:
Statistic DF Value Prob
-------------------------------------------------
Chi-Square 1 1.7787 0.1823
Likelihood Ratio Chi-Square 1 1.7900 0.1809
Continuity Adj. Chi-Square 1 1.0683 0.3013
Mantel-Haenszel Chi-Square 1 1.7391 0.1872
Phi Coefficient 0.1988
Contingency Coefficient 0.1950
Cramer’s V 0.1988
Fisher’s Exact Test
----------------------------------
Cell (1,1) Frequency (F) 15
Left-sided Pr <= F 0.9493
Right-sided Pr >= F 0.1507
Table Probability (P) 0.1000
Two-sided Pr <= P 0.2362
16 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
Here are the estimates of risk difference:
Column 1 Risk Estimates
(Asymptotic)95\% (Exact)95\%
Risk ASE Confide Limits Confide Limits
-----------------------------------------------------
Row 1 0.6522 0.0993 0.4575 0.8468 0.4273 0.8362
Row 2 0.4545 0.1062 0.2465 0.6626 0.2439 0.6779
Total 0.5556 0.0741 0.4104 0.7007 0.4000 0.7036
Difference 0.1976 0.1454 -0.0873 0.4825
Difference is (Row 1 - Row 2)
The next page of output gives ”Column 2 Risk Estimates” which you maychoose to ignore.
Here are the Risk estimates with continuity correction:
Column 1 Risk Estimates
(Asymptotic) 95% (Exact) 95%
Risk ASE Confide Limits Confide Limits
-----------------------------------------------------
Row 1 0.6522 0.0993 0.4358 0.8686 0.4273 0.8362
Row 2 0.4545 0.1062 0.2238 0.6853 0.2439 0.6779
Total 0.5556 0.0741 0.3993 0.7118 0.4000 0.7036
Difference 0.1976 0.1454 -0.1318 0.5270
Difference is (Row 1 - Row 2)
The asymptotic confidence limits include
a continuity correction.
This agrees with our hand calculations done previously in this chapter.SAS also gives a similar table for ”Column 2 Risk Estimates”, which,
again, you may wish to ignoreNote, although we requested a Newcombe Method calculation of confi-
dence interval for the difference in proportions, it DOES NOT work in SAS9.2
12.3. USING SAS FOR CONTINGENCY TABLES 17
12.3.2 Creating pretty tables
In this section, the emphasis is on creating tables in a suitable, readable for-mat, but the statistical analyses are still the same. In the previous example,we used the default for creation of a table, that is, the numerical value of thelevels of a discrete variables.
In this particular example,
1. the level with ”0” is first level
2. the level with ”1” is second level
and we created formats appropriately.In this case, because we wanted the observed count of ”15”, in the first
row and first column, and we know that the the values of ”0” are the firstlevel for each variable, we label the ”0”’s as YES, and, similarly, the ”1”’s asNO.
However we may want formats defined differently, for example, we maywant
• ”1” to be formatted as YES
• ”0” to be formatted as NO.
Hence the variables values of (1,1) have a count of 15. In order to do this,we create data with ”1 1 15” in one line, but we put this value first after theDATALINES command. We tell SAS to use this information by adding theoption ”ORDER=DATA” on the PROC FREQ line.
In other words
1. create formats so that columns and rows of the table are correctlylabelled;
2. input table in order a, b, c, d;
3. say PROC FREQ ORDER=DATA;
18 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
Here is a SAS program which does this:
title1 ’simple contingency table’;
title2 ’with different formats’;
PROC FORMAT; value yesno 1=’yes’ 0=’no’;
DATA marj;
INPUT r o freq; FORMAT r yesno. o yesno.;
DATALINES;
1 1 15
1 0 8
0 1 10
0 0 12
;
PROC FREQ ORDER=DATA;
WEIGHT freq;
TABLES r*o/NOROW NOCOL NOPERCENT ;
And here is output with the new new formats. Note that the output is thesame, but we have ”1” as YES and ”0” as NO, which we may wish to use inlater analyses.
simple contingency table
with different formats
The FREQ Procedure
Table of r by o
Frequency|yes |no | Total
---------+--------+--------+
yes | 15 | 8 | 23
---------+--------+--------+
no | 10 | 12 | 22
---------+--------+--------+
Total 25 20
12.3. USING SAS FOR CONTINGENCY TABLES 19
12.3.3 Dealing with Raw data - not counts
In this case, the data consists of records of individuals, who have discretevalues (in this case, ”1” or ”2”) for each variable, and we have to use SASto sum over individuals to create counts, and hence tables.
Here is a typical program, where the values of the discrete variables arepre-defined, and we merely code those values and we create a contingencytable:[12:46am mario]
title ’ analysis from raw data’;
filename two ’two.dat’;
proc format;
value gender 1=’Male’ 2=’Female’;
value smoking 1=’No’ 2=’Yes’;
data second;
infile two;
input id age sex hr smoking;
label sex=’Sex of Subject’
smoking=’Smoking status’;
format sex gender. smoking smoking.;
proc freq ;
tables sex*smoking/norow nocol nopercent;
Here is the data:
1 22 1 60 1
2 25 1 80 2
3 24 1 75 1
4 23 1 65 1
5 27 1 90 2
6 26 1 70 1
7 27 2 55 1
8 26 2 65 1
9 23 2 70 1
10 30 2 75 2
11 25 2 85 2
12 24 2 90 2
20 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
We know that SAS will put the count for values (1,1) in the upper leftcell of the table, that is, the males who said No:
analysis from raw data
The FREQ Procedure
Table of sex by smoking
sex(Sex of Subject)
smoking(Smoking status)
Frequency|No |Yes | Total
---------+--------+--------+
Male | 4 | 2 | 6
---------+--------+--------+
Female | 3 | 3 | 6
---------+--------+--------+
Total 7 5 12
We actually want the YES outcome in the first column (and are not worriedabout rows)
12.3.3.1 Getting tables in correct order
There are many ways to do this:
1. SORT on the variables defining row and column of the table; in thisexample, we would only have to sort on the row defining SMOKING,and use the command
Proc FREQ ORDER=DATA;
The problem with this method is that it depends on the physical orderof data. You don’t want to create a permanent dataset that depends onthe order of the data, because it can be changed by a SORT on anothervariable. You should use a SORT to create a temporary dataset for aparticular analysis.Because of these problems, nothing further will be shown about thismethod
12.3. USING SAS FOR CONTINGENCY TABLES 21
2. use ORDER=FORMATTED to get the rows and columns of the tablein the alphabetic order of formats. The problem with this is that bothvariables will be done this way; in this particular case, the Rows willchanges from Males first to Females first, and the columns will remainwith No first, then Yes (see below);
3. Use a trick on the names of the formats to get the formats in the correctorder. You may have to do this with both variables (see below);
4. Define a new version of variablewith values in the correct order. Two examples are given below.
12.3.3.2 order defined by formats
This requires a particular option on the Proc FREQ line:
Proc FREQ ORDER=FORMATTED;
Here is the output:
analysis from raw data - use formats
Table of sex by smoking
sex(Sex of Subject)
smoking(Smoking status)
Frequency|No |Yes | Total
---------+--------+--------+
Female | 3 | 3 | 6
---------+--------+--------+
Male | 4 | 2 | 6
---------+--------+--------+
Total 7 5 12
Note that the order of columns and rows is the the alphabetical order ofthe formats; hence ”No” still comes before ”Yes” which we don’t want, and”Females” comes before ”Males”, which his change, but is ok.
22 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.3.3.3 Redefine formats
In order to get the Yes column first, we can define one level as ’Yes’ and theother as ’Zno’; hence
proc format;
value smoking 1=’Zno’ 2=’Yes’;
and
Proc FREQ ORDER=FORMATTED;
Now, the first column will be the smokers, even though one strange format(Zno) is used, and Females come before Males, as before
The FREQ Procedure
Table of sex by smoking
sex(Sex of Subject)
smoking(Smoking status)
Frequency|Yes |Zno | Total
---------+--------+--------+
Female | 3 | 3 | 6
---------+--------+--------+
Male | 2 | 4 | 6
---------+--------+--------+
Total 5 7 12
12.3. USING SAS FOR CONTINGENCY TABLES 23
12.3.3.4 Redefine variable(s)
In this case, we create a new variable which has its values in the order wewish, AND we create a new format to go along the new values. Here is partof a SAS program to do this:
Proc FORMAT;
smokb value 2=’Yes’ 3=’No’;
DATA ...;
...
smok2 = smoking;
if (smoking=1) then (smok2=3);
format smok2 smokb;
label smok2=’Smoking status 2’;
...
PROC FREQ DATA=...;
TABLES sex*smok2 ...
SAS uses the default numerical order, but the values of the new SMOKINGvariable are 2 and 3, where the lower value of 2 corresponds to the outcomeYES. Hence in this contingency table, ”Yes” comes before ”No”, which isgood, and ”Males” come before ”Females”, which is ok:
analysis from raw data
The FREQ Procedure\su
Table of sex by smok2
sex(Sex of Subject)
smok2(Smoking status 2)
Frequency|Yes |No | Total
---------+--------+--------+
Male | 3 | 3 | 6
---------+--------+--------+
Female | 2 | 4 | 6
---------+--------+--------+
Total 5 7 12
24 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.3.3.5 Alternative redefinition
Another way of redefining the variable is to switch, in a new variable, thevalues of 1 and 2; here is sample code:
Proc FORMAT;
smokb value 1=’Yes’ 2=’No’;
DATA ...;
...
smok2 = smoking;
if (smoking=1) then (smok2=2);
if (smoking=2) then (smok2=1);
format smok2 smokb;
label smok2=’Smoking status 2’;
...
PROC FREQ DATA=;
TABLES sex*smok2 ...
The output is exactly like the preceding output (but the values of the newvariables are different, as are their formats).
12.4. DESIGNING STUDIES 25
12.4 Designing studies
When planning a study which compares a binary outcome between two pop-ulations, there are two possible computations to be made when trying to plana study:
1. sample sizeHow big a sample size do we need to detect the difference in two pro-portions (probabilities);
2. powerwhat is the chance (probability) of detecting the effect of the new treat-ment
Both these calculations use the effect size, that is,
1. in a population study, the difference in the proportions in two popula-tions,
2. in a clinical study, the change in proportion (population probability)between the new treatment and the old one.
12.4.1 Sample size
We are interested in the change in probability δπ = π1 − π2
Since the variance depends on mean, for this calculation we have to specifyπ1, π2
The simple formula from previous work on difference in means becomes morecomplex
n =
(
√
2π(1− π)zα/2 +√
π1(1− π1) + π2(1− π2)zβES
)2
(12.1)where π = π1+π2
2. The effect size, ES, is δπ.
The σ, which was included in δ in the earlier formula, does not appear inthis ES; it does appear in the numerator of the equation above.
usually α = 0.05, and β = 0.20 (that is, the power is 80%)so that zα/2 = z0.025 = 1.960 and zβ = z0.20 = 0.842
26 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.4.1.1 Sample size calculation example
In a clinical trial, where the usual success rate is 50%, we hope to improvethis by 10% to a new rate of 60%.Mathematically, this may be stated as π2 = 0.5 and π1 = 0.60, δ = 0.10 = ES(We label the two groups to that ES is positive and π = 0.50+0.60
2= 0.55
Substituting into the preceding equation, we get
n =
(
√
2(0.55)(0.45)(1.96) +√
0.50(0.50) + 0.60(0.40)(0.842)
0.10
)2
=
(
[√0.495]1.96 + [
√0.49]0.842
0.10
)2
=
(
1.3789 + 0.5894
0.10
)2
=
(
1.9683
0.10
)2
= 387.4528
that is 388 (close enough to 400)
12.4. DESIGNING STUDIES 27
12.4.1.2 An approximation
It is possible to assume that π1 and π2 are close enough to π that they canbe replaced in equation (12.1), which becomes
n =
(
√
2π(1− π)(zα/2 + zβ)
ES
)2
(12.2)
Using numbers from the previous example, equation (12.2) becomes
n =
(
√
2(0.55)(0.45)(1.96 + 0.842)
0.10
)2
= 388.6
which we round up to 389. This seems to be a conservative approximation.
28 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.4.2 Power for difference in proportions
Recall, that, for the difference in means this was calculated as
Pr
(
ZN > zα/) −|δA|σD̄
)
For proportions, this becomes
Pr
(
ZN > zα/) −|δπ|σD̄p
)
(12.3)
whereδπ = π1 − π2
and
σD̄p=
√
π1(1− π1)
n1
+π2(1− π2)
n2
which, for equal sample size, becomes
=
√
π1(1− π1) + π2(1− π2)
n
12.4.2.1 example: power for difference in proportions
Say, for the smoking-cold example,π1 = 0.65, π2 = 0.45, n1 = n2 = n = 25.Hence δπ = π1 − π2 = 0.65− 0.45 = 0.20
σD̄p=
√
0.65(0.35) + 0.45(0.55)
25= 0.1378
so that power is
Pr
(
ZN > z0.025 −0.20
0.1378
)
= Pr(ZN > 1.960− 1.4510) = Pr(ZN > 0.509)
= z0.509 = 0.305
Hence the chance of finding a difference of 0.20 with samples of size 25 is30%
12.4. DESIGNING STUDIES 29
12.4.2.2 Approximation
If, for the purposes of calculating σD̄p, we are prepared to assume that π1 =
π2 = π, then
σD̄p=
√
2(0.55(0.45)
25= 0.1407
so that the power is approximately
Pr
(
ZN > z0.025 −0.20
0.1407
)
= Pr(ZN > 1.960− 1.421) = Pr(ZN > 0.539)
= z0.539 = 0.2950
This is smaller than the more exact calculation, and is thus conservative(although this may not always be so).
30 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.5 One-sided alternatives
If we nave a one-side alternative, we can use the text baseed on p1− p2, thatis,
p1 − p2√
p(1− p)(
1n1
+ 1n2
)
where p1 and p2 are the proportions in the two samples, and p is the overallproportion
p =(X1 +X2)
(n1 + n2)
12.5.1 example of one-sided test
Suppose we have an alternative
HA : π1 > π2
ie, smokers are more likely to get colds than non-smokers.We have observed p1 = (15/23) = 0.65217; p2 = (10/22) = 0.45455and p = 25/45 = 0.55555so that
p = Pr
ZN >0.65217− 0.45455
√
0.55555(0.44444)(
123
+ 122
)
= Pr
(
ZN >0.19762
√
0.24691(0.08893)
)
= Pr
(
ZN >0.19762
0.14818
)
= Pr(ZN > 1.3336) = z1.3336 = 0.0912
Hence, at α = 0.05, cannot reject Ho.
12.5. ONE-SIDED ALTERNATIVES 31
12.5.2 Continuity correction
In this case, the test statistic is
(p1 − p2)−(
12n1
+ 12n2
)
√
p(1− p)(
1n1
+ 1n2
)
and
p = Pr
ZN >0.65217− 0.45455−
(
146
+ 144
)
√
0.55555(0.44444)(
123
+ 122
)
= Pr
(
ZN >0.15316
0.14818
)
= Pr(ZN > 1.0336) = z1.0336 ≈ 0.1506
Hence, at α = 0.05, we cannot reject Ho.
32 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
12.5.3 use of SY for one-sided alternatives
Recall that SY was developed for two-sided alternatives. In calculating thep-value, we used the formula
p = Pr(χ21 > x) = 2Pr(ZN >
√x)(12.7)
we actually wanted
Pr(χ21 > x) = Pr(ZN >
√x) + Pr(ZN < −
√x)
but becausePr(ZN >
√x) = Pr(ZN < −
√x)
we get equation (12.7)
For one-sided alternativesuse only one of
Pr(ZN >√x)
andPr(ZN < −
√x)
for example, for one-sided alternative, use
p = Pr(ZN >√
SY )
12.5.3.1 example: use of SY for one-sided test
For the two-sided alternative
pvalue = Pr(SY > 1.0668) = 2Pr(ZN > 1.0336)
but for the one-sided alternative
pvalue == 2Pr(ZN >√1.0668)
= Pr(ZN > 1.0336)
which is equivalent to the result using statistic p1 − p2...
12.6. PROOF OF EQUIVALENCE OF TESTS 33
12.6 Proof of Equivalence of tests
12.6.1 difference in proportions and SP
For testing hypotheses about the difference in probabilities (population pro-portions) we can use the test based on the difference in proportions, or wecan use SP .These two test statistics can be shown to be mathematically equivalent.Take the test based on the difference in proportions and square it.
(p1 − p2)2
p(1− p)(
1r1+ 1
r2
)
Rewrite this using the notation from contingency table
=
(
ar1− c
r2
)2
(
c1T
c2T
)
(
1r1+ 1
r2
)
=
(
ar2−cr1r1r2
)2
(
c1c2T 2
)
(
Tr1r2
)
=(ar2 − cr1)
2T
c1c2r1r2
34 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
A term in numerator can be written
ar2 − cr1 = a(c+ d)− c(a+ b)
= ac+ ad− ac− bc = ad− bc
so test statistic is
(ad− bc)2T
c1c2r1r2= SP
QED
12.6. PROOF OF EQUIVALENCE OF TESTS 35
12.6.2 Two versions of SP
We want to show the equivalence of usual version of SP to the epidemiological
version
SP =2∑
i=1
2∑
j=1
(
(Oij − Eij)2
Eij
)
=
(
a− r1c1T
)2
r1c1T
+
(
b− r1c2T
)2
r1c2T
+
(
c− r2c1T
)2
r2c1T
+
(
d− r2c2T
)2
r2c2T
=1
T
(aT − r1c1)2
r1c1+
(bT − r1c2)2
r1c2
+(cT − r2c1)
2
r2c1+
(dT − r2c2)2
r2c2
In numerator of first term
aT − r1c1 = a(r1 + r2)− r1(a+ c) = ar2 − cr1
= a(c+ d)− c(a+ b) = ad− bc
similarly for numerator of all the other termsNow we have
(ad− bc)2
T
(
1
r1c1+
1
r1c2+
1
r2c1+
1
r2c2
)
36 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
(ad− bc)2
T
(
r2c2 + r2c1 + r1c2 + r1c1r1r2c1c2
)
The numerator of second factor becomes
r2(c2 + c1) + r1(c2 + c1) = (r2 + r1)(c2 + c1) = T 2
hence(ad− bc)2T
r1r2c1c2
1. We have demonstrated the ”unadjusted” version of all three statisticsare mathematically equivalent
2. We could also show that the ”continuity correction unadjusted” versionof all three statistics are mathematically equivalentUse whichever of the three you find easiest for your calculations
3. this applies to two-sided andone-sided alternative hypotheses
12.7. USING SAS WITH 2X3 TABLES 37
12.7 Using SAS with 2x3 tables
For 2x2 tables,the exact test (Fisher’s) comes automatically; however, is ispossible to get exact probabilities for tables larger than 2X2 . One has toinsert the command EXACT into Proc FREQ
title "get exact pvalue for 2x3 table";
options ls=64 ps=24;
data exact;
input r c n;
datalines;
1 1 147
1 2 435
1 3 256
2 1 147
2 2 392
2 3 323
;
proc freq ORDER=DATA;
weight n;
table r*c/CHISQ NOROW NOCOL NOPERCENT EXACT;
38 CHAPTER 12. INFERENCE ABOUT TWO PROBABILITIES
Here is the output to this calculation:
get exact pvalue for 2x3 table
The FREQ Procedure
Table of r by c
r c
Frequency| 1| 2| 3| Total
---------------------------------------------
1 | 147 | 435 | 256 | 838
---------------------------------------------
2 | 147 | 392 | 323 | 862
----------------------------------------------
Total | 294 | 827 | 579 | 1700
Statistics for Table of r by c
Statistic DF Value Prob
------------------------------------------------
Chi-Square 2 9.6519 0.0080
Likelihood Ratio Chi-Square 2 9.6684 0.0080
Mantel-Haenszel Chi-Square 1 4.8042 0.0284
Phi Coefficient 0.0753
Contingency Coefficient 0.0751
Cramer’s V 0.0753
Fisher’s Exact Test
----------------------------------
Table Probability (P) 1.771E-05
Pr <= P 0.0080
Sample Size = 1700
12.8 Questions
see end of next chapter