To use these macros, put the text files below in the MACROS subdirectory of the Minitab program directory as DEVMEAN.MAC, DEVMED.MAC, FKTEST.MAC, LEVENE.MAC, MEDBOX.MAC, and SPRLEVGR.MAC. The MACROS subdirectory is commonly set up as
by the Student Edition of Minitab, Version 12 for Windows 95/98. There may be other locations for specific installations, however.
Suppose that data are in columns c3, c6, c7, and c8. The macros can be invoked by a Session window command like
Note the leading % sign. You must have the command line option of the session window ENABLED. Data columns may also be specified by name. The macros and their functions follow.
DEVMEAN.MAC -- given a set of columns of data, forms a stacked column of data containing deviations from respective group means (signed, NOT absolute deviations) and a column of group indices or subscripts.
# %DEVMEAN # From columns x.1 to x.num, put deviations from means in difmean # with index elements in idx # adif has data that has groups indexed by column idx, # creates a new col adif that is absolute diffs from mean # 1999-2-13 # J C Nash # macro is for Student Edition of Minitab for Windows # Optionally using 'devns' subcommand puts absolute deviations from # MEANS in specified column with subscripts specified by 'subs' # subcommand macro devmean x.1-x.num difmean idx mcolumn difmean idx x.1-x.num mconstant num cst.1-cst.num ii jj dlen echo note Compute absolute deviations from means of variables note With boxplots thereof. noecho # create column for the data and means stack x.1-x.num difmean; subs idx. let dlen = n(difmean)+nmiss(difmean) # print dlen if num=0 echo note No data provided noecho else do ii=1:num let cst.ii=mean(x.ii) enddo echo note column means in order noecho print cst.1-cst.num do jj=1:dlen let ii=idx(jj) if ii<>'*' let difmean(jj)=(difmean(jj)-cst.ii) endif enddo endif echo endmacro
DEVMED.MAC -- given a set of columns of data, forms a stacked column of data containing deviations from respective group medians (signed, NOT absolute deviations) and a column of group indices or subscripts.
# %DEVMED # From columns x.1 to x.num, put deviations from medians in difmed # with index elements in idx # adif has data that has groups indexed by column idx, # creates a new col adif that is absolute diffs from median # 1999-2-13 # J C Nash # macro is for Student Edition of Minitab for Windows # Optionally using 'devns' subcommand puts absolute deviations from # MEDIANS in specified column with subscripts specified by 'subs' # subcommand macro devmed x.1-x.num difmed idx mcolumn difmed idx x.1-x.num mconstant num cst.1-cst.num ii jj dlen echo note Compute absolute deviations from medians of variables note With boxplots thereof. noecho # create column for the data and medians stack x.1-x.num difmed; subs idx. let dlen = n(difmed)+nmiss(difmed) # print dlen if num=0 echo note No data provided noecho else do ii=1:num let cst.ii=median(x.ii) enddo echo note column medians in order noecho print cst.1-cst.num do jj=1:dlen let ii=idx(jj) if ii<>'*' let difmed(jj)=(difmed(jj)-cst.ii) endif enddo endif echo endmacro
FKTEST.MAC -- conducts the Fligner-Killeen tests on data in the specified columns, using absolute deviations from group medians. The test value fkx is compared to a chi-squared statistic, while fky is compared to an F statistic.
# %FKTEST # From columns x.1 to x.num, # adif has data that has groups indexed by column idx, # creates a new col adif that is absolute diffs from median # 1999-2-13, 2000-8-31 # J C Nash # macro is for Student Edition of Minitab for Windows macro fktest x.1-x.num mcolumn adif idx x.1-x.num rnk skor mconstant num cst.1-cst.num ii jj dlen fkx fky fkxx echo note Fligner-Killeen normal scores test of equality of variances noecho # create column for the data and medians stack x.1-x.num adif; subs idx. # number of data elements in column is sum of data + missing let dlen = n(adif)+nmiss(adif) # print dlen if num=0 echo note No data provided noecho else do ii=1:num let cst.ii=median(x.ii) enddo # echo # note column medians in order # noecho # print cst.1-cst.num do jj=1:dlen let ii=idx(jj) if ii<>'*' # create deviations from medians let adif(jj)=abs(adif(jj)-cst.ii) endif enddo echo note Fligner Killeen test of homoskedasticity noecho rank adif rnk let rnk=0.5*(1+rnk/(n(adif)+1)) invcdf rnk skor; normal 0 1. name rnk 'rank' name skor 'score' # remove # in next line to print intermediate values # print idx adif rnk skor # compute do ii=1:num let cst.ii=0 enddo # mean of all scores let fkxx=mean(skor) # fky will hold variance of scores let fky=0 do jj=1:dlen if skor(jj)<>'*' let ii=idx(jj) let cst.ii=cst.ii+skor(jj) let fky=fky+(skor(jj)-fkxx)**2 endif enddo # print cst.1-cst.num let fky=fky/(n(adif)-1) # print fky fkxx # and compute the means by category do ii=1:num let cst.ii=cst.ii/n(x.ii) enddo # print cst.1-cst.num let fkx=0 do ii=1:num let fkx=fkx+n(x.ii)*(cst.ii-fkxx)**2 enddo # print fkx let fkx=fkx/fky let fkxx=num-1 echo note Fligner Killeen x statistic -- compare to Chisquare # print fkx noecho cdf fkx; chisquare fkxx. # # Extend to fky using F statistic let fky=(fkx/(num-1))/((n(adif)-1-fkx)/(n(adif)-num)) # print fky # put in appropriate output let fkx=n(adif)-num echo note Fligner Killeen y statistic -- compare to F noecho cdf fky; F fkxx fkx. endif echo endmacro
LEVENE.MAC -- carries out the Levene deviation-from-mean and deviation-from-median tests.
# %LEVENE # From columns x.1 to x.num, # adif has data that has groups indexed by column idx, # creates a new col adif that is absolute diffs from median # 1999-2-13 # J C Nash # macro is for Student Edition of Minitab for Windows # Optionally using 'devns' subcommand puts absolute deviations from # MEANS in specified column with subscripts specified by 'subs' # subcommand macro levene x.1-x.num; devns adif; subs idx. mcolumn adif idx x.1-x.num rnk mconstant num cst.1-cst.num ii jj dlen fkx fky fkxx echo note Levene ANOVA tests for equality of variances on columns noecho brief 0 # move data (stacked) into adif stack x.1-x.num adif; subs idx. let dlen = n(adif)+nmiss(adif) if num=0 echo note No data provided noecho else do ii=1:num let cst.ii=mean(x.ii) enddo echo note column means in order # noecho # print cst.1-cst.num do jj=1:dlen let ii=idx(jj) if adif(jj)<>'*' let adif(jj)=abs(adif(jj)-cst.ii) endif enddo # now do the anova numerator # compute do ii=1:num let cst.ii=0 enddo # fky will hold variance of scores do jj=1:dlen if adif(jj)<>'*' let ii=idx(jj) let cst.ii=cst.ii+adif(jj) endif enddo do ii=1:num let cst.ii=cst.ii/n(x.ii) enddo # echo # note Means of absolute deviations from the mean # noecho # print cst.1-cst.num # mean of all scores let fkxx = mean(adif) # could incorporate in loop above let fky=0 do ii=1:num let fky=fky+n(x.ii)*(cst.ii-fkxx)**2 enddo let fky=fky/(num-1) # print fky fkxx # numerator complete in fky # Levene mean fkxx no longer needed let fkx=0 do jj=1:dlen if adif(jj)<>'*' let ii=idx(jj) let fkx=fkx+(adif(jj)-cst.ii)**2 endif enddo # print fkx let fkx=fkx/(n(adif)-num) # print fkx # denominator complete let fky=fky/fkx # print fky let fkx=num-1 let fkxx=n(adif)-num brief 2 # echo note Levene MEAN test cdf fky; F fkx fkxx. noecho brief 0 erase adif erase idx endif # now do median test brief 0 # move data (stacked) into adif stack x.1-x.num adif; subs idx. let dlen = n(adif)+nmiss(adif) if num=0 echo note No data provided noecho else do ii=1:num let cst.ii=median(x.ii) enddo echo note column means in order # noecho # print cst.1-cst.num do jj=1:dlen let ii=idx(jj) if adif(jj)<>'*' let adif(jj)=abs(adif(jj)-cst.ii) endif enddo # now do the anova numerator # compute do ii=1:num let cst.ii=0 enddo # fky will hold variance of scores do jj=1:dlen if adif(jj)<>'*' let ii=idx(jj) let cst.ii=cst.ii+adif(jj) endif enddo do ii=1:num let cst.ii=cst.ii/n(x.ii) enddo # echo # note Means of absolute deviations from the mean # noecho # print cst.1-cst.num # mean of all scores let fkxx = mean(adif) # could incorporate in loop above let fky=0 do ii=1:num let fky=fky+n(x.ii)*(cst.ii-fkxx)**2 enddo let fky=fky/(num-1) # print fky fkxx # numerator complete in fky # Levene mean fkxx no longer needed let fkx=0 do jj=1:dlen if adif(jj)<>'*' let ii=idx(jj) let fkx=fkx+(adif(jj)-cst.ii)**2 endif enddo # print fkx let fkx=fkx/(n(adif)-num) # print fkx # denominator complete let fky=fky/fkx # print fky let fkx=num-1 let fkxx=n(adif)-num brief 2 # echo note Levene MEDIAN test cdf fky; F fkx fkxx. noecho brief 0 erase adif erase idx endif # brief 2 echo endmacro
MEDBOX.MAC -- draws notched boxplots of the absolute deviations from group medians. Note that these are in the character graphics format.
# %MEDBOX # From columns x.1 to x.num, # adif has data that has groups indexed by column idx, # creates a new col adif that is absolute diffs from median # 1999-2-13 # J C Nash # macro is for Student Edition of Minitab for Windows # Optionally using 'devns' subcommand puts absolute deviations from # MEDIANS in specified column with subscripts specified by 'subs' # subcommand macro medbox x.1-x.num; devns adif; subs idx. mcolumn adif idx x.1-x.num mconstant num cst.1-cst.num ii jj dlen echo note Compute absolute deviations from medians of variables note With boxplots thereof. noecho # create column for the data and medians stack x.1-x.num adif; subs idx. let dlen = n(adif)+nmiss(adif) # print dlen if num=0 echo note No data provided noecho else do ii=1:num let cst.ii=median(x.ii) enddo echo note column medians in order noecho print cst.1-cst.num do jj=1:dlen let ii=idx(jj) if ii<>'*' let adif(jj)=abs(adif(jj)-cst.ii) endif enddo gstd boxplot adif; by idx; notch. name adif 'adevmed' endif echo endmacro
SPRLEVGR.MAC -- draws a spread-level graph (with a fitted line plot) of the data in the specified columns.
# %SPRLEVGR # From columns x.1 to x.num, # adif has data that has groups indexed by column idx, # creates a new col adif that is absolute diffs from median # 1999-2-13 # J C Nash # macro is for Student Edition of Minitab for Windows # Optionally using 'devns' subcommand puts absolute deviations from # MEDIANS in specified column with subscripts specified by 'subs' # subcommand macro sprlevgr x.1-x.num; spreads adif; levels meds; log; subs idx. mcolumn adif idx x.1-x.num meds mconstant num cst.1-cst.num ii jj dlen echo note Compute absolute deviations from medians of variables note or of log variables note And produce spread level graph noecho # create column for the data and medians stack x.1-x.num adif; subs idx. if log = 1 echo note Log transform being used noecho let adif = log(adif) # Should check for negative numbers!!! endif # create column for medians copy adif meds let dlen = n(adif)+nmiss(adif) # print dlen if num=0 echo note No data provided noecho else do ii=1:num if log=1 let cst.ii=log(median(x.ii)) # NOTE median unaffected by logarithm, so can take log(med) or med(log) else let cst.ii=median(x.ii) endif enddo # echo # note column medians in order # noecho # print cst.1-cst.num do jj=1:dlen let ii=idx(jj) if adif(jj)<>'*' let adif(jj)=abs(adif(jj)-cst.ii) let meds(jj)=cst.ii endif enddo name adif 'adevmed' # now do the graphs let adif=sqrt(adif) gpro %fitline adif meds endif echo endmacro