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

[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 Cohen's d or Hedge's g as the effect size, depending on calculation of pooled group standard deviation, for example in an equal groups unpaired t-test .

Alpha is the (two-tailed) type I error, mdiff is the difference in group means, sd is the average group standard deviation with power inputted in the power column. The program then outputs the common group sample size. Calculations can also be done using a spreadsheet. You can specify input in terms of Cohen's d. This may be done in R.

```DATA LIST free
/alpha (f10.5) mdiff (f10.5) sd (f10.5) power (f10.5).
BEGIN DATA.
0.05 6.0 10.0 0.90
0.05 3.0 4.0 0.90
0.05 6.0 10.0 0.90
END DATA.

define unpairt (!pos !tokens(1)
/ !pos !tokens(1)
/ !pos !tokens(1)
/ !pos !tokens(1)).
COMPUTE #POW = !4.
compute #conf = (1-!1/2).
compute #lc3 = 1.
compute #ind=0.
compute n = 20.
comment COMPUTE #LC1 = 2.000.
COMPUTE #CUMF2 = 1-ncdf.t(idf.t(#conf,2*n-2),(2*n)-2,(!2)/sqrt(2*!3*!3/n)).
COMPUTE #DIFF = 10 .
SET MXLOOPS=10000.
LOOP IF (#DIFF GT .00005) .
+       DO IF (#CUMF2 LT #pow) .
+               COMPUTE #LC3 = N .
+               COMPUTE N = (N + 0.5).
+               COMPUTE #CUMF2 =  1-ncdf.t(idf.t(#conf,2*n-2),(2*n)-2,(!2)/sqrt(2*!3*!3/n)).
+       ELSE .
+               COMPUTE #LC1 = n .
+               COMPUTE n = (n - 0.5) .
+               COMPUTE #CUMF2 = 1-ncdf.t(idf.t(#conf,2*n-2),(2*n)-2,(!2)/sqrt(2*!3*!3/n)).
+       END IF .
+       COMPUTE #DIFF = ABS(#CUMF2 - #pow) .
END LOOP .
compute #pow2 = 1-ncdf.t(idf.t(#conf,2*n-2),(2*n)-2,(!2)/sqrt(2*!3*!3/n)).
compute #differ=abs(#pow-#pow2).
if (n-trunc(n) gt 0.5) #ind=1.
if (#ind eq 0) n=trunc(n)+1.
if (#ind eq 1) n=rnd(n).
EXECUTE .
compute alpha=!1.
compute mdiff=!2.
compute sd=!3.
compute power=!4.
formats n (f7.0) alpha (f5.2) mdiff (f5.2) sd (f5.2) power (f5.2).
variable labels n 'Sample Sizes Required' /alpha 'Alpha' /mdiff 'Mean Difference' /sd 'SD' /power 'Power'.
report format=list automatic align(center)
/variables=n alpha mdiff sd power
/title "Unpaired t-test sample size for given power assuming equal groups" .
!enddefine.

set errors=none.

matrix.
get m /variables=alpha mdiff sd power  /missing=omit.
compute alpha=make(1,1,0).
compute mdiff=make(1,1,0).
compute sd=make(1,1,0).
compute power=make(1,1,0).
compute alpha=m(:,1).
compute mdiff=m(:,2).
compute sd=m(:,3).
compute power=m(:,4).
end matrix.
unpairt alpha mdiff sd power.```

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