UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Textbook Examples
Experimental Design by Kirk
Chapter 7: Randomized Block Designs

This page shows how to obtain the results from Kirk Chapter 7 using SAS.
Use data file rb4 (page 167).
data rb4;
input  y  a  s;
datalines;
 3  1  1 
 4  2  1 
 4  3  1 
 3  4  1 
 2  1  2 
 4  2  2 
 4  3  2 
 5  4  2 
 2  1  3 
 3  2  3 
 3  3  3 
 6  4  3 
 3  1  4 
 3  2  4 
 3  3  4 
 5  4  4 
 1  1  5 
 2  2  5 
 4  3  5 
 7  4  5 
 3  1  6 
 3  2  6 
 6  3  6 
 6  4  6 
 4  1  7 
 4  2  7 
 5  3  7 
10  4  7 
 6  1  8 
 5  2  8 
 5  3  8 
 8  4  8 
 ;
 run;
Table 7.2-1, page 260.
Note: The all option in the table statement display row and column sums.
options formchar='|-*+*+++*+*';

proc tabulate data=rb4;
  class s a;
  var y;
  table s all, sum*y=' '*(a all);
run;

*--------------+----------------------------------------------------------------*
|              |                              Sum                               |
|              +---------------------------------------------------+------------+
|              |                         a                         |            |
|              +------------+------------+------------+------------+            |
|              |     1      |     2      |     3      |     4      |    All     |
+--------------+------------+------------+------------+------------+------------+
|s             |            |            |            |            |            |
+--------------+            |            |            |            |            |
|1             |        3.00|        4.00|        4.00|        3.00|       14.00|
+--------------+------------+------------+------------+------------+------------+
|2             |        2.00|        4.00|        4.00|        5.00|       15.00|
+--------------+------------+------------+------------+------------+------------+
|3             |        2.00|        3.00|        3.00|        6.00|       14.00|
+--------------+------------+------------+------------+------------+------------+
|4             |        3.00|        3.00|        3.00|        5.00|       14.00|
+--------------+------------+------------+------------+------------+------------+
|5             |        1.00|        2.00|        4.00|        7.00|       14.00|
+--------------+------------+------------+------------+------------+------------+
|6             |        3.00|        3.00|        6.00|        6.00|       18.00|
+--------------+------------+------------+------------+------------+------------+
|7             |        4.00|        4.00|        5.00|       10.00|       23.00|
+--------------+------------+------------+------------+------------+------------+
|8             |        6.00|        5.00|        5.00|        8.00|       24.00|
+--------------+------------+------------+------------+------------+------------+
|All           |       24.00|       28.00|       34.00|       50.00|      136.00|
*--------------+------------+------------+------------+------------+------------*
Table 7.2-2, page 261.
proc glm data=rb4;
  class a s;
  model y = a s;
run;

The GLM Procedure

Dependent Variable: y

                                        Sum of
Source                      DF         Squares     Mean Square    F Value    Pr > F
Model                       10      80.5000000       8.0500000       5.73    0.0004
Error                       21      29.5000000       1.4047619
Corrected Total             31     110.0000000

R-Square     Coeff Var      Root MSE        y Mean
0.731818      27.88768      1.185227      4.250000

Source                      DF       Type I SS     Mean Square    F Value    Pr > F
a                            3     49.00000000     16.33333333      11.63    0.0001
s                            7     31.50000000      4.50000000       3.20    0.0180

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            3     49.00000000     16.33333333      11.63    0.0001
s                            7     31.50000000      4.50000000       3.20    0.0180
Table 7.3-2, page 271.
Note: The process of obtaining the Tukey's test for additivity takes several steps.
proc means mean data=rb4;  /* obtain grand mean */ var y;
run;

Analysis Variable : y

        Mean
------------
   4.2500000
------------

proc glm data=rb4;
  class a s;
  model y = a s;
  output out=rb4out predicted=yhat;  /* save the predicted scores yhat */
run;

[output omitted]

data rb4out;
  set rb4out;
  ybar = 4.25; /* the grand mean */
  ystar = (yhat-ybar)**2;
run;

proc glm data=rb4out;
  class a s;
  model y = a s ystar / ss3;  /* use sums of squares type 3 */
  /* the test for ystar is Tukeys test for additivity' */
run;

The GLM Procedure

Dependent Variable: y

                                        Sum of
Source                      DF         Squares     Mean Square    F Value    Pr > F
Model                       11      82.2738905       7.4794446       5.40    0.0006
Error                       20      27.7261095       1.3863055
Corrected Total             31     110.0000000


R-Square     Coeff Var      Root MSE        y Mean
0.747944      27.70388      1.177415      4.250000

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            3     35.72642695     11.90880898       8.59    0.0007
s                            7     23.76793627      3.39541947       2.45    0.0549
ystar                        1      1.77389051      1.77389051       1.28    0.2714
Figure 7.3-1, page 272.
proc glm data=rb4;
  class a s;
  model y = a s;
  output out=rb4out2 predicted=p rstudent=r ;
run;

[output omitted]

symbol1 v=circle;

proc gplot data=rb4out2;
  plot r*p;
run;
Various computations on compound symmetry, pages 274-282.
Note 1: This analysis requires that the data be organized in its wide form, with one line per subject.
Note 2: Proc corr is used with the cov option to display the covariance matrix. The nocorr and nosimple options suppress the correlation matrix and descriptive statistics.
data rb4wide;
input s y1 y2 y3 y4;
datalines;
1 3 4 4 3
2 2 4 4 5
3 2 3 3 6
4 3 3 3 5
5 1 2 4 7
6 3 3 6 6
7 4 4 5 10
8 6 5 5 8
;
run;

proc corr cov nocorr nosimple data=rb4wide;
  var y1 y2 y3 y4;
run;

The CORR Procedure

   4  Variables:    y1       y2       y3       y4

                        Covariance Matrix, DF = 7
                  y1                y2                y3                y4
y1       2.285714286       1.142857143       0.714285714       1.285714286
y2       1.142857143       0.857142857       0.285714286       0.285714286
y3       0.714285714       0.285714286       1.071428571       0.928571429
y4       1.285714286       0.285714286       0.928571429       4.500000000

proc glm data=rb4wide;
  model y1 y2 y3 y4 =  / nouni;
  repeated a;
run;

The GLM Procedure
Repeated Measures Analysis of Variance

           Repeated Measures Level Information

Dependent Variable          y1       y2       y3       y4
        Level of a           1        2        3        4


 Manova Test Criteria and Exact F Statistics for the Hypothesis of no a Effect
                        H = Type III SSCP Matrix for a
                             E = Error SSCP Matrix

                             S=1    M=0.5    N=1.5

Statistic                        Value    F Value    Num DF    Den DF    Pr > F
Wilks' Lambda               0.24580793       5.11         3         5    0.0554
Pillai's Trace              0.75419207       5.11         3         5    0.0554
Hotelling-Lawley Trace      3.06821705       5.11         3         5    0.0554
Roy's Greatest Root         3.06821705       5.11         3         5    0.0554

Univariate Tests of Hypotheses for Within Subject Effects

                                                                              Adj Pr > F
Source               DF    Type III SS    Mean Square   F Value   Pr > F    G - G    H - F
a                     3    49.00000000    16.33333333     11.63   0.0001   0.0015   0.0003
Error(a)             21    29.50000000     1.40476190

Greenhouse-Geisser Epsilon    0.6195
Huynh-Feldt Epsilon           0.8343
Use data file rb3.
data rb3;
input s a y;
datalines;
1 1 15
1 2 12
1 3 11
2 2 11
2 3  9
3 1 13
3 2 13
;
run;
Table 7.8-2, page 299.
proc tabulate data=rb3;
  class s a;
  var y;
  table s, sum*y=' '*a;
run;

*----------------+--------------------------------------*
|                |                 Sum                  |
|                +--------------------------------------+
|                |                  a                   |
|                +------------+------------+------------+
|                |     1      |     2      |     3      |
+----------------+------------+------------+------------+
|s               |            |            |            |
+----------------+            |            |            |
|1               |       15.00|       12.00|       11.00|
+----------------+------------+------------+------------+
|2               |           .|       11.00|        9.00|
+----------------+------------+------------+------------+
|3               |       13.00|       13.00|           .|
*----------------+------------+------------+------------*
Table 7.8-3, page 301.
proc glm data=rb3;
  class a s;
  model y = a s / ss3;
run;

The GLM Procedure

Dependent Variable: y

                                        Sum of
Source                      DF         Squares     Mean Square    F Value    Pr > F
Model                        4     19.73333333      4.93333333       4.35    0.1954
Error                        2      2.26666667      1.13333333
Corrected Total              6     22.00000000

R-Square     Coeff Var      Root MSE        y Mean
0.896970      8.871511      1.064581      12.00000

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            2      8.40000000      4.20000000       3.71    0.2125
s                            2      3.73333333      1.86666667       1.65    0.3778
Use datafile grb4.
data grb4;
input g id a y;
datalines;
 1  1  1  3 
 1  2  1  3 
 1  1  2  4 
 1  2  2  3 
 1  1  3  4 
 1  2  3  3 
 1  1  4  3 
 1  2  4  5 
 2  1  1  2 
 2  2  1  2 
 2  1  2  4 
 2  2  2  3 
 2  1  3  4 
 2  2  3  3 
 2  1  4  5 
 2  2  4  6 
 3  1  1  6 
 3  2  1  3 
 3  1  2  5 
 3  2  2  3 
 3  1  3  5 
 3  2  3  6 
 3  1  4  8 
 3  2  4  6 
 4  1  1  1 
 4  2  1  4 
 4  1  2  2 
 4  2  2  4 
 4  1  3  4 
 4  2  3  5 
 4  1  4  7 
 4  2  4 10
 ;
 run;
Tables 7.9-1, page 305.
proc tabulate data=grb4;
  class g id a;
  var y;
  table g*id, sum*y=' '*a;
run;

*----------------+---------------------------------------------------*
|                |                        Sum                        |
|                +---------------------------------------------------+
|                |                         a                         |
|                +------------+------------+------------+------------+
|                |     1      |     2      |     3      |     4      |
+-------+--------+------------+------------+------------+------------+
|g      |id      |            |            |            |            |
+-------+--------+            |            |            |            |
|1      |1       |        3.00|        4.00|        4.00|        3.00|
|       +--------+------------+------------+------------+------------+
|       |2       |        3.00|        3.00|        3.00|        5.00|
+-------+--------+------------+------------+------------+------------+
|2      |1       |        2.00|        4.00|        4.00|        5.00|
|       +--------+------------+------------+------------+------------+
|       |2       |        2.00|        3.00|        3.00|        6.00|
+-------+--------+------------+------------+------------+------------+
|3      |1       |        6.00|        5.00|        5.00|        8.00|
|       +--------+------------+------------+------------+------------+
|       |2       |        3.00|        3.00|        6.00|        6.00|
+-------+--------+------------+------------+------------+------------+
|4      |1       |        1.00|        2.00|        4.00|        7.00|
|       +--------+------------+------------+------------+------------+
|       |2       |        4.00|        4.00|        5.00|       10.00|
*-------+--------+------------+------------+------------+------------*

proc tabulate data=grb4;
  class g a;
  var y;
  table g all, sum*y=' '*(a all);
run;

*----------------+----------------------------------------------------------------*
|                |                              Sum                               |
|                +---------------------------------------------------+------------+
|                |                         a                         |            |
|                +------------+------------+------------+------------+            |
|                |     1      |     2      |     3      |     4      |    All     |
+----------------+------------+------------+------------+------------+------------+
|g               |            |            |            |            |            |
+----------------+            |            |            |            |            |
|1               |        6.00|        7.00|        7.00|        8.00|       28.00|
+----------------+------------+------------+------------+------------+------------+
|2               |        4.00|        7.00|        7.00|       11.00|       29.00|
+----------------+------------+------------+------------+------------+------------+
|3               |        9.00|        8.00|       11.00|       14.00|       42.00|
+----------------+------------+------------+------------+------------+------------+
|4               |        5.00|        6.00|        9.00|       17.00|       37.00|
+----------------+------------+------------+------------+------------+------------+
|All             |       24.00|       28.00|       34.00|       50.00|      136.00|
*----------------+------------+------------+------------+------------+------------*
Table 7.9-2, page 306.
Note: To obtain the correct F-ratio for a, a*b is used as the error term.
proc glm data=grb4;
  class a g id;
  model y = a g a*g / ss3;
  test h=a e=a*g;
run;

The GLM Procedure

Dependent Variable: y

                                        Sum of
Source                      DF         Squares     Mean Square    F Value    Pr > F
Model                       15      85.0000000       5.6666667       3.63    0.0074
Error                       16      25.0000000       1.5625000
Corrected Total             31     110.0000000

R-Square     Coeff Var      Root MSE        y Mean
0.772727      29.41176      1.250000      4.250000

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            3     49.00000000     16.33333333      10.45    0.0005
g                            3     16.75000000      5.58333333       3.57    0.0377
a*g                          9     19.25000000      2.13888889       1.37    0.2795

        Tests of Hypotheses Using the Type III MS for a*g as an Error Term

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            3     49.00000000     16.33333333       7.64    0.0076

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California