noecho ################################################################ # # Name: twopropsim.mtb # Date: October 11, 2009 # Author: Dennis Walsh # # Purpose: This Minitab macro will approximate the p-value # for testing the equality of two population proportions. # # Hypotheses: Ho: p1=p2 versus Ha: p1 not= p2. # # Method: We assume two independent random samples of # sizes n1 and n2 with number of successes x1 and x2 respectively. Using # a Bayesian approach with the observed data, we assume a # beta(x1+x2+1, n1+n2-x1-x2+1) distribution for the unknown common null # proportion p. We then generate a value for p from this beta distribution. # Next we use that random p to generate an observation s1 from a binomial(n1,p) # distribution and an observation s2 from a binomial(n2,p) distribution. # Exexuting the macro 10,000 times will provide 10,000 random pairs (s1,s2). # Counting the number of times |s1/n1-s2/n2| is greater than or equal to # |x1/n1-x2/n2| provides a proportion that is used for the p-value of the test. # # Set up: Prior to invoking the exec command in Minitab, store # the constants x1, n1, x2, n2, 0, and 0 in k101 through k106. # # Results: After running the macro 10,000 times, view the # estimated p-value by printing constant k114. Clean up afterwards by # erasing c101-c104 and k101-k104. # ################################################################ noecho let k108=abso(k101/k102-k103/k104) let k109=k101+k103+1 let k110=k102+k104-k109+2 random 1 c101; beta k109 k110. let k111=c101(1) random 1 c102; binomial k102 k111. random 1 c104; binomial k104 k111. let k112=abso(c102(1)/k102-c104(1)/k104) let k113=round(.5*(sign(k112-k108)+1)) let k105=k113+k105 let k106=1+k106 let k114=k105/k106 name k114 "estimated p_value" end