macro resampletwo x1 x2 iter dxbar; alternative tails. #By: PGMathews, March 13, 2000 forMinitab V12 #Revision: 1.0 March 13, 2000 PGM #This macro uses resampling methods to perform the two #independent sample test for a difference in location. #The macro accepts two input columns of data (x1 and x2) and resamples #the pooled observations. The difference between the means (dxbar) of #the resampled data are calculated for many (iter) resamples. Then #the p value is determined from the number of cases that #exceed the difference between the original sample means. The #macro can deal with unequal sample size and also calculates #the upper 95% confidence interval for the true p value when #the value of p is sufficiently small (<0.05). #Example call: # mtb> %resampletwo c1 c2 1000 c3; # subc> alternative 0. #The user must either install this macro in the Mtbwin\Macros directory, #change the default directory with the cd command to the directory where #this macro resides, or indicate the full path name to run the macro. mcolumn x1 x2 dxbar mcolumn x1x2 bool sampleID randID newx1 newx2 mcolumn pbool mconstant iter tails j nobs mconstant meanx1 meanx2 diffmean pvalue pmax df chisqr default tails=0 #default is two tailed test brief 1 #enable outputs to session window let meanx1=mean(x1) #the first sample's mean let meanx2=mean(x2) #the second sample's mean let diffmean=mean(x1)-mean(x2) #the difference between the means note print meanx1 meanx2 diffmean erase dxbar #clear out the old column note note This macro runs very slowly. Please be patient. note Macro is running... note do j=1:iter stack x1 x2 x1x2; #pool the data subs sampleID. let nobs=count(x1x2) #combined number of observations rand nobs bool #random values for resample sort sampleID randID; #randomize the sample IDs by bool. unstack x1x2 newx1 newx2; #unstack the pooled data by the random IDs subs randID. let dxbar(j)=mean(newx1)-mean(newx2) #find the difference between the new means enddo if tails=0 #two tailed test let pbool=abs(dxbar)>abs(diffmean) #count all of the extreme observations endif if tails=1 #right tailed test let pbool=dxbar>diffmean endif if tails=-1 #left tailed test let pbool=dxbar