/************* castle1.sas ********************* Two-way ANOVA SAS example with dummy var coding: See Section 19.4; data on P. 818 ***************************************************/ options linesize = 79; proc format; /* value labels used in data step below */ value htfmt 1 = 'Bottom' 2 = 'Middle' 3 = 'Top'; value widfmt 1 = 'Regular' 2 = 'Wide'; data bake; infile 'castle.dat'; input height width sales; label height = 'Display Height' width = 'Display Width' sales = 'Sales in cases'; format height htfmt.; format width widfmt.; /* Asssociate variables with print formats */ /* Effect dummy variable coding */ if width = 1 then w1 = 1; else w1 = -1; if height = 1 then h1 = 1; else if height = 3 then h1 = -1; else h1 = 0; if height = 2 then h2 = 1; else if height = 3 then h2 = -1; else h2 = 0; h1w1 = h1*w1 ; h2w1 = h2*w1; /* Interactions */ /* Cell means coding: indicators are named after their parameters. */ if height = 1 and width = 1 then mu11 = 1 ; else mu11 = 0; if height = 1 and width = 2 then mu12 = 1 ; else mu12 = 0; if height = 2 and width = 1 then mu21 = 1 ; else mu21 = 0; if height = 2 and width = 2 then mu22 = 1 ; else mu22 = 0; if height = 3 and width = 1 then mu31 = 1 ; else mu31 = 0; if height = 3 and width = 2 then mu32 = 1 ; else mu32 = 0; /* Make combination variable */ hwcombo = 10*height + width; proc freq; tables height * width / nopercent norow nocol; tables hwcombo * (height width) / nopercent norow nocol; proc glm; /* glm does the dummy vars for us */ class height width; model sales = height width height*width; means height width height*width; means height / alpha=.05 tukey bon scheffe cldiff; /* Why didn't I bother to do it for shelf width? */ proc reg; /* Now do it with dummy var regression using effect coding */ model sales = h1 h2 w1 h1w1 h2w1; height: test h1=h2=0; width: test w1 = 0; h_by_w: test h1w1 = h2w1 = 0; proc reg; /* Now with cell means coding */ model sales = mu11 -- mu32 / noint ; height: test mu11+mu12=mu21+mu22=mu31+mu32; width: test mu11+mu21+mu31=mu12+mu22+mu32; h_by_w: test mu11-mu12 = mu21-mu22 = mu31-mu32; proc glm; /* Combination variables are good for comparing cell means */ class hwcombo; model sales=hwcombo; means hwcombo / tukey; /* Could have used cldiff option */