(I) SAMPLE SIZE FOR CONFIDENCE INTERVAL ESTIMATION *. DEFINE cimean(s=!TOKENS(1) /eps=!TOKENS(1) /ci=!DEFAULT(95) !TOKENS(1) ). * Sample size required for the CI for one mean *. MATRIX. PRINT /TITLE ' SAMPLE SIZE: CONFIDENCE INTERVAL PRECISION: ONE MEAN'. compute sd=!s. compute eps=!eps. compute ci=!ci. do if ci=95. compute zalfa=1.96. end if. do if ci=99. compute zalfa=2.576. end if. do if ci=99.9. compute zalfa=3.09. end if. print ci /format="f8.1" /title='Confidence level (%)'. print eps /format="f8.2" /title="Precision desired". print sd /format="f8.3" /title="Estimated Std deviation". compute n=TRUNC((zalfa**2)*(sd**2)/(eps**2))+1. print {n} /format="f8.0" /title="Sample size required". END MATRIX. !ENDDEFINE. * MACRO call: give values for Std deviation, precision desired and confidence level *. cimean s=8.7 eps=2. cimean s=8.7 eps=2 ci=99. cimean s=8.7 eps=2 ci=99.9. ******************************************************************************** (II) SAMPLE SIZE FOR HIPOTHESIS TESTING *. * Usual conditions for alfa and power (auxiliary file). * This file covers the most used conditions for sample size determination (add your own if required): - alfa=5% and 1% with for or two tailed tests - power=80%, 90%, 95% and 99%. * This file must be active in order to make the MACROS work. DATA LIST LIST /id(F2.0) alfa(f8.3) tails(F2.0) power(F8.3). BEGIN DATA 1 0.05 1 0.80 2 0.05 2 0.80 3 0.05 1 0.90 4 0.05 2 0.90 5 0.05 1 0.95 6 0.05 2 0.95 7 0.05 1 0.99 8 0.05 2 0.99 9 0.01 1 0.80 10 0.01 2 0.80 11 0.01 1 0.90 12 0.01 2 0.90 13 0.01 1 0.95 14 0.01 2 0.95 15 0.01 1 0.99 16 0.01 2 0.99 END DATA. COMPUTE zalfa = IDF.NORMAL(1-(alfa/tails),0,1) . COMPUTE zbeta = IDF.NORMAL(1-power,0,1) . EXEC. *********************************** * ONE SAMPLE, CONTINUOUS OUTCOMES * ***********************************. DEFINE onemeand(d=!TOKENS(1)). * Comparison of one sample mean with a population mean with Cohen's d as input (auxiliary file needed) *. MATRIX. PRINT /TITLE ' SAMPLE SIZE: ONE MEAN OR PAIRED MEANS (COHEN`S D)'. get id /var=id. get alfa /var=alfa. get tails/ var=tails. get power /var=power. get zalfa /var=zalfa. get zbeta /var=zbeta. compute cohend=!d. print cohend /format="f8.2" /title="Difference worth detecting (Cohen's d)". compute n=TRUNC(((zalfa-zbeta)/cohend)&**2)+1. print {id,100*alfa,tails,100*power,n} /format="f8.0" /clabels="Id","Alfa(%)","N. tails","Power(%)","N" /title="Sample size required". END MATRIX. !ENDDEFINE. * MACRO call: give value for d *. onemeand d=0.76. DEFINE onemeanx(m=!TOKENS(1) /s=!TOKENS(1) ). * Comparison of one sample mean with a population mean with mean diff and Std deviation as input (auxiliary file needed) *. MATRIX. PRINT /TITLE ' SAMPLE SIZE: ONE MEAN OR PAIRED MEANS (MEAN AND SD)'. get id /var=id. get alfa /var=alfa. get tails/ var=tails. get power /var=power. get zalfa /var=zalfa. get zbeta /var=zbeta. compute mean=!m. compute sd=!s. compute cohend=mean/sd. print {mean,sd,cohend} /format="f8.2" /clabels="Mean","Std.dev","Cohen's d" /title="Data for difference worth detecting". compute n=TRUNC(((zalfa-zbeta)/cohend)&**2)+1. print {id,100*alfa,tails,100*power,n} /format="f8.0" /clabels="Id","Alfa(%)","N. tails","Power(%)","N" /title="Sample size required". END MATRIX. !ENDDEFINE. * MACRO call: give values for mean dif (sample-population) and Std deviation *. onemeanx m=10 s=13.1. DEFINE onemeanp(d=!TOKENS(1) /n=!TOKENS(1) /alfa=!DEFAULT(0.05) !TOKENS(1) /tails=!DEFAULT(2) !TOKENS(1)). * Power of a test, given a sample size and an observed mean diff (Cohen's d) (auxiliary file NOT needed) *. MATRIX. PRINT /TITLE ' SAMPLE SIZE: POWER OF A TEST (ONE MEAN WITH COHEN`S D)'. compute cohend=!d. compute n=!n. compute alfa=!alfa. compute tails=!tails. compute pval=alfa/tails. do if pval=0.05. compute zalfa=1.645. end if. do if pval=0.025. compute zalfa=1.96. end if. do if pval=0.01. compute zalfa=2.326. end if. do if pval=0.005. compute zalfa=2.576. end if. print cohend /format="f8.2" /title="Difference worth detecting (Cohen's d)". print {100*alfa,tails,n} /format="f8.0" /clabels="Alfa(%)","Tails","N" /title="Input data". compute beta=100*(1-cdfnorm(zalfa-abs(cohend*sqrt(n)))). print beta /format="f8.1" /title="Power of the test (%)". END MATRIX. !ENDDEFINE. * MACRO call: give values Cohen's d, sample size used, alfa level and tails *. onemeanp d=0.76 n=14 alfa=0.05 tails=2. ************************************************ * TWO INDEPENDENT SAMPLES, CONTINUOUS OUTCOMES * ************************************************. DEFINE twomeand(d=!TOKENS(1)/ r=!DEFAULT(1)!TOKENS(1)). * Comparison of 2 independent means with Cohen's d as input (auxiliary file needed) *. MATRIX. PRINT /TITLE ' SAMPLE SIZE: TWO INDEPENDENT MEANS (STANDARDIZED MEAN DIFF.)'. get id /var=id. get alfa /var=alfa. get tails/ var=tails. get power /var=power. get zalfa /var=zalfa. get zbeta /var=zbeta. compute k=!r. compute cohend=!d. print cohend /format="f8.2" /title="Difference worth detecting (Cohen's d)". print k /format="f8.0" /title="Ratio (N2/N1)". * Harmonic N *. compute n=TRUNC(2*((zalfa-zbeta)/cohend)&**2)+1. * Sample Ni *. COMPUTE n1=n*(k+1)/(2*k). COMPUTE n2=n*(1+k)/2. print {id,100*alfa,tails,100*power,n1,n2,n1+n2} /format="f8.0" /clabels="Id","Alfa(%)","N. tails","Power(%)","N1","N2","Total N" /title="Sample size required". END MATRIX. !ENDDEFINE. * MACRO call: indicate values for d and ratio *. twomeand d=0.5 r=1. twomeand d=0.5 r=2. twomeand d=0.5 r=3. twomeand d=0.3 r=1. twomeand d=0.3 r=2. twomeand d=0.3 r=3. * If you want to get the output for just one condition, for example alfa=5%, one tail and 90% power (row Nr. 3). TEMPORARY. SELECT IF ID=3. twomeand d=0.5 r=2. DEFINE twomeanx(m1=!TOKENS(1)/ m2=!TOKENS(1)/ s=!TOKENS(1)/ r=!DEFAULT(1)!TOKENS(1)). * Comparison of 2 independent means with means and sd as input (auxiliary file needed) *. MATRIX. PRINT /TITLE ' SAMPLE SIZE: TWO INDEPENDENT MEANS (UNSTANDARDIZED MEANS DIFF.)'. get id /var=id. get alfa /var=alfa. get tails/ var=tails. get power /var=power. get zalfa /var=zalfa. get zbeta /var=zbeta. compute k=!r. compute mean1=!m1. compute mean2=!m2. compute sd=!s. compute cohend=(mean1-mean2)/sd. print {mean1,mean2,sd,cohend} /format="f8.2" /clabels="Mean1","Mean2","Std.dev","Cohen's d" /title="Data for difference worth detecting". print k /format="f8.0" /title="Ratio (N2/N1)". * Harmonic N *. compute n=TRUNC(2*((zalfa-zbeta)/cohend)&**2)+1. * Sample Ni *. COMPUTE n1=n*(k+1)/(2*k). COMPUTE n2=n*(1+k)/2. print {id,100*alfa,tails,100*power,n1,n2,n1+n2} /format="f8.0" /clabels="Id","Alfa(%)","N. tails","Power(%)","N1","N2","Total N" /title="Sample size required". END MATRIX. !ENDDEFINE. * MACRO call: give values for both means, common Std deviation and ratio *. twomeanx m1=4.5 m2=4 s=1 r=1. twomeanx m1=4.5 m2=4 s=1 r=2. twomeanx m1=4.5 m2=4 s=1 r=3. twomeanx m1=4.5 m2=4 s=0.9 r=1. twomeanx m1=4.5 m2=4 s=0.9 r=2. twomeanx m1=4.5 m2=4 s=0.9 r=3. DEFINE twomeanp(d=!TOKENS(1) /n1=!TOKENS(1) /n2=!TOKENS(1) /alfa=!DEFAULT(0.05) !TOKENS(1) /tails=!DEFAULT(2) !TOKENS(1)). * Power of a test, given sample sizes and an observed mean diff (Cohen's d) (auxiliary file NOT needed) *. MATRIX. PRINT /TITLE ' SAMPLE SIZE: POWER OF A TEST (TWO MEANS WITH COHEN`S D)'. compute cohend=!d. compute n1=!n1. compute n2=!n2. compute n=2*n1*n2/(n1+n2). compute alfa=!alfa. compute tails=!tails. compute pval=alfa/tails. do if pval=0.05. compute zalfa=1.645. end if. do if pval=0.025. compute zalfa=1.96. end if. do if pval=0.01. compute zalfa=2.326. end if. do if pval=0.005. compute zalfa=2.576. end if. print cohend /format="f8.2" /title="Difference worth detecting (Cohen's d)". print {100*alfa,tails,n1,n2} /format="f8.0" /clabels="Alfa(%)","Tails","N1","N2" /title="Input data". compute beta=100*(1-cdfnorm(zalfa-abs(cohend*sqrt(n/2)))). print beta /format="f8.1" /title="Power of the test (%)". END MATRIX. !ENDDEFINE. * MACRO call: give values for both sample sizes, Cohen's d, alfa level and tails *. twomeanp d=0.94 n1=7 n2=14 alfa=0.05 tails=2.