Two-Way ANOVA Model #2

Soybean Example

Program Listing

PROC FORMAT;
 VALUE den 1='regular' 2='thick';
 VALUE fert 1='low' 2='medium' 3='high';
RUN;

DATA soybean(DROP=rep);
 FORMAT  density den.  fertilizer fert.;
 DO fertilizer = 1 TO 3;
   DO density = 1 TO 2;
     combo = (density-1)*3 + fertilizer;
     DO rep = 1 TO 4;
       INPUT yield @@;
       OUTPUT;
      END;
    END;
  END;
DATALINES;
37.5 36.5 38.6 36.5 37.4 35.0 38.1 36.5
48.1 48.3 48.6 46.4 36.7 36.4 39.3 37.5
48.5 46.1 49.1 48.2 45.7 45.7 48.0 46.4
;

OPTIONS LS=76 NODATE NONUMBER NOCENTER;

TITLE1 'Two-Way ANOVA Model 2';
TITLE2 'Soybean Example';
TITLE3 'Test for Homogeneous Variance';
TITLE4 'and Equal Cell Means';
PROC GLM DATA=soybean;
  CLASS combo;
  MODEL yield = combo;
  MEANS combo/HOVTEST=BF;
QUIT;

TITLE3 'Tests for Interaction & Main Effects';
PROC GLM DATA=soybean ORDER=INTERNAL;
  CLASS density fertilizer;
  MODEL yield = density | fertilizer;
  RUN;
  ** Seeing significant interaction effect,
     do simple effects analyses;
  /* H0: μ1121 */
  /* H0: μ1222 */
  /* H0: μ1323 */
  TITLE3 'Simple Effects of density within fertilizer';
  LSMEANS density*fertilizer/SLICE=fertilizer;
  RUN;
  /* H0: μ111213 */
  /* H0: μ212223 */
  TITLE3 'Simple Effects of fertilizer within density';
  LSMEANS density*fertilizer/SLICE=density;
  RUN;
  /* To get the pairwise comparison of the simple effects
     of fertilizer within each level of density, do the
     following (explained following immediately the output listing) */
  TITLE4 'Density = regular';
  ESTIMATE 'mu[11]-mu[12]' fertilizer 1 -1
	   density*fertilizer 1 -1;
  ESTIMATE 'mu[11]-mu[13]' fertilizer 1 0 -1
	   density*fertilizer 1 0 -1;
  ESTIMATE 'mu[12]-mu[13]' fertilizer 0 1 -1
	   density*fertilizer 0 1 -1;
  RUN;
  TITLE4 'Density = thick';
  ESTIMATE 'mu[21]-mu[22]' fertilizer 1 -1
	   density*fertilizer 0 0 0 1 -1;
  ESTIMATE 'mu[21]-mu[23]' fertilizer 1 0 -1
	   density*fertilizer 0 0 0 1 0 -1;
  ESTIMATE 'mu[22]-mu[23]' fertilizer 0 1 -1
	   density*fertilizer 0 0 0 0 1 -1;
  RUN;
QUIT;

Output Listing

Two-Way ANOVA Model 2
Soybean Example
Test for Homogeneous Variance
and Equal Cell Means

The GLM Procedure
 
Dependent Variable: yield   
                            Sum of
Source            DF       Squares   Mean Square  F Value  Pr > F
Model              5   638.2570833   127.6514167    91.79  <.0001
Error             18    25.0325000     1.3906944                 
Corrected Total   23   663.2895833                               


R-Square     Coeff Var      Root MSE    yield Mean
0.962260      2.788164      1.179277      42.29583


Source        DF     Type I SS   Mean Square  F Value  Pr > F
combo          5   638.2570833   127.6514167    91.79  <.0001


Source        DF   Type III SS   Mean Square  F Value  Pr > F
combo          5   638.2570833   127.6514167    91.79  <.0001


 Brown and Forsythe's Test for Homogeneity of yield Variance
       ANOVA of Absolute Deviations from Group Medians
 
                      Sum of        Mean
Source        DF     Squares      Square    F Value    Pr > F
combo          5      0.3938      0.0788       0.12    0.9854
Error         18     11.5125      0.6396                     


Level of           ------------yield------------
combo        N             Mean          Std Dev
1            4       37.2750000       1.00124922
2            4       47.8500000       0.98826447
3            4       47.9750000       1.30479884
4            4       36.7500000       1.33790882
5            4       37.4750000       1.30224166
6            4       46.4500000       1.08474267



Two-Way ANOVA Model 2
Soybean Example
Tests for Interaction & Main Effects

The GLM Procedure

Dependent Variable: yield   
                            Sum of
Source            DF       Squares   Mean Square  F Value  Pr > F
Model              5   638.2570833   127.6514167    91.79  <.0001
Error             18    25.0325000     1.3906944                 
Corrected Total   23   663.2895833                               


R-Square     Coeff Var      Root MSE    yield Mean
0.962260      2.788164      1.179277      42.29583


Source              DF     Type I SS   Mean Square  F Value  Pr > F
density              1   102.9204167   102.9204167    74.01  <.0001
fertilizer           2   417.7733333   208.8866667   150.20  <.0001
density*fertilizer   2   117.5633333    58.7816667    42.27  <.0001


Source              DF   Type III SS   Mean Square  F Value  Pr > F
density              1   102.9204167   102.9204167    74.01  <.0001
fertilizer           2   417.7733333   208.8866667   150.20  <.0001
density*fertilizer   2   117.5633333    58.7816667    42.27  <.0001



Two-Way ANOVA Model 2
Soybean Example
Simple Effects of density within fertilizer

The GLM Procedure
Least Squares Means

density    fertilizer    yield LSMEAN
regular    low             37.2750000
regular    medium          47.8500000
regular    high            47.9750000
thick      low             36.7500000
thick      medium          37.4750000
thick      high            46.4500000


        density*fertilizer Effect Sliced by fertilizer for yield
 
                        Sum of
fertilizer  DF         Squares     Mean Square    F Value    Pr > F
low          1        0.551250        0.551250       0.40    0.5369
medium       1      215.281250      215.281250     154.80    <.0001
high         1        4.651250        4.651250       3.34    0.0840



Two-Way ANOVA Model 2
Soybean Example
Simple Effects of fertilizer within density

The GLM Procedure
Least Squares Means

density    fertilizer    yield LSMEAN
regular    low             37.2750000
regular    medium          47.8500000
regular    high            47.9750000
thick      low             36.7500000
thick      medium          37.4750000
thick      high            46.4500000


        density*fertilizer Effect Sliced by density for yield
 
                     Sum of
density  DF         Squares     Mean Square    F Value    Pr > F
regular   2      301.781667      150.890833     108.50    <.0001
thick     2      233.555000      116.777500      83.97    <.0001



Two-Way ANOVA Model 2
Soybean Example
Simple Effects of fertilizer within density
Density = regular

The GLM Procedure
 
Dependent Variable: yield   
                                    Standard
Parameter           Estimate           Error    t Value    Pr > |t|
mu[11]-mu[12]    -10.5750000      0.83387482     -12.68      <.0001
mu[11]-mu[13]    -10.7000000      0.83387482     -12.83      <.0001
mu[12]-mu[13]     -0.1250000      0.83387482      -0.15      0.8825



Two-Way ANOVA Model 2
Soybean Example
Simple Effects of fertilizer within density
Density = thick

The GLM Procedure
 
Dependent Variable: yield   
                                    Standard
Parameter           Estimate           Error    t Value    Pr > |t|
mu[21]-mu[22]    -0.72500000      0.83387482      -0.87      0.3961
mu[21]-mu[23]    -9.70000000      0.83387482     -11.63      <.0001
mu[22]-mu[23]    -8.97500000      0.83387482     -10.76      <.0001

In most cases, SAS uses internal order of class variables or formatted order if user specifies format in PROC GLM. If you want SAS to show the formatted values while keeping the internal order, use ORDER=INTERNAL options in PROC GLM. So, in our program above, 1=regular and 2=thick for density; and 1=low, 2=medium, 3=high for fertilizer (since the user-defined formats ar permanently associated with the data). Imagine if you entered fertilizer as character variables without explicit format in the DATA step, then the order would have been high, low, and medium for the three levels and that can easily mess up our investigation of the simple effects if we did not pay attention. So that is why the data were constructed this way.

Now, the simple effects. As you can see from the comments in the program, SAS performs partial null hypothesis tests of simple effects (not pairwise comparisions). So the simple effects of density within fertilizer are each at single degree of freedom F test. This is comparable to t tests in the R example for simple effects of density (see Two-Way ANOVA Model 2 (addendum)). That is, just square the t values to get F values.

It leaves us only to get estimates and t values for simple fertilizer effects within density. The ESTIMATE comes to rescue!

To understand how SAS does this, note that SAS arrange the parameters in this order (in this example):

(μ,α121, β23, (αβ)11,(αβ)12,(αβ)13, (αβ)21,(αβ)22,(αβ)23).
Yes, SAS arrangement of array elements is row-major (rows by rows). So, for example, to get μ11−μ12:
=(μ+α11+(αβ)11) −  (μ+α12+(αβ)12) =β1−β2+(αβ)11−(αβ)12
So, to specify such contrast, do, in ESTIMATE statement (abbrev. below, A=density B=fertilizer)
B 1 −1 0    A*B 1 −1 0 0 0 0
SAS allows you to omit all trailing zeros, so you can do
B 1 −1    A*B 1 −1

Other contrasts can be specified in a similar fashion. The results are now comparable to Two-Way ANOVA Model 2 (addendum) now. However, note that the above results are for individual tests and confidence intervals. In R example, you also see simultaneous inferences.