Diff for "FAQ/power/propsn" - CBU statistics Wiki
location: Diff for "FAQ/power/propsn"
Differences between revisions 1 and 2
Revision 1 as of 2006-09-15 10:48:25
Size: 2496
Editor: PeterWatson
Comment:
Revision 2 as of 2006-09-15 10:50:08
Size: 3041
Editor: PeterWatson
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[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 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.

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

DATA LIST free
/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)).


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.
compute #lc3 = 1.
compute #ind=0.
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.
LOOP IF (#DIFF GT .00005) .
+       DO IF (#CUMF2 LT #pow) .
+               COMPUTE #LC3 = #CHISQ.
+               COMPUTE #CHISQ = (#chisq + rnd(#chisq/3)).
+               COMPUTE #CUMF2 =  1 - NCDF.CHISQ(IDF.CHISQ(#conf,#DF),#DF,#CHISQ).
+       ELSE .
+               COMPUTE #LC1 = #chisq .
+               COMPUTE #chisq = (#chisq + #LC3)/2 .
+               COMPUTE #CUMF2 = 1 - NCDF.CHISQ(IDF.CHISQ(#conf,#DF),#DF,#CHISQ).
+       END IF .
+       COMPUTE #DIFF = ABS(#CUMF2 - #pow) .
END LOOP .
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).
EXECUTE .
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'.
report format=list automatic align(center)
  /variables=ntot alpha p1 p2 ratio oddsr power 
  /title "Sample Size for comparing two independent proportions given power" .
!enddefine.

matrix.
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).
compute alpha=make(1,1,0).
compute power=make(1,1,0).
compute p11=m(:,1).
compute p12=m(:,2).
compute p21=m(:,3).
compute p22=m(:,4).  
compute alpha=m(:,5).
compute power=m(:,6).
end matrix.
orpow p11 p12 p21 p22 alpha power.

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