Size: 3054
Comment:
|
Size: 2993
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
p1 and p2 are the proportions in groups 1 and 2 respectively being compared, ratio is the ratio of sizes of group 1 to group 2, alpha is the (two-tailed) type I error. The program then outputs the total sample size required for the specified power. | p1 and p2 are the proportions in groups 1 and 2 respectively being compared, delta is the ratio of sizes of group 2 to group 1, alpha is the (two-tailed) type I error. The program then outputs the total sample size required for the specified power. |
Line 10: | Line 10: |
/p1 p2 ratio alpha power. BEGIN DATA. 0.19 0.09 1 0.05 0.80 0.19 0.09 4 0.05 0.80 0.19 0.09 10 0.05 0.80 END DATA. compute p11= (p1*ratio)/(1+ratio). compute p12=((1-p1)*ratio)/(1+ratio). compute p21=p2/(1+ratio). compute p22=(1-p2)/(1+ratio). set errors=none. define orpow ( !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1)). |
/alpha p1 p2 delta power. BEGIN DATA. .05 0.19 0.09 2 0.87 .05 0.40 0.35 2 0.80 END DATA. |
Line 31: | Line 17: |
compute oddsr = (!1*!4)/(!3*!2). exe. COMPUTE #POW = !6. COMPUTE #chisq1 = ( LN(oddsr) / sqrt((1/!1)+(1/!2)+(1/!3)+(1/!4)) )**2. compute #df=1. compute #conf = 1-!5. |
define propn (!pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1)). COMPUTE #POW = !5. compute #conf = 1-!1. |
Line 41: | Line 26: |
compute #chisq = 3.000. comment COMPUTE #LC1 = 2.000. COMPUTE #CUMF2 = 1 - NCDF.CHISQ(IDF.CHISQ(#conf,#DF),#DF,#CHISQ). COMPUTE #DIFF = 1 . SET MXLOOPS=10000. |
compute n1=3. compute n2=!4*n1. compute #pbar= (n1*!2 + n2*!3) / (n1+n2). compute #z2= ( (!2-!3) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2. compute oddsr = ( n1*!2*n2*(1-!3) ) / ( n1*(1-!2)*n2*!3 ). compute #CUMF2=1-ncdf.chisq(idf.chisq(1-!1,1),1,#z2). compute #diff=1. SET MXLOOPS=40000. |
Line 48: | Line 36: |
+ COMPUTE #LC3 = #CHISQ. + COMPUTE #CHISQ = (#chisq + rnd(#chisq/3)). + COMPUTE #CUMF2 = 1 - NCDF.CHISQ(IDF.CHISQ(#conf,#DF),#DF,#CHISQ). |
+ COMPUTE #LC3 = n1. + COMPUTE n1 = (n1 + 1). + compute n2=!4*n1. + compute #pbar= (n1*!2 + n2*!3) / (n1+n2). + compute #z2= ( (!2-!3) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2. + compute #CUMF2=1-ncdf.chisq(idf.chisq(1-!1,1),1,#z2). |
Line 52: | Line 43: |
+ COMPUTE #LC1 = #chisq . + COMPUTE #chisq = (#chisq + #LC3)/2 . + COMPUTE #CUMF2 = 1 - NCDF.CHISQ(IDF.CHISQ(#conf,#DF),#DF,#CHISQ). |
+ COMPUTE #LC1 = n1 . + COMPUTE n1 = (n1 + #LC3)/2 . + compute n2=!4*n1. + compute #pbar= (n1*!2 + n2*!3) / (n1+n2). + compute #z2= ( (!2-!3) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2. + compute #CUMF2=1-ncdf.chisq(idf.chisq(1-!1,1),1,#z2). |
Line 58: | Line 52: |
compute ntot = #chisq/#chisq1. exe. if (ntot-trunc(ntot) gt 0.5) #ind=1. if (#ind eq 0) ntot=trunc(ntot)+1. if (#ind eq 1) ntot=rnd(ntot). |
if (n1-trunc(n1) gt 0.5) #ind=1. if (#ind eq 0) n1=trunc(n1)+1. if (#ind eq 1) n1=rnd(n1). |
Line 64: | Line 56: |
compute p11=!1. compute p12=!2. compute p21=!3. compute p22=!4. compute alpha=!5. compute power=!6. compute p1=p11/(p11+p12). compute p2=p21/(p21+p22). formats ntot (f7.0) alpha (f5.2) p1 (f5.2) p2 (f5.2) ratio (f5.2) oddsr power (f5.2). variable labels ntot 'Total Sample Size Required' /alpha 'Alpha' /p1 'Proportion 1' /p2 'Proportion 2' /ratio 'Ratio Gp1:Gp2' /oddsr 'Odds Ratio' /power 'Power'. |
compute alpha=!1. compute p1=!2. compute p2=!3. compute n2=!4*n1. compute power=!5. formats n1 (f7.0) n2 (f7.0) alpha (f5.2) p1 (f5.2) p2 (f5.2) power (f5.2). variable labels n1 'Sample Size 1' /n2 'Sample Size 2' /alpha 'Alpha' /p1 'Proportion 1' /p2 'Proportion 2' /power 'Power'. |
Line 75: | Line 64: |
/variables=ntot alpha p1 p2 ratio oddsr power /title "Sample Size for comparing two independent proportions given power" . |
/variables=n1 n2 alpha p1 p2 power /title "Sample Size required for a two sample, two-tailed binomial test" . |
Line 80: | Line 69: |
get m /variables=p11 p12 p21 p22 alpha power /missing=omit. compute p11=make(1,1,0). compute p12=make(1,1,0). compute p21=make(1,1,0). compute p22=make(1,1,0). |
get m /variables=alpha p1 p2 delta power /missing=omit. |
Line 86: | Line 71: |
compute p1=make(1,1,0). compute p2=make(1,1,0). compute delta=make(1,1,0). |
|
Line 87: | Line 75: |
compute p11=m(:,1). compute p12=m(:,2). compute p21=m(:,3). compute p22=m(:,4). compute alpha=m(:,5). compute power=m(:,6). |
compute alpha=m(:,1). compute p1=m(:,2). compute p2=m(:,3). compute delta=m(:,4). compute power=m(:,5). |
Line 94: | Line 81: |
orpow p11 p12 p21 p22 alpha power. | propn alpha p1 p2 delta power. |
[ADJUST THE EXAMPLE INPUT AS DESIRED; THEN COPY AND PASTE INTO A SPSS SYNTAX WINDOW AND RUN; OUTPUT BOTH TO SPREADSHEET AND OUTPUT WINDOW].
This program uses the difference in proportions (or equivalently the odds ratio) as the effect size, see http://en.wikipedia.org/wiki/Effect_size#Cohen.27s_d.
p1 and p2 are the proportions in groups 1 and 2 respectively being compared, delta is the ratio of sizes of group 2 to group 1, alpha is the (two-tailed) type I error. The program then outputs the total sample size required for the specified power.
DATA LIST free /alpha p1 p2 delta power. BEGIN DATA. .05 0.19 0.09 2 0.87 .05 0.40 0.35 2 0.80 END DATA. define propn (!pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1)). COMPUTE #POW = !5. compute #conf = 1-!1. compute #lc3 = 1. compute #ind=0. compute n1=3. compute n2=!4*n1. compute #pbar= (n1*!2 + n2*!3) / (n1+n2). compute #z2= ( (!2-!3) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2. compute oddsr = ( n1*!2*n2*(1-!3) ) / ( n1*(1-!2)*n2*!3 ). compute #CUMF2=1-ncdf.chisq(idf.chisq(1-!1,1),1,#z2). compute #diff=1. SET MXLOOPS=40000. LOOP IF (#DIFF GT .00005) . + DO IF (#CUMF2 LT #pow) . + COMPUTE #LC3 = n1. + COMPUTE n1 = (n1 + 1). + compute n2=!4*n1. + compute #pbar= (n1*!2 + n2*!3) / (n1+n2). + compute #z2= ( (!2-!3) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2. + compute #CUMF2=1-ncdf.chisq(idf.chisq(1-!1,1),1,#z2). + ELSE . + COMPUTE #LC1 = n1 . + COMPUTE n1 = (n1 + #LC3)/2 . + compute n2=!4*n1. + compute #pbar= (n1*!2 + n2*!3) / (n1+n2). + compute #z2= ( (!2-!3) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2. + compute #CUMF2=1-ncdf.chisq(idf.chisq(1-!1,1),1,#z2). + END IF . + COMPUTE #DIFF = ABS(#CUMF2 - #pow) . END LOOP . if (n1-trunc(n1) gt 0.5) #ind=1. if (#ind eq 0) n1=trunc(n1)+1. if (#ind eq 1) n1=rnd(n1). EXECUTE . compute alpha=!1. compute p1=!2. compute p2=!3. compute n2=!4*n1. compute power=!5. formats n1 (f7.0) n2 (f7.0) alpha (f5.2) p1 (f5.2) p2 (f5.2) power (f5.2). variable labels n1 'Sample Size 1' /n2 'Sample Size 2' /alpha 'Alpha' /p1 'Proportion 1' /p2 'Proportion 2' /power 'Power'. report format=list automatic align(center) /variables=n1 n2 alpha p1 p2 power /title "Sample Size required for a two sample, two-tailed binomial test" . !enddefine. matrix. get m /variables=alpha p1 p2 delta power /missing=omit. compute alpha=make(1,1,0). compute p1=make(1,1,0). compute p2=make(1,1,0). compute delta=make(1,1,0). compute power=make(1,1,0). compute alpha=m(:,1). compute p1=m(:,2). compute p2=m(:,3). compute delta=m(:,4). compute power=m(:,5). end matrix. propn alpha p1 p2 delta power.