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

The program calculates the sample size for doing the McNemar test with a given power (An on-line power calculator is also available.)

P12 is the proportion of respondents you expect to change from group '1' to group '2' (the proportion which are in cell 12) and p21 the proportion of people you expect to change from group '2' to group '1'. Give the power and the type I error is alpha and total number of pairs required is outputted. A calculator is also available in a spreadsheet.

Time 1

Group

1

2

Time 2

1

p11

p12

2

p21

p22

[COPY AND PASTE CONTENTS OF BOX BELOW INTO A SPSS SYNTAX WINDOW; ADJUST DATA AS REQUIRED]

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

None: FAQ/power/mcn (last edited 2013-03-08 10:18:05 by localhost)