FAQ/power/mcn - CBU statistics Wiki

Revision 1 as of 2006-09-19 15:49:18

Clear message
location: FAQ / power / mcn

DATA LIST free
/p12 p21 alpha power. 
BEGIN DATA. 
0.5 0.2 .05 0.80 
0.5 0.2 .10 0.80
0.5 0.2 .05 0.80
0.5 0.2 .05 0.80
0.5 0.2 .10 0.80
END DATA. 
print errors=none.

define mcn ( !pos !tokens(1)
                   /!pos !tokens(1)
                   /!pos !tokens(1)
                   /!pos !tokens(1)).

COMPUTE chisq1 = ((!1-!2)**2)/(!1+!2).
compute #df=1.
compute #conf = 1-!3.

COMPUTE #POW = !4.

compute #lc3 = 1.
compute #ind=0.
compute #chisq = 3.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(1)).
+               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.
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 p12=!1.
compute p21=!2.
compute alpha=!3.
compute power=!4.
formats p12 (f5.2) p21 (f5.2) alpha (f5.2) ntot (f5.2) power (f5.2).
variable labels p12 'Prop 12' /p21 'Prop 21' /alpha 'Two-Tailed Alpha' /ntot 'Total Number of Pairs' /power 'Power'.
report format=list automatic align(center)
  /variables=p12 p21 alpha ntot power 
  /title "Power for given sample size for McNemar's test from a 2x2 table of proportions" .
!enddefine.

matrix.
get m /variables=p12 p21 alpha power /missing=omit.
compute p12=make(1,1,0).
compute p21=make(1,1,0).
compute alpha=make(1,1,0).
compute power=make(1,1,0).
compute p12=m(:,1).
compute p21=m(:,2).
compute alpha=m(:,3).
compute power=m(:,4).
end matrix.
mcn p12 p21 alpha power.