/*SAMPLE SIZE AND POWER calculators for RISK RATIO (for cohort or cross-sectional studies)*/ /*Caclulates sample size for fixed power or power for fixed sample size*/ /*Calculates sample size and power for a range of risk ratio values*/ /*Assumes two groups: exposed and unexposed*/ /*Assumes binary outcome variable*/ /*Null hypothesis: proportion that have the outcome is the same in both groups (=RR is equal to 1.0)*/ /*Assumes two-tailed test at .05 significance*/ /*Author: Kristin Cobb, March 2005*/ /*SAMPLE SIZE CALCULATOR: sample size from power: under different assumptions for the risk ratio*/ /*User enters: punexp = proportion of the unexposed group that you expect to have the outcome (*entered as a decimal, e.g. .20) power = how much statistical power you want (entered as a decimal, e.g. 0.80) r = ratio of the unexposed group to the exposed group (e.g., 2 unexposed per exposed) RR= Expected risk ratio due to exposure (e.g. risk ratio for exposed: unexposed) ltf= expected loss to follow up or expected percentage of the sample for whom you expect to have incomplete outcome data (entered as a decimal, e.g. .15) */ %macro samplesize4(punexp, power, r, RR, ltf); data samplesize4; if &RR.>1 then do; do i=1.1 to (&RR.+1) by .10; RR=i; pexp=&punexp.*RR; pavg=(pexp+&punexp.*&r.)/(1+&r.); Zbeta=probit(&power.); num=(1.96+Zbeta)**2; den=(pexp-&punexp.)**2; nexposed=ceil(((num*pavg*(1-pavg)*(&r.+1))/(&r.*den))/(1-<f.)); nunexposed=ceil((&r.*nexposed)); output; end; end; if &RR.<1 then do; do i=.1 to .90 by .10; RR=i; pexp=&punexp.*RR; pavg=(pexp+&punexp.*&r.)/(1+&r.); Zbeta=probit(&power.); num=(1.96+Zbeta)**2; den=(pexp-&punexp.)**2; nexposed=ceil(((num*pavg*(1-pavg)*(&r.+1))/(&r.*den))/(1-<f.)); nunexposed=ceil((&r.*nexposed)); output; end; end; run; proc print data=samplesize4 noobs; var RR nexposed nunexposed; run; %mend samplesize4; /*example usage of sample size macro:*/ %samplesize4(punexp=.20, power=.925, r=2, RR=2.0, ltf=.15); /*POWER CALCULATOR: power from sample size: under different assumptions for the risk ratio*/ /*User enters: Nexposed = number of exposed subjects in the study Nunexposed = number of unexposed subjects in the study Punexp = proportion of the unexposed group that you expect to have the outcome (*entered as a decimal, e.g. .20) RR= Expected risk ratio due to exposure (e.g. risk ratio for exposed: unexposed) ltf= expected loss to follow up or expected percentage of the sample for whom you expect to have incomplete outcome data (entered as a decimal, e.g. .15) */ %macro power4(nexposed, nunexposed, punexp, RR, ltf); data power4; if &RR.>1 then do; do i=1.1 to &RR.+1 by .10; RR=i; r=&nunexposed./&nexposed.; pexp=&punexp.*RR; pavg=(pexp+&punexp.*r)/(1+r); den=(pexp-&punexp.)**2; num=(&nexposed.*(1-<f.)*den*r)/((r+1)*pavg*(1-pavg)); Zbeta=sqrt(num)-1.96; power=cdf('normal',Zbeta); output; end; end; if &RR.<1 then do; do i=.1 to .90 by .10; RR=i; r=&nunexposed./&nexposed.; pexp=&punexp.*RR; pavg=(pexp+&punexp.*r)/(1+r); den=(pexp-&punexp.)**2; num=(&nexposed.*(1-<f.)*den*r)/((r+1)*pavg*(1-pavg)); Zbeta=sqrt(num)-1.96; power=cdf('normal',Zbeta); output; end; end; run; proc print data=power4 noobs; var RR power; run; %mend power4; /*example usage of power macro:*/ %power4(nexposed=100, nunexposed=200, punexp=.20, RR=2.0, ltf=.15);