macro
fisherspower p1 p2 n1 n2;
sign alpha.
#Fisher's exact test is the two independent sample test for Ho: p1 = p2 vs.
#Ha: p1 < p2. This macro calculates the power of the test for user
#specified values of p1, p2, n1, and n2 where:
# p1 and p2 are the population fractions defective and
# n1 and n2 are the sizes of the two samples.
#The specified values of p1 and p2 must meet the condition p1 < p2.
#Example calling statement:
# mtb > %fisherspower 0.01 0.05 80 80
#Macro should return power = 0.211135
#See Mathews, Sample Size Calculations, Section 4.3.2.1, p. 97.
#This macro may contain errors. MM&B Inc. is not responsible for its use or misuse.
#Always check its answers by manual calculation or cross check with another calculator.
#Mathews Malnar and Bailey, Inc.
#217 Third Street, Fairport Harbor, OH 44077
#Phone: 440-350-0911
#E-mail: paul@mmbstatistical.com
#Copyright (c) Mathews Malnar and Bailey, Inc., 2001 - 2013, All rights reserved.
#Rev. (2/13/05, PGM): Validated for V14.
mconstant p1 p2 n1 n2 alpha x1 x2 bx1 bx2 cumbx2
mconstant ntot xtot thisp power time incpow
default alpha=0.05
#This algorithm searches the x1 by x2 table where x1 = 0:n1 and x2 = 0:n2
#for the smallest x2 that makes Fisher's test significant for a given x1.
#Then it calculates the contribution to the power from the binomial distributions
#of x1 and x2: b(x = x1;n1,p1) x b(c = x2;n2,p2).
note
note This macro runs very slowly. Please be patient.
note The macro is running ...
note
brief 0 #suppress diagnostic print statements when not needed
let ntot=n1+n2
let power=0
let x2=0 #Should this be x2 = -1? Technically yes but practically no because can never reject HA when x2=0.
do x1=0:n1
let thisp=1
while (thisp>alpha) and (x2