Skip to Main Content

Design and Analysis, Fourth Edition, by Keppel and Wickens Chapter 25: Nested Factors | SAS Textbook Examples

Data from the completely between subject design, Table 25.1, page 552

data table25_1a;
input a b y;
datalines;
1 1 14
1 2 13
1 3 15
1 1 15
1 2 12
1 3 17
1 1 12
1 2 15
1 3 15
1 1 13
1 2 16
1 3 16
1 1 13
1 2 12
1 3 15
2 1 7
2 2 8
2 3 13
2 1 8
2 2 6
2 3 10
2 1 7
2 2 11
2 3 11
2 1 7
2 2 11
2 3 11
2 1 8
2 2 11
2 3 10
;
run;

Analysis of Variance from the completely between-subject design with Factor B
nested within Factor A, Table 25.3, page 557

NOTE: Refer to Chapter 24 for a discussion of the random statement.

proc glm data = table25_1a;
  class a b;
  model y = a b(a) / ss3;
  random b(a) / test;
run; 
quit;
The GLM Procedure

Dependent Variable: y
                                        Sum of
Source                      DF         Squares     Mean Square    F Value    Pr > F
Model                        5     229.8666667      45.9733333      22.07    <.0001
Error                       24      50.0000000       2.0833333
Corrected Total             29     279.8666667

R-Square     Coeff Var      Root MSE        y Mean
0.821343      12.30150      1.443376      11.73333

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            1     182.5333333     182.5333333      87.62    <.0001
b(a)                         4      47.3333333      11.8333333       5.68    0.0023

Source                  Type III Expected Mean Square
a                       Var(Error) + 5 Var(b(a)) + Q(a)
b(a)                    Var(Error) + 5 Var(b(a))
Tests of Hypotheses for Mixed Model Analysis of Variance

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            1      182.533333      182.533333      15.43    0.0171
Error: MS(b(a))              4       47.333333       11.833333

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
b(a)                         4       47.333333       11.833333       5.68    0.0023
Error: MS(Error)            24       50.000000        2.083333
proc mixed data = table25_1a method = type3;
  class a b;
  model y = a ;
  random b(a);
run; quit;
The Mixed Procedure

                  Model Information
Data Set                     WORK.TABLE25_1A
Dependent Variable           y
Covariance Structure         Variance Components
Estimation Method            Type 3
Residual Variance Method     Factor
Fixed Effects SE Method      Model-Based
Degrees of Freedom Method    Containment

             Class Level Information
Class    Levels    Values
a             2    1 2
b             3    1 2 3

           Dimensions
Covariance Parameters             2
Columns in X                      3
Columns in Z                      6
Subjects                          1
Max Obs Per Subject              30
Observations Used                30
Observations Not Used             0
Total Observations               30

                                   Type 3 Analysis of Variance
                        Sum of
Source        DF       Squares   Mean Square  Expected Mean Square                Error Term
a              1    182.533333    182.533333  Var(Residual) + 5 Var(b(a)) + Q(a)  MS(b(a))
b(a)           4     47.333333     11.833333  Var(Residual) + 5 Var(b(a))         MS(Residual)
Residual      24     50.000000      2.083333  Var(Residual)                       .
     Type 3 Analysis of Variance
           Error
Source        DF    F Value    Pr > F
a              4      15.43    0.0171
b(a)          24       5.68    0.0023
Residual       .        .       .

Covariance Parameter
      Estimates
Cov Parm     Estimate
b(a)           1.9500
Residual       2.0833

           Fit Statistics
-2 Res Log Likelihood           112.4
AIC (smaller is better)         116.4
AICC (smaller is better)        116.9
BIC (smaller is better)         116.0

        Type 3 Tests of Fixed Effects
              Num     Den
Effect         DF      DF    F Value    Pr > F
a               1       4      15.43    0.0171

Data from the completely within-subject design, Table 25.1, page 552

data table25_1b;
input s a b y;
datalines;
1 1 1 13
1 1 2 12
1 1 3 12
1 2 1 7
1 2 2 12
1 2 3 12
2 1 1 16
2 1 2 13
2 1 3 18
2 2 1 10
2 2 2 12
2 2 3 11
3 1 1 15
3 1 2 13
3 1 3 14
3 2 1 5
3 2 2 8
3 2 3 8
4 1 1 12
4 1 2 13
4 1 3 15
4 2 1 7
4 2 2 11
4 2 3 13
5 1 1 15
5 1 2 13
5 1 3 14
5 2 1 5
5 2 2 8
5 2 3 12
;
run;

Analysis of Variance from the completely within-subject design, Table 25.3,
page 557. Factor B is nested within Factor A and all observations are completely
within-subject.

proc glm data = table25_1b;
  class s a b;
  model y = a b(a) s a*s / ss3;
  random b(a) s a*s / test;
run; 
quit;
The GLM Procedure

     Class Level Information
Class         Levels    Values
s                  5    1 2 3 4 5
a                  2    1 2
b                  3    1 2 3

Number of observations    30

Dependent Variable: y
                                        Sum of
Source                      DF         Squares     Mean Square    F Value    Pr > F
Model                       13     263.1000000      20.2384615      11.62    <.0001
Error                       16      27.8666667       1.7416667
Corrected Total             29     290.9666667

R-Square     Coeff Var      Root MSE        y Mean
0.904227      11.34432      1.319722      11.63333

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            1     149.6333333     149.6333333      85.91    <.0001
b(a)                         4      62.1333333      15.5333333       8.92    0.0006
s                            4      27.1333333       6.7833333       3.89    0.0215
s*a                          4      24.2000000       6.0500000       3.47    0.0318

Source                  Type III Expected Mean Square
a                       Var(Error) + 3 Var(s*a) + 5 Var(b(a)) + Q(a)
b(a)                    Var(Error) + 5 Var(b(a))
s                       Var(Error) + 3 Var(s*a) + 6 Var(s)
s*a                     Var(Error) + 3 Var(s*a)
Tests of Hypotheses for Mixed Model Analysis of Variance

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            1      149.633333      149.633333       7.54    0.0356
Error                   5.6515      112.135397       19.841667
Error: MS(b(a)) + MS(s*a) - MS(Error)

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
b(a)                         4       62.133333       15.533333       8.92    0.0006
s*a                          4       24.200000        6.050000       3.47    0.0318
Error: MS(Error)            16       27.866667        1.741667

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
s                            4       27.133333        6.783333       1.12    0.4572
Error: MS(s*a)               4       24.200000        6.050000
proc mixed data = table25_1b method = type3;
  class s a b;
  model y = a ;
  random b(a) s a*s ;
run; 
quit;
The Mixed Procedure

                  Model Information
Data Set                     WORK.TABLE25_1B
Dependent Variable           y
Covariance Structure         Variance Components
Estimation Method            Type 3
Residual Variance Method     Factor
Fixed Effects SE Method      Model-Based
Degrees of Freedom Method    Containment

             Class Level Information
Class    Levels    Values
s             5    1 2 3 4 5
a             2    1 2
b             3    1 2 3

            Dimensions
Covariance Parameters             4
Columns in X                      3
Columns in Z                     21
Subjects                          1
Max Obs Per Subject              30
Observations Used                30
Observations Not Used             0
Total Observations               30

                                   Type 3 Analysis of Variance
                          Sum of
Source         DF        Squares    Mean Square   Expected Mean Square
a               1     149.633333     149.633333   Var(Residual) + 3 Var(s*a) + 5 Var(b(a)) + Q(a)
b(a)            4      62.133333      15.533333   Var(Residual) + 5 Var(b(a))
s               4      27.133333       6.783333   Var(Residual) + 3 Var(s*a) + 6 Var(s)

                         Type 3 Analysis of Variance
                                                   Error
Source     Error Term                                 DF    F Value    Pr > F
a          MS(b(a)) + MS(s*a) - MS(Residual)      5.6515       7.54    0.0356
b(a)       MS(Residual)                               16       8.92    0.0006
s          MS(s*a)                                     4       1.12    0.4572

                                   Type 3 Analysis of Variance
                         Sum of
Source         DF        Squares    Mean Square   Expected Mean Square
s*a             4      24.200000       6.050000   Var(Residual) + 3 Var(s*a)
Residual       16      27.866667       1.741667   Var(Residual)

                         Type 3 Analysis of Variance
                                                   Error
Source     Error Term                                 DF    F Value    Pr > F
s*a        MS(Residual)                               16       3.47    0.0318
Residual   .                                           .        .       .

Covariance Parameter
      Estimates
Cov Parm     Estimate
b(a)           2.7583
s              0.1222
s*a            1.4361
Residual       1.7417

           Fit Statistics
-2 Res Log Likelihood           119.6
AIC (smaller is better)         127.6
AICC (smaller is better)        129.3
BIC (smaller is better)         126.8

        Type 3 Tests of Fixed Effects
              Num     Den
Effect         DF      DF    F Value    Pr > F
a               1       4       7.54    0.0516

Data from the mixed design (long format), Table 25.1, page 552

data table25_1c;
input s a b y;
datalines;
1  1 1 13
1  1 2 11
1  1 3 15
2  1 1 16
2  1 2 11
2  1 3 16
3  1 1 13
3  1 2 16
3  1 3 17
4  1 1 13
4  1 2 14
4  1 3 16
5  1 1 13
5  1 2 12
5  1 3 16
6  2 1 7
6  2 2 9
6  2 3 13
7  2 1 9
7  2 2 6
7  2 3 11
8  2 1 7
8  2 2 10
8  2 3 10
9  2 1 9
9  2 2 13
9  2 3 16
10 2 1 8
10 2 2 11
10 2 3 11
;
run;

Analysis of Variance from a nested mixed design, Table 25.3, page 557

NOTE: Subjects are nested within Factor A, Factor B is nested within Factor A
implying that subjects are crossed with Factor B.

proc glm data = table25_1c;
  class s a b;
  model y = a b(a) s(a) /ss3;
  random a b(a) s(a) / test;
run; 
quit;
The GLM Procedure

           Class Level Information
Class         Levels    Values
s                 10    1 2 3 4 5 6 7 8 9 10
a                  2    1 2
b                  3    1 2 3

Number of observations    30

Dependent Variable: y
                                        Sum of
Source                      DF         Squares     Mean Square    F Value    Pr > F
Model                       13     239.3333333      18.4102564       6.93    0.0002
Error                       16      42.5333333       2.6583333
Corrected Total             29     281.8666667

R-Square     Coeff Var      Root MSE        y Mean
0.849101      13.51193      1.630440      12.06667

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            1     128.1333333     128.1333333      48.20    <.0001
b(a)                         4      72.1333333      18.0333333       6.78    0.0022
s(a)                         8      39.0666667       4.8833333       1.84    0.1430


Source                  Type III Expected Mean Square
a                       Var(Error) + 3 Var(s(a)) + 5 Var(b(a)) + 15 Var(a)
b(a)                    Var(Error) + 5 Var(b(a))
s(a)                    Var(Error) + 3 Var(s(a))

Tests of Hypotheses for Random Model Analysis of Variance

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
a                            1      128.133333      128.133333       6.32    0.0551
Error                    4.844       98.132023       20.258333
Error: MS(b(a)) + MS(s(a)) - MS(Error)

Source                      DF     Type III SS     Mean Square    F Value    Pr > F
b(a)                         4       72.133333       18.033333       6.78    0.0022
s(a)                         8       39.066667        4.883333       1.84    0.1430
Error: MS(Error)            16       42.533333        2.658333
proc mixed data = table25_1c method = type3 ;
  class s a b;
  model y = a ;
  random b(a) s(a);
run; 
quit;
The Mixed Procedure

                  Model Information
Data Set                     WORK.TABLE25_1C
Dependent Variable           y
Covariance Structure         Variance Components
Estimation Method            Type 3
Residual Variance Method     Factor
Fixed Effects SE Method      Model-Based
Degrees of Freedom Method    Containment

             Class Level Information
Class    Levels    Values
s            10    1 2 3 4 5 6 7 8 9 10
a             2    1 2
b             3    1 2 3

            Dimensions
Covariance Parameters             3
Columns in X                      3
Columns in Z                     16
Subjects                          1
Max Obs Per Subject              30
Observations Used                30
Observations Not Used             0
Total Observations               30

                                   Type 3 Analysis of Variance
                          Sum of
Source         DF        Squares    Mean Square   Expected Mean Square
a               1     128.133333     128.133333   Var(Residual) + 3 Var(s(a)) + 5 Var(b(a)) + Q(a)
b(a)            4      72.133333      18.033333   Var(Residual) + 5 Var(b(a))
s(a)            8      39.066667       4.883333   Var(Residual) + 3 Var(s(a))

                         Type 3 Analysis of Variance
                                                   Error
Source     Error Term                                 DF    F Value    Pr > F
a          MS(b(a)) + MS(s(a)) - MS(Residual)      4.844       6.32    0.0551
b(a)       MS(Residual)                               16       6.78    0.0022
s(a)       MS(Residual)                               16       1.84    0.1430

                                   Type 3 Analysis of Variance
                          Sum of
Source         DF        Squares    Mean Square   Expected Mean Square
Residual       16      42.533333       2.658333   Var(Residual)

                         Type 3 Analysis of Variance
                                                   Error
Source     Error Term                                 DF    F Value    Pr > F
Residual   .                                           .        .       .

Covariance Parameter
      Estimates
Cov Parm     Estimate
b(a)           3.0750
s(a)           0.7417
Residual       2.6583

           Fit Statistics
-2 Res Log Likelihood           124.8
AIC (smaller is better)         130.8
AICC (smaller is better)        131.8
BIC (smaller is better)         130.2

        Type 3 Tests of Fixed Effects
              Num     Den
Effect         DF      DF    F Value    Pr > F
a               1       4       6.32    0.0657