FAQ/power/propsn - CBU statistics Wiki
location: / propsn

This program uses the difference in proportions (or equivalently the odds ratio) as the effect size.

p1 and p2 are the proportions in groups 1 and 2 respectively being compared, delta is the ratio: size of group 2 / size of group 1, alpha is the (two-tailed) type I error. The program then outputs the sample sizes required for the specified power. A power calculator is also available in a spreadsheet or using a web calculator here. and in R and G*POWER3.

An example uses marginal probabilities to compute cell probabilities in a 2x2 table to give inputs for a power analysis.

[ADJUST THE EXAMPLE INPUT AS DESIRED; THEN COPY AND PASTE INTO A SPSS SYNTAX WINDOW AND RUN; OUTPUT BOTH TO SPREADSHEET AND OUTPUT WINDOW].

```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.

set errors=none.
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.
define propncc (!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 #contc= 0.5*((1/n1)+(1/n2)).
compute #pbar= (n1*p1 + n2*p2) / (n1+n2).
compute #z21= ( ( abs(p1-p2)-#contc ) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2.
compute #CUMF2=1-ncdf.chisq(idf.chisq(1-alpha,1),1,#z21).
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 #contc= 0.5*((1/n1)+(1/n2)).
+                      compute #pbar= (n1*p1 + n2*p2) / (n1+n2).
+                      compute #z21= ( ( abs(p1-p2)-#contc ) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2.
+                      compute #CUMF2=1-ncdf.chisq(idf.chisq(1-alpha,1),1,#z21).
+       ELSE .
+               COMPUTE #LC1 = n1 .
+               COMPUTE n1 = (n1 + #LC3)/2 .
+                      compute n2=!4*n1.
+                      compute #contc= 0.5*((1/n1)+(1/n2)).
+                      compute #pbar= (n1*p1 + n2*p2) / (n1+n2).
+                      compute #z21= ( ( abs(p1-p2)-#contc ) /sqrt( #pbar*(1-#pbar)*( (1/n1) + (1/n2) ) ) )**2.
+                      compute #CUMF2=1-ncdf.chisq(idf.chisq(1-alpha,1),1,#z21).
+       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 Sizes for a two sample, two-tailed binomial test (continuity corrected)" .
!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.
propncc alpha p1 p2 delta power.```

None: FAQ/power/propsn (last edited 2013-03-08 10:17:39 by localhost)