SAS code for a Factorial ANOVA

Here are the same data again, together with the SAS datastep to input the data into a SAS data set named factor01. We then have 4 SAS PROC MIXED analyses, fitting the same fixed effects components (a, b and a*b), but with different combinations of variance components.


data factor01; input a b wt; cards; 1 1 104 2 2 103 1 2 91 1 3 94 1 3 92 2 2 104 1 1 104 1 3 93 2 3 92 2 1 101 2 2 104 2 3 89 2 1 105 1 1 107 1 2 93 1 2 99 2 1 102 2 2 98 2 3 91 1 3 86 2 1 101 1 2 97 1 1 106 2 3 86 ; proc mixed data=factor01; classes a b; model wt = a b a*b; /* model as per fixed effects GLM model, 1 common, homogeneous variance for all groups */ run; quit; proc mixed data=factor01; classes a b; model wt = a b a*b; repeated /group=a*b; /* different variance for each a*b subgroup */ run; quit; proc mixed data=factor01; classes a b; model wt = a b a*b; repeated /group=b; /* different variance for each level of factor b */ run; quit; proc mixed data=factor01; classes a b; model wt = a b a*b; repeated /group=a; /* different variance for eacch level of factor a */ run; quit;


Here is the output from the first PROC MIXED run, where we have fitted a model with the main effects factors a and b as well as the interaction a*b with one common residual error variance for all observations.

Factor A has 2 levels (with values 1 and 2). Factor B has 3 levels (with values 1, 2 and 3). The estimate of the (co)variance, the residual error variance is 7.889.

The SAS System


                              The MIXED Procedure

                            Class Level Information

                            Class     Levels  Values
                            A              2  1 2
                            B              3  1 2 3

                     Covariance Parameter Estimates (REML)

                     Cov Parm       Estimate
                     Residual     7.88888889

                        Model Fitting Information for WT

                    Description                        Value
                    Observations                     24.0000
                    Res Log Likelihood              -48.2889
                    Akaike's Information Criterion  -49.2889
                    Schwarz's Bayesian Criterion    -49.7341
                    -2 Res Log Likelihood            96.5777

                            Tests of Fixed Effects

                   Source      NDF   DDF  Type III F  Pr > F
                   A             1    18        0.53  0.4767
                   B             2    18       46.18  0.0001
                   A*B           2    18        7.93  0.0034

The SAS System


                              The MIXED Procedure

                            Class Level Information

                            Class     Levels  Values
                            A              2  1 2
                            B              3  1 2 3

                       REML Estimation Iteration History

               Iteration  Evaluations     Objective     Criterion
                       0            1   63.49596156
                       1            1   60.19416416    0.00000000

                           Convergence criteria met.

                     Covariance Parameter Estimates (REML)

                     Cov Parm  Group        Estimate
                     DIAG      A*B 1 1    2.25000000
                     DIAG      A*B 1 2   13.33333333
                     DIAG      A*B 1 3   12.91666667
                     DIAG      A*B 2 1    3.58333333
                     DIAG      A*B 2 2    8.25000000
                     DIAG      A*B 2 3    7.00000000

                        Model Fitting Information for WT

                    Description                        Value
                    Observations                     24.0000
                    Res Log Likelihood              -46.6380
                    Akaike's Information Criterion  -52.6380
                    Schwarz's Bayesian Criterion    -55.3091
                    -2 Res Log Likelihood            93.2760
                    Null Model LRT Chi-Square         3.3018
                    Null Model LRT DF                 5.0000
                    Null Model LRT P-Value            0.6536

                            Tests of Fixed Effects

                   Source      NDF   DDF  Type III F  Pr > F
                   A             1    18        0.53  0.4767
                   B             2    18       56.92  0.0001

The SAS System


                            Tests of Fixed Effects

                   Source      NDF   DDF  Type III F  Pr > F
                   A*B           2    18        7.73  0.0038

The SAS System


                              The MIXED Procedure

                            Class Level Information

                            Class     Levels  Values
                            A              2  1 2
                            B              3  1 2 3

                       REML Estimation Iteration History

               Iteration  Evaluations     Objective     Criterion
                       0            1   63.49596156
                       1            1   60.80351835    0.00000000

                           Convergence criteria met.

                     Covariance Parameter Estimates (REML)

                     Cov Parm  Group      Estimate
                     DIAG      B 1      2.91666667
                     DIAG      B 2     10.79166667
                     DIAG      B 3      9.95833333

                        Model Fitting Information for WT

                    Description                        Value
                    Observations                     24.0000
                    Res Log Likelihood              -46.9427
                    Akaike's Information Criterion  -49.9427
                    Schwarz's Bayesian Criterion    -51.2782
                    -2 Res Log Likelihood            93.8853
                    Null Model LRT Chi-Square         2.6924
                    Null Model LRT DF                 2.0000
                    Null Model LRT P-Value            0.2602

                            Tests of Fixed Effects

                   Source      NDF   DDF  Type III F  Pr > F
                   A             1    18        0.53  0.4767
                   B             2    18       56.92  0.0001
                   A*B           2    18        7.73  0.0038

The SAS System


                              The MIXED Procedure

                            Class Level Information

                            Class     Levels  Values
                            A              2  1 2
                            B              3  1 2 3

                       REML Estimation Iteration History

               Iteration  Evaluations     Objective     Criterion
                       0            1   63.49596156
                       1            1   63.11253690    0.00000000

                           Convergence criteria met.

                     Covariance Parameter Estimates (REML)

                     Cov Parm  Group      Estimate
                     DIAG      A 1      9.50000000
                     DIAG      A 2      6.27777778

                        Model Fitting Information for WT

                    Description                        Value
                    Observations                     24.0000
                    Res Log Likelihood              -48.0972
                    Akaike's Information Criterion  -50.0972
                    Schwarz's Bayesian Criterion    -50.9875
                    -2 Res Log Likelihood            96.1943
                    Null Model LRT Chi-Square         0.3834
                    Null Model LRT DF                 1.0000
                    Null Model LRT P-Value            0.5358

                            Tests of Fixed Effects

                   Source      NDF   DDF  Type III F  Pr > F
                   A             1    18        0.53  0.4767
                   B             2    18       46.18  0.0001
                   A*B           2    18        7.93  0.0034