macro Fishers D1 D2 N1 N2 #This macro calculates the one-tailed Fisher's method p value for the #two-sample test to compare two population fractions defective. The #user must specify the number of defectives in the samples (D1 and D2) #and the sample sizes (N1 and N2). #Example calling statement: # mtb> %fishers 0 4 20 20 #Answer: p = 0.0530146 #Copyright (c) Paul G. Mathews 19 October 2001 All rights reserved #Paul Mathews and Rebecca Malnar, Statistical Trainers and Consultants #217 Third Street, Fairport Harbor, OH 44077 #440-350-0911 #pmathews@apk.net #This macro may contain errors and its accuracy is not guaranteed. Use #this macro at your own risk. Mathews and Malnar take no responsibility #for the use or misuse of this macro. mconstant N TotDef N1 N2 D1 D2 p1 p2 pvalue mtitle "Fisher's Method to Compare Two Population Fractions Defective" notitle let N=N1+N2 let TotDef=D1+D2 let p1=D1/N1 let p2=D2/N2 print N1 D1 p1 note print N2 D2 p2 if p1 p2" print pvalue endif endmacro macro hypergeometric x A B n PxABn; cum. #This macro calculates the hypergeometric distribution #h(x;A,B,n). The funny order of the different terms is #necessary to avoid overflow errors in the factorials. #Example call: # mtb> %hypergeometric 2 6 24 5 k1 mconstant x A B n PxABn AplusB i nminusx let AplusB=A+B if (x<0) or (x>n) or (x>A) or (n<0) or (n>AplusB) let PxABn=0 elseif (x=0) let PxABn=1 do i=1:n let PxABn=(B+1-i)/(A+B+1-i)*PxABn enddo elseif cum #cumulative probability let PxABn=1 do i=1:x let PxABn=(A+1-i)/(x+1-i)/(A+B+1-i)*(n+1-i)*PxABn enddo let nminusx=n-x do i=1:nminusx let PxABn=(B+1-i)/(A+B-x+1-i)*PxABn enddo else #not cumulative, i.e. single x let PxABn=1 do i=1:x let PxABn=(A+1-i)/(x+1-i)/(A+B+1-i)*(n+1-i)*PxABn enddo let nminusx=n-x do i=1:nminusx let PxABn=(B+1-i)/(A+B-x+1-i)*PxABn enddo endif endmacro