*! version 1.0.0 Hilbe Oct-12-92 STB-11 sg15 * Sample Size calculation: Means & proportions program define sampsiz version 3.0 parse "`*'", parse(" ,") local alpha "`1'" local power "`2'" local nullh "`3'" local testh "`4'" if "`testh'"=="" { di in red _n "Input is as follows:" di in red "sampsiz alpha power null test, [pr|m] t([p|c]) s([1|2]) " di in red _n "alpha usually .01, .05, .1" di in red "power = 1-beta (usually 4 times alpha:.01~.95,.05~.80)" di in red "null = null mean or proportion" di in red "test = test or alternate mean or proportion" di in red "[pr|m] REQUIRED : pr=proportion, m=means" di in red "t([p|c]) REQUIRED : p =population, c=comparison" di in red "s([1|2]) default=2: use s(1) for 1-sided test" di in red "sd = use only for means-population tests" di in red "sd1 sd2 = use only for means-comparison tests" di in red "r() = rate or multiple for unequal sample size comparison tests" exit 100 } conf n `alpha' conf n `power' conf n `nullh' conf n `testh' mac shift mac shift mac shift mac shift local options "Sides(integer 2) PRop Mean Type(string) Rate(real 1.0) SD(real 1.0) SD1(real 1.0) SD2(real 1.0)" parse "`*'" if "`sides'"=="1" { local alphaz = invnorm(1- `alpha') local powerz = invnorm(`power') } else { local alphaz = invnorm(1- `alpha'/2) local powerz = invnorm(`power') } if "`prop'"!="" { if "`type'"=="p" { #delimit ; local sizen = (`alphaz'*sqrt((`nullh'*(1-`nullh')))) + (`powerz'*sqrt((`testh'*(1-`testh')))); local sized = abs(`nullh'-`testh'); local size = (`sizen'/`sized')^2; #delimit cr } if "`type'"=="c" { #delimit ; local meanp = (`nullh'+(`rate'*`testh'))/(`rate'+1); local meanq = 1- `meanp'; local sizen1 = `alphaz'*sqrt((`rate'+1)*`meanp'*`meanq'); local sizen2 = sqrt(`rate'*`nullh'*(1-`nullh')+`testh'* (1-`testh')); local sizen3 = `powerz'*`sizen2'; local sizen4 = (`sizen1' + `sizen3')^2; /* - */ * local sized = `rate'* (`nullh'-`testh')^2; local sized = `rate'* (abs(`nullh'-`testh'))^2; local size = `sizen4'/`sized'; local size = (`size'/4) * ((1+ sqrt(1+(2*(`rate'+1)) / (`size'* `rate'* abs(`testh'-`nullh')))))^2; #delimit cr } di in gr _n(2) _col(20) "Estimated Sample Size Computation" di in gr _col(30) "Proportions" if "`type'"=="c" { di in gr _n " Number of cases: Sample 1 => " in ye int(`size'+.5) di in gr " Number of cases: Sample 2 => " in ye int((`size'+.5)*`rate') di in gr " Z-alpha => " in ye %3.2f `alphaz' di in gr " Z-power => " in ye %3.2f `powerz' } else { di in gr _n " Number of cases => " in ye int(`size'+.5) di in gr " Z-alpha => " in ye %3.2f `alphaz' di in gr " Z-power => " in ye %3.2f `powerz' } } if "`mean'"!="" { if "`type'"=="p" { local size = (((`alphaz'+`powerz')*`sd')/(`testh'-`nullh'))^2 di in gr _n(2) _col(20) "Estimated Sample Size Computation" di in gr _col(33) "Means" di in gr _n " Number of cases => " in ye int(`size'+.5) di in gr " Z-alpha => " in ye %3.2f `alphaz' di in gr " Z-power => " in ye %3.2f `powerz' } if "`type'"=="c" { #delimit ; local sizen1 = (`sd1'^2+(`sd2'^2*`rate'))*(`alphaz'+`powerz')^2; local sized1 = (`testh'-`nullh')^2; local size1 = `sizen1'/`sized1'; * local sizen2 = ((`rate'*`sd1'^2)+`sd2'^2)*(`alphaz'+`powerz')^2; * local sized2 = (`testh'-`nullh')^2; * local size2 = `sizen2'/`sized2'; local size2 = `size1'/`rate'; #delimit cr di in gr _n(2) _col(20) "Estimated Sample Size Computation" di in gr _col(33) "Means" di in gr _n " Number of cases: Sample 1 => " in ye int(`size1'+.5) di in gr " Sample 2 => " in ye int(`size2'+.5) di in gr " Z-alpha => " in ye %3.2f `alphaz' di in gr " Z-power => " in ye %3.2f `powerz' } } end