macro
fisherspowerslow p1 p2 n1 n2;
sign alpha.
#This macro calculates the power using two different algorithms to get through the
#x1 x x2 table. One method is fast but complicated. The other is VERY slow but easy to understand.
#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 > %fisherspowerslow 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 - 2016, All rights reserved.
#20050213, PGM: Validated for V14
#20160119, PGM: Validated for V17
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
#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).
#This algorithm searches the x1 x x2 table, with x1 in rows and x2 in columns, from top to
#bottom, left to right, where x1 = 0:n1 and x2 = 0:n2, for the smallest x2 that makes Fisher's
#test significant (p <= alpha) for a given x1. All of the values to the right of x2 up to n2
#are also statistically significant. The row's contribution to the power is given by
#b(x = x1;n1,p1) x b(x2 <= x <= n2;n2,p2).
mreset #Reset environment conditions to their default states after the macro is done.
note
note This macro runs very slowly. Please be patient.
note The macro is running ...
note
notitle
brief 0 #suppress output
#brief 2 #print the results from each iteration to the Session window
#This algorithm is fast, only considers the upper right corner of the x1 x x2 table:
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