The GLM Procedure

Example 47.5 Three-Way Analysis of Variance with Contrasts

(View the complete code for this example.)

This example uses data from Cochran and Cox (1957, p. 176) to illustrate the analysis of a three-way factorial design with replication, including the use of the CONTRAST statement with interactions, the OUTSTAT= data set, and the SLICE= option in the LSMEANS statement.

The object of the study is to determine the effects of electric current on denervated muscle. The variables are as follows:

Rep

the replicate number, 1 or 2

Time

the length of time the current is applied to the muscle, ranging from 1 to 4

Current

the level of electric current applied, ranging from 1 to 4

Number

the number of treatments per day, ranging from 1 to 3

MuscleWeight

the weight of the denervated muscle

The following statements produce Output 47.5.1 through Output 47.5.4.

data muscles;
   do Rep=1 to 2;
      do Time=1 to 4;
         do Current=1 to 4;
            do Number=1 to 3;
               input MuscleWeight @@;
               output;
            end;
         end;
      end;
   end;
   datalines;
72 74 69 61 61 65 62 65 70 85 76 61
67 52 62 60 55 59 64 65 64 67 72 60
57 66 72 72 43 43 63 66 72 56 75 92
57 56 78 60 63 58 61 79 68 73 86 71
46 74 58 60 64 52 71 64 71 53 65 66
44 58 54 57 55 51 62 61 79 60 78 82
53 50 61 56 57 56 56 56 71 56 58 69
46 55 64 56 55 57 64 66 62 59 58 88
;
proc glm outstat=summary;
   class Rep Current Time Number;
   model MuscleWeight = Rep Current|Time|Number;
   contrast 'Time in Current 3'
      Time 1 0 0 -1 Current*Time 0 0 0 0 0 0 0 0 1 0 0 -1,
      Time 0 1 0 -1 Current*Time 0 0 0 0 0 0 0 0 0 1 0 -1,
      Time 0 0 1 -1 Current*Time 0 0 0 0 0 0 0 0 0 0 1 -1;
   contrast 'Current 1 versus 2' Current 1 -1;
   lsmeans Current*Time / slice=Current;
run;
proc print data=summary;
run;

The first CONTRAST statement examines the effects of Time within level 3 of Current. This is also called the simple effect of Time within Current*Time. Note that, since there are three degrees of freedom, it is necessary to specify three rows in the CONTRAST statement, separated by commas. Since the parameterization that PROC GLM uses is determined in part by the ordering of the variables in the CLASS statement, Current is specified before Time so that the Time parameters are nested within the Current*Time parameters; thus, the Current*Time contrast coefficients in each row are simply the Time coefficients of that row within the appropriate level of Current.

The second CONTRAST statement isolates a single-degree-of-freedom effect corresponding to the difference between the first two levels of Current. You can use such a contrast in a large experiment where certain preplanned comparisons are important, but you want to take advantage of the additional error degrees of freedom available when all levels of the factors are considered.

The LSMEANS statement with the SLICE= option is an alternative way to test for the simple effect of Time within Current*Time. In addition to listing the LS-means for each current strength and length of time, it gives a table of F tests for differences between the LS-means across Time within each Current level. In some cases, this can be a way to disentangle a complex interaction.

Output 47.5.1: Overall Analysis

The GLM Procedure

Class Level Information
ClassLevelsValues
Rep21 2
Current41 2 3 4
Time41 2 3 4
Number31 2 3

Number of Observations Read96
Number of Observations Used96

The GLM Procedure
 
Dependent Variable: MuscleWeight

SourceDFSum of SquaresMean SquareF ValuePr > F
Model485782.916667120.4774311.770.0261
Error473199.48958368.074246  
Corrected Total958982.406250   

R-SquareCoeff VarRoot MSEMuscleWeight Mean
0.64380513.051058.25071263.21875


The output, shown in Output 47.5.2 and Output 47.5.3, indicates that the main effects for Rep, Current, and Number are significant (with p-values of 0.0045, <0.0001, and 0.0461, respectively), but the main effect for Time is not significant, indicating that, in general, it does not matter how long the current is applied. None of the interaction terms are significant, nor are the contrasts significant. Notice that the row in the sliced ANOVA table corresponding to level 3 of current matches the "Time in Current 3" contrast.

Output 47.5.2: Individual Effects and Contrasts

SourceDFType I SSMean SquareF ValuePr > F
Rep1605.010417605.0104178.890.0045
Current32145.447917715.14930610.51<.0001
Time3223.11458374.3715281.090.3616
Current*Time9298.67708333.1863430.490.8756
Number2447.437500223.7187503.290.0461
Current*Number6644.395833107.3993061.580.1747
Time*Number6367.97916761.3298610.900.5023
Current*Time*Number181050.85416758.3807870.860.6276

SourceDFType III SSMean SquareF ValuePr > F
Rep1605.010417605.0104178.890.0045
Current32145.447917715.14930610.51<.0001
Time3223.11458374.3715281.090.3616
Current*Time9298.67708333.1863430.490.8756
Number2447.437500223.7187503.290.0461
Current*Number6644.395833107.3993061.580.1747
Time*Number6367.97916761.3298610.900.5023
Current*Time*Number181050.85416758.3807870.860.6276

ContrastDFContrast SSMean SquareF ValuePr > F
Time in Current 3334.8333333311.611111110.170.9157
Current 1 versus 2199.1875000099.187500001.460.2334


Output 47.5.3: Simple Effects of Time

The GLM Procedure
Least Squares Means

Current*Time Effect Sliced by Current for MuscleWeight
CurrentDFSum of SquaresMean SquareF ValuePr > F
13271.45833390.4861111.330.2761
23120.66666740.2222220.590.6241
3334.83333311.6111110.170.9157
4394.83333331.6111110.460.7085


The SS, F statistics, and p-values can be stored in an OUTSTAT= data set, as shown in Output 47.5.4.

Output 47.5.4: Contents of the OUTSTAT= Data Set

Obs_NAME__SOURCE__TYPE_DFSSFPROB
1MuscleWeightERRORERROR473199.49..
2MuscleWeightRepSS11605.018.88750.00454
3MuscleWeightCurrentSS132145.4510.50540.00002
4MuscleWeightTimeSS13223.111.09250.36159
5MuscleWeightCurrent*TimeSS19298.680.48750.87562
6MuscleWeightNumberSS12447.443.28640.04614
7MuscleWeightCurrent*NumberSS16644.401.57770.17468
8MuscleWeightTime*NumberSS16367.980.90090.50231
9MuscleWeightCurrent*Time*NumberSS1181050.850.85760.62757
10MuscleWeightRepSS31605.018.88750.00454
11MuscleWeightCurrentSS332145.4510.50540.00002
12MuscleWeightTimeSS33223.111.09250.36159
13MuscleWeightCurrent*TimeSS39298.680.48750.87562
14MuscleWeightNumberSS32447.443.28640.04614
15MuscleWeightCurrent*NumberSS36644.401.57770.17468
16MuscleWeightTime*NumberSS36367.980.90090.50231
17MuscleWeightCurrent*Time*NumberSS3181050.850.85760.62757
18MuscleWeightTime in Current 3CONTRAST334.830.17060.91574
19MuscleWeightCurrent 1 versus 2CONTRAST199.191.45700.23344