macro ZTest Mu0 Sigma c1; Alternative Tails; Error Alpha. #Mathews and Malnar #217 Third Street, Fairport Harbor, OH 44077 #440-350-0911 pmathews@apk.net #Copyright September 2000 #Rev: 1.0 for Minitab V12.2 January 24, 2000, PGMathews #Rev: RMalnar August 24, 2000 #Rev: 9/18/2000 Changed subcommand defaults and added brief at end. #Macro calls MTB system macro ztest and then PGM macro #%ztestplot which plots the result. For Minitab to find the macro #you must either: #1) copy this file to your mtbwin\macros subdirectory #2) change the default directory to its location #3) use the full path name to the macro. #Example call: # mtb> %ZTest 80.0 3 c1; # subc> Alternative -1; # subc> Error 0.01. #Copy these lines to the command prompt (without the #): #%ZTest 80.0 3 c1; #Alternative -1; #Error 0.01. Mcolumn c1 Mconstant Mu0 Sigma Tails Alpha Zp Default Tails=0 Default Alpha=0.05 brief 1 ZTest Tails Sigma c1; #call MTB system macro ztest Alternative Tails. Let Zp=(Mean(c1)-Mu0)/Sigma*sqrt(count(c1)) Let Zp=round(Zp,2) If abs(Zp)<3.1 Call ztestplot Zp Alpha; #call PGM plotting macro Alternative Tails. Else NOTE Your p value is out of range EndIf brief endmacro ###################################################### macro ztestplot zp alpha; Alternative tails. #-1/0/+1 for left/two tailed/right #PGMathews 12/4/98 Rev. 1.0 for Minitab V13.2 #440-350-0911 pmathews@apk.net #Creates a graph of a normal curve, with tails shaded. #Shades tail area(s) corresponding to p. Places tick(s) #corresponding to alpha. #Default hypothesis is two tails (Ha: mu.ne.mu0). #Use tails=-1 for one tailed left test (Ha: mumu0). #Example call: # mtb> %ztestplot -2.34 0.05; # subc> Alternative -1. mcolumns z pdf group mconstant p zp alpha zalpha tails mconstant lzalpha rzalpha halfalph mconstant shade notshade mconstant LARLim RARLim default tails=0 brief 0 set z #assigns the z values for plot -3.2:3.2/0.01. end pdf z pdf #the corresponding probabilities ############################################################## If tails = -1 #Ha: mumu0 let shade=round((3.2-zp)/0.01) let notshade=641-shade set group notshade(1) shade(0) end cdf zp p let p=round(1-p,3) invcdf alpha zalpha let zalpha=round(-zalpha,2) let RARLim=zalpha+0.3 let LARLim=zalpha-1.2 Layout Plot pdf*z; Area group; #the shaded regions Type 1 1; Color 14 0; EType 0 0; Base 0 0; NoLegend; NoFrame 1. Plot pdf * z; #the curve and lines Connect; Tick 1 0 zp zalpha; #for x (1) axis TSize 0.8; Angle 90; Offset -0.007 -0.05; Tick 2 0; #for y (2) axis Line -3.2 0 3.2 0; #the baseline Line 0 0 0 0.4; #the origin Line zalpha 0 zalpha 0.4; #the A/R limit Text RARLim 0.3 "Reject Ho"; Text LARLim 0.3 "Accept Ho"; #Footnote "alpha= , zalpha= "; #Footnote "p= , zp= "; Footnote "Mathews and Malnar, September 2000"; Size 0.7; Nolegend. EndLayout. ########################################################### Else #Ha: mu.ne.mu0 let shade=round((3.2-abs(zp))/0.01) let notshade=641-2*shade set group #settings for fill groups shade(0) notshade(1) shade(0) end cdf zp p let p=round(p,3) #format for plot let halfalph=alpha/2 #let's just do one side invcdf halfalph lzalpha #the z value let rzalpha=-lzalpha #the right side let lzalpha=round(lzalpha,2) #formatted for plot let rzalpha=round(rzalpha,2) let RARLim=rzalpha+0.3 #plotting positions let LARLim=lzalpha-1.2 #for labels Layout Plot pdf*z; #for the fill regions Area group; #the shaded regions Type 1 1; #solid fill Color 14 0; #gray tails EType 0 0; Base 0 0; #lower limit for fill NoLegend; NoFrame 1. Plot pdf * z; #the curve and lines Connect; Tick 1 0 zp lzalpha -rzalpha; #for x (1) axis TSize 0.8; #small ones Angle 90; #rotated for room Offset -0.007 -0.05; #to line up the characters Tick 2 0; #for y (2) axis Line -3.2 0 3.2 0; #the baseline Line 0 0 0 0.4; #the origin Line lzalpha 0 lzalpha 0.4; #the left A/R limit Line rzalpha 0 rzalpha 0.4; #the right A/R limit Text LARLim 0.3 "Reject Ho"; #the labels Text RARLim 0.3 "Reject Ho"; Text -0.5 0.3 "Accept Ho"; #Footnote "alpha= , zalpha= "; #Footnote "p= , zp= "; Footnote "Mathews and Malnar, September 2000"; Size 0.7; Nolegend. EndLayout. Endif ############################################################ brief endmacro