STA429/1007 F 2004 Handout 6: The Potato Data

Custom tests and contrasts in factorial ANOVA



/* potato.sas */
options linesize=79 noovp formdlim='_';
title 'Rotten potatos: STA429/1007 F 2004';
title2 'Custom tests with proc reg and proc glm';

data spud;
     infile 'potato2.dat' firstobs=2; /* Skip the first line that R uses */
     input id bact temp rot;
     if temp=1 and bact=1 then mu11=1; else mu11=0;
     if temp=1 and bact=2 then mu12=1; else mu12=0;
     if temp=1 and bact=3 then mu13=1; else mu13=0;
     if temp=2 and bact=1 then mu21=1; else mu21=0;
     if temp=2 and bact=2 then mu22=1; else mu22=0;
     if temp=2 and bact=3 then mu23=1; else mu23=0;
     combo = 10*temp+bact;

proc means;
     class bact temp;
     var rot;
/* Better looking output from proc tabulate */

proc tabulate;
     class bact temp;
     var rot;
     table (temp all),(bact all) * (mean*rot);

proc glm;
     title3 'Standard 2-way ANOVA with proc glm';
     class bact temp;
     model rot=temp|bact;
     means temp*bact;

/* Now generate the tests for main effects and interaction, and also 2 tests
   for bacteria type, once just for low temp and once just for high. Do this
   first with test statements in proc reg, and then with contrasts in proc glm.

               BACTERIA TYPE
TEMP      1         2        3
  1     mu11      mu12      mu13
  2     mu21      mu22      mu23
*/

proc reg;
     title3 'Using the proc reg test statement';
     model rot = mu11--mu23 / noint;
     overall: test mu11=mu12=mu13=mu21=mu22=mu23;
     temper:  test mu11+mu12+mu13=mu21+mu22+mu23;
     bacter:  test mu11+mu21=mu12+mu22,
                   mu12+mu22=mu13+mu23;
     B_by_T:  test mu11-mu21=mu12-mu22=mu13-mu23;
     BjustLO: test mu11=mu12=mu13;
     BjustHI: test mu21=mu22=mu23;

/* Definition: A contrast is a linear combination whose coefficients
               add to zero. We can test whether collections of contrasts
               of cell means are all to equal zero.*/
proc glm;
     title3 'Test contrasts with proc glm';
     class combo;
     model rot=combo;
     contrast 'Main Effect for Temerature'
        combo  1  1  1  -1 -1 -1;
     contrast 'Main Effect for Bacteria'
        combo  1 -1  0   1 -1  0,
        combo  0  1 -1   0  1 -1;
     contrast 'Temperature by Bacteria Interaction'
        combo  1 -1  0  -1  1  0,
        combo  0  1 -1   0 -1  1;
     contrast 'Bacteria Just for Low Temp'
        combo  1 -1  0   0  0  0,
        combo  0  1 -1   0  0  0;
     contrast 'Bacteria Just for High Temp'
        combo  0  0  0   1 -1  0,
        combo  0  0  0   0  1 -1;

Here is potato.lst


_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      1
                    Custom tests with proc reg and proc glm
                                               15:11 Saturday, October 16, 2004

                              The MEANS Procedure

                            Analysis Variable : rot

                               N
         bact          temp  Obs   N          Mean       Std Dev       Minimum
 -----------------------------------------------------------------------------
            1             1    9   9     3.5555556     4.2752518             0

                          2    9   9     7.0000000     3.5355339             0

            2             1    9   9     4.7777778     3.1135903             0

                          2    9   9    13.5555556     6.3267510     3.0000000

            3             1    9   9     8.0000000     4.5552168     2.0000000

                          2    9   9    19.5555556     5.5251948     8.0000000
 -----------------------------------------------------------------------------

                            Analysis Variable : rot

                                               N
                         bact          temp  Obs       Maximum
                 ---------------------------------------------
                            1             1    9     9.0000000

                                          2    9    10.0000000

                            2             1    9    10.0000000

                                          2    9    23.0000000

                            3             1    9    15.0000000

                                          2    9    26.0000000
                 ---------------------------------------------

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      2
                    Custom tests with proc reg and proc glm
                                               15:11 Saturday, October 16, 2004

    -----------------------------------------------------------------------
    |                 |                 bact                 |            |
    |                 |--------------------------------------|            |
    |                 |     1      |     2      |     3      |    All     |
    |                 |------------+------------+------------+------------|
    |                 |    Mean    |    Mean    |    Mean    |    Mean    |
    |                 |------------+------------+------------+------------|
    |                 |    rot     |    rot     |    rot     |    rot     |
    |-----------------+------------+------------+------------+------------|
    |temp             |            |            |            |            |
    |-----------------|            |            |            |            |
    |1                |        3.56|        4.78|        8.00|        5.44|
    |-----------------+------------+------------+------------+------------|
    |2                |        7.00|       13.56|       19.56|       13.37|
    |-----------------+------------+------------+------------+------------|
    |All              |        5.28|        9.17|       13.78|        9.41|
    -----------------------------------------------------------------------

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      3
                    Custom tests with proc reg and proc glm
                      Standard 2-way ANOVA with proc glm
                                               15:11 Saturday, October 16, 2004

                               The GLM Procedure

                           Class Level Information

                        Class         Levels    Values

                        bact               3    1 2 3

                        temp               2    1 2


                         Number of observations    54

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      4
                    Custom tests with proc reg and proc glm
                      Standard 2-way ANOVA with proc glm
                                               15:11 Saturday, October 16, 2004

                               The GLM Procedure

Dependent Variable: rot

                                      Sum of
Source                     DF        Squares    Mean Square   F Value   Pr > F

Model                       5    1652.814815     330.562963     15.05   <.0001

Error                      48    1054.222222      21.962963

Corrected Total            53    2707.037037


              R-Square     Coeff Var      Root MSE      rot Mean

              0.610562      49.81676      4.686466      9.407407


Source                     DF      Type I SS    Mean Square   F Value   Pr > F

temp                        1    848.0740741    848.0740741     38.61   <.0001
bact                        2    651.8148148    325.9074074     14.84   <.0001
bact*temp                   2    152.9259259     76.4629630      3.48   0.0387


Source                     DF    Type III SS    Mean Square   F Value   Pr > F

temp                        1    848.0740741    848.0740741     38.61   <.0001
bact                        2    651.8148148    325.9074074     14.84   <.0001
bact*temp                   2    152.9259259     76.4629630      3.48   0.0387

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      5
                    Custom tests with proc reg and proc glm
                      Standard 2-way ANOVA with proc glm
                                               15:11 Saturday, October 16, 2004

                               The GLM Procedure

         Level of     Level of           -------------rot-------------
         bact         temp         N             Mean          Std Dev

         1            1            9        3.5555556       4.27525178
         1            2            9        7.0000000       3.53553391
         2            1            9        4.7777778       3.11359028
         2            2            9       13.5555556       6.32675097
         3            1            9        8.0000000       4.55521679
         3            2            9       19.5555556       5.52519482

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      6
                    Custom tests with proc reg and proc glm
                       Using the proc reg test statement
                                               15:11 Saturday, October 16, 2004

                               The REG Procedure
                                 Model: MODEL1
                           Dependent Variable: rot

              NOTE: No intercept in model. R-Square is redefined.

                             Analysis of Variance

                                    Sum of           Mean
Source                   DF        Squares         Square    F Value    Pr > F

Model                     6     6431.77778     1071.96296      48.81    <.0001
Error                    48     1054.22222       21.96296
Uncorrected Total        54     7486.00000


             Root MSE              4.68647    R-Square     0.8592
             Dependent Mean        9.40741    Adj R-Sq     0.8416
             Coeff Var            49.81676


                             Parameter Estimates

                          Parameter       Standard
     Variable     DF       Estimate          Error    t Value    Pr > |t|

     mu11          1        3.55556        1.56216       2.28      0.0273
     mu12          1        4.77778        1.56216       3.06      0.0036
     mu13          1        8.00000        1.56216       5.12      <.0001
     mu21          1        7.00000        1.56216       4.48      <.0001
     mu22          1       13.55556        1.56216       8.68      <.0001
     mu23          1       19.55556        1.56216      12.52      <.0001

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      7
                    Custom tests with proc reg and proc glm
                       Using the proc reg test statement
                                               15:11 Saturday, October 16, 2004

                               The REG Procedure
                                 Model: MODEL1

                Test overall Results for Dependent Variable rot

                                           Mean
           Source             DF         Square    F Value    Pr > F

           Numerator           5      330.56296      15.05    <.0001
           Denominator        48       21.96296

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      8
                    Custom tests with proc reg and proc glm
                       Using the proc reg test statement
                                               15:11 Saturday, October 16, 2004

                               The REG Procedure
                                 Model: MODEL1

                Test temper Results for Dependent Variable rot

                                           Mean
           Source             DF         Square    F Value    Pr > F

           Numerator           1      848.07407      38.61    <.0001
           Denominator        48       21.96296

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                      9
                    Custom tests with proc reg and proc glm
                       Using the proc reg test statement
                                               15:11 Saturday, October 16, 2004

                               The REG Procedure
                                 Model: MODEL1

                Test bacter Results for Dependent Variable rot

                                           Mean
           Source             DF         Square    F Value    Pr > F

           Numerator           2      325.90741      14.84    <.0001
           Denominator        48       21.96296

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                     10
                    Custom tests with proc reg and proc glm
                       Using the proc reg test statement
                                               15:11 Saturday, October 16, 2004

                               The REG Procedure
                                 Model: MODEL1

                Test B_by_T Results for Dependent Variable rot

                                           Mean
           Source             DF         Square    F Value    Pr > F

           Numerator           2       76.46296       3.48    0.0387
           Denominator        48       21.96296

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                     11
                    Custom tests with proc reg and proc glm
                       Using the proc reg test statement
                                               15:11 Saturday, October 16, 2004

                               The REG Procedure
                                 Model: MODEL1

                Test BjustLO Results for Dependent Variable rot

                                           Mean
           Source             DF         Square    F Value    Pr > F

           Numerator           2       47.44444       2.16    0.1264
           Denominator        48       21.96296

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                     12
                    Custom tests with proc reg and proc glm
                       Using the proc reg test statement
                                               15:11 Saturday, October 16, 2004

                               The REG Procedure
                                 Model: MODEL1

                Test BjustHI Results for Dependent Variable rot

                                           Mean
           Source             DF         Square    F Value    Pr > F

           Numerator           2      354.92593      16.16    <.0001
           Denominator        48       21.96296

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                     13
                    Custom tests with proc reg and proc glm
                         Test contrasts with proc glm
                                               15:11 Saturday, October 16, 2004

                               The GLM Procedure

                           Class Level Information

                  Class         Levels    Values

                  combo              6    11 12 13 21 22 23


                         Number of observations    54

_______________________________________________________________________________

                      Rotten potatos: STA429/1007 F 2004                     14
                    Custom tests with proc reg and proc glm
                         Test contrasts with proc glm
                                               15:11 Saturday, October 16, 2004

                               The GLM Procedure

Dependent Variable: rot

                                      Sum of
Source                     DF        Squares    Mean Square   F Value   Pr > F

Model                       5    1652.814815     330.562963     15.05   <.0001

Error                      48    1054.222222      21.962963

Corrected Total            53    2707.037037


              R-Square     Coeff Var      Root MSE      rot Mean

              0.610562      49.81676      4.686466      9.407407


Source                     DF      Type I SS    Mean Square   F Value   Pr > F

combo                       5    1652.814815     330.562963     15.05   <.0001


Source                     DF    Type III SS    Mean Square   F Value   Pr > F

combo                       5    1652.814815     330.562963     15.05   <.0001


 Contrast                                   DF     Contrast SS     Mean Square

 Main Effect for Temerature                  1     848.0740741     848.0740741
 Main Effect for Bacteria                    2     651.8148148     325.9074074
 Temperature by Bacteria Interaction         2     152.9259259      76.4629630
 Bacteria Just for Low Temp                  2      94.8888889      47.4444444
 Bacteria Just for High Temp                 2     709.8518519     354.9259259

           Contrast                               F Value    Pr > F

           Main Effect for Temerature               38.61    <.0001
           Main Effect for Bacteria                 14.84    <.0001
           Temperature by Bacteria Interaction       3.48    0.0387
           Bacteria Just for Low Temp                2.16    0.1264
           Bacteria Just for High Temp              16.16    <.0001