/* SAS Example of the Regression Approach to the ANOVA model */ /* We will analyze the Kenton Foods data from the example in class */ /* The response variable is sales and the factor is package design. */ /* The store label is also given in the data set. */ /*** With the Factor-Effects Model ***/ DATA kenton; INPUT SALES DESIGN STORE; /* Defining r-1 = 3 indicator variables: */ IF DESIGN = 1 then X1 = 1; ELSE IF DESIGN = 4 then X1 = -1; /* because r=4 here */ ELSE X1 = 0; IF DESIGN = 2 then X2 = 1; ELSE IF DESIGN = 4 then X2 = -1; /* because r=4 here */ ELSE X2 = 0; IF DESIGN = 3 then X3 = 1; ELSE IF DESIGN = 4 then X3 = -1; /* because r=4 here */ ELSE X3 = 0; cards; 11 1 1 17 1 2 16 1 3 14 1 4 15 1 5 12 2 1 10 2 2 15 2 3 19 2 4 11 2 5 23 3 1 20 3 2 18 3 3 17 3 4 27 4 1 33 4 2 22 4 3 26 4 4 28 4 5 ; run; /* Fitting this ANOVA model via a regression approach with PROC REG: */ PROC REG DATA = kenton; MODEL SALES = X1 X2 X3; run; /* Note the estimates for the regression parameters are: */ /* 18.675 (estimate of mu_dot), -4.075 (estimate of tau_1) */ /* -5.275 (estimate of tau_2), 0.825 (estimate of tau_3) */ /* Estimate of tau_4 is thus -(-4.075)-(-5.275)-0.825. */ /* Estimates of the Factor Level Means: */ /* For Design 1: 18.675 - 4.075 = 14.6. */ /* For Design 2: 18.675 - 5.275 = 13.4. */ /* For Design 3: 18.675 + 0.825 = 19.5. */ /* For Design 4: 18.675-(-4.075)-(-5.275)-0.825 = 27.2. */ /* Verify that these are the same estimates we obtained */ /* with the other approach. */ /*** With the Cell-Means Model ***/ DATA kenton; INPUT SALES DESIGN STORE; /* Defining r = 4 indicator variables: */ IF DESIGN = 1 then X1 = 1; ELSE X1 = 0; IF DESIGN = 2 then X2 = 1; ELSE X2 = 0; IF DESIGN = 3 then X3 = 1; ELSE X3 = 0; IF DESIGN = 4 then X4 = 1; ELSE X4 = 0; cards; 11 1 1 17 1 2 16 1 3 14 1 4 15 1 5 12 2 1 10 2 2 15 2 3 19 2 4 11 2 5 23 3 1 20 3 2 18 3 3 17 3 4 27 4 1 33 4 2 22 4 3 26 4 4 28 4 5 ; run; /* Fitting this ANOVA model via a regression approach with PROC REG: */ /* We must specify a no-intercept fit with the NOINT option. */ PROC REG DATA = kenton; MODEL SALES = X1 X2 X3 X4 / NOINT; run; /* Note the estimates for the regression parameters are: */ /* 14.6 (estimate of mu_1), 13.4 (estimate of mu_2), */ /* 19.5 (estimate of mu_3), 27.2 (estimate of mu_4). */ /* These are exactly the estimates of the factor level means. */