/*SAMPLE SIZE AND POWER calculators for TTEST (cross-sectional study, cohort study, case-control study)*/ /*Caclulates sample size for fixed power or power for fixed sample size*/ /*Calculates sample size and power for a range of difference-in-means values*/ /*Assumes two groups: one smaller group and one larger group (or equal size)--could be cases and controls, exposed and unexposed, treatment and control, etc.*/ /*Assumes a continuous outcome variable*/ /*Null hypothesis: difference in means between the two groups is equal to zero*/ /*Assumes two-tailed test at .05 significance*/ /*Author: Kristin Cobb, March 2005*/ /*SAMPLE SIZE CALCULATOR: sample size from power: under different assumptions for the difference in means*/ /*User enters: power = how much statistical power you want (entered as a decimal, e.g. 0.80) r = ratio of the larger group to the smaller group (e.g., 2:1 control:treatment) meandiff = Expected difference in means (of the continous outcome) between the two groups stddev = expected standard deviation in the continuous outcome (entered in the same units as the meandiff) ltf = percent of people you expect to lose (for cohort study) or for whom you expect to have incomplete data on (for cross-sectional or case-control study), (entered as a decimal, e.g. 0.15) */ %macro samplesize2(power, r, meandiff, stddev, ltf); data samplesize2; diffZ=abs(&meandiff./&stddev.); do i=.1 to (diffZ+1) by .1; Z=i; Zbeta=probit(&power.); num=((&r.+1)/&r.)*(1.96+Zbeta)**2; nsmall=ceil((num*(1/Z**2))/(1-<f.)); nlarge=ceil((&r.*nsmall)); difference=Z*&stddev.; stddev = &stddev.; output; end; run; proc print data=samplesize2 noobs; var difference stddev Z nsmall nlarge; run; %mend samplesize2; /*example usage of sample size macro:*/ %samplesize2(power=.90, r=1, meandiff=50, stddev=50, ltf=.15); /*POWER CALCULATOR: power from sample size: under different assumptions for the magnitude of the difference in means*/ /*User enters: nlarge = number of people in the larger group nsmall = number of people in the smaller group meandiff = Expected difference in means (of the continous outcome) between the two groups stddev = expected standard deviation in the continuous outcome (entered in the same units as the meandiff) ltf = percent of people you expect to lose (for cohort study) or for whom you expect to have incomplete data on (for cross-sectional or case-control study), (entered as a decimal, e.g. 0.15) */ %macro power2(nlarge, nsmall, meandiff, stddev, ltf); data power2; diffZ=abs(&meandiff./&stddev.); do i=.1 to (diffZ+1) by .1; Z=i; r=&nlarge./&nsmall.; num=&nsmall.*(1-<f.)*(Z**2)*(r/(r+1)); Zbeta=sqrt(num)-1.96; power=cdf('normal',Zbeta); difference=Z*&stddev.; stddev = &stddev.; output; end; run; proc print data=power2 noobs; var difference stddev Z power; run; %mend power2; /*example usage of power macro:*/ %power2(nlarge=300, nsmall=200, meandiff=50, stddev=25, ltf=.15);