macro fishersim p1 p2 n1 n2 #macro finds the power of Fisher's exact test by simulation #Uses Ha: p1 < p2 #This macro was written to validate the fisherspower macro and #shouldn't be of much use to anyone. The macro finds the power to #reject Ho: p1 = p2 by simulating many random samples from two #binomial populations with those fractions defective. #Example call: #%fishersim 0.01 0.20 80 80 #Copyright Mathews and Malnar, December 2001 #Mathews and Malnar, Statistical Trainers and Consultants #217 Third Street, Fairport Harbor, OH 44077 #440-350-0911 pmathews@apk.net mcolumn x1 x2 rejectHo mconstant p1 p2 n1 n2 i bad1 totn totbad thisp power trials note note This macro runs very slowly. Please be patient. note Macro is running ... note let trials=1000 rand trials x1; binomial n1 p1. rand trials x2; binomial n2 p2. let totn = n1 + n2 do i=1:trials if x1(i) < x2(i) #Then there's a chance to reject Ho let bad1=x1(i) let totbad = x1(i) + x2(i) cdf bad1 thisp; #Fisher's test hypergeometric totn n1 totbad. if thisp <= 0.05 #reject Ho let rejectHo(i) = 1 else let rejectHo(i) = 0 endif else let rejectHo(i) = 0 endif enddo let power=sum(rejectHo)/trials print power endmacro