Stata Textbook Examples
Experimental Design by Roger Kirk
Chapter 14: Fractional Factorial Designs

Use data file crff24-1, page 596.
use http://www.ats.ucla.edu/stat/stata/examples/kirk/crff24-1, clear

list

            a         b         c         d         y 
  1.        0         0         0         0         3  
  2.        0         0         0         0         6  
  3.        0         0         1         1         4  
  4.        0         0         1         1         3  
  5.        0         1         0         1         7  
  6.        0         1         0         1         6  
  7.        0         1         1         0         7  
  8.        0         1         1         0         8  
  9.        1         0         0         1         2  
 10.        1         0         0         1         2  
 11.        1         0         1         0         2  
 12.        1         0         1         0         3  
 13.        1         1         0         0         5  
 14.        1         1         0         0         6  
 15.        1         1         1         1         9  
 16.        1         1         1         1        11 
Parts of Table 14.3-1, page 672.
table a c b, cont(sum y)

----------+-------------------------
          |         b and c         
          | ---- 0 ---    ---- 1 ---
        a |    0     1       0     1
----------+-------------------------
        0 |    9     7      13    15
        1 |    4     5      11    20
----------+-------------------------

table a b, cont(sum y) row col

----------+--------------------
          |          b         
        a |     0      1  Total
----------+--------------------
        0 |    16     28     44
        1 |     9     31     40
          | 
    Total |    25     59     84
----------+--------------------

table a c, cont(sum y) row 

----------+-----------
          |     c     
        a |    0     1
----------+-----------
        0 |   22    22
        1 |   15    25
          | 
    Total |   37    47
----------+-----------

table b c, cont(sum y) 

----------+-----------
          |     c     
        b |    0     1
----------+-----------
        0 |   13    12
        1 |   24    35
----------+-----------
Table 14.3-2, page 674.
anova y a b c d a*b a*c b*c

                     Number of obs =      16     R-squared     =  0.9189
                     Root MSE      = 1.06066     Adj R-squared =  0.8480

            Source |  Partial SS    df       MS           F     Prob > F
        -----------+----------------------------------------------------
             Model |      102.00     7  14.5714286      12.95     0.0009
                   |
                 a |        1.00     1        1.00       0.89     0.3734
                 b |       72.25     1       72.25      64.22     0.0000
                 c |        6.25     1        6.25       5.56     0.0462
                 d |        1.00     1        1.00       0.89     0.3734
               a*b |        6.25     1        6.25       5.56     0.0462
               a*c |        6.25     1        6.25       5.56     0.0462
               b*c |        9.00     1        9.00       8.00     0.0222
                   |
          Residual |        9.00     8       1.125   
        -----------+----------------------------------------------------
             Total |      111.00    15        7.40
Use data file lsff33-2, page 688.
use http://www.ats.ucla.edu/stat/stata/examples/kirk/lsff33-2, clear

list

            a         b         c         s         y 
  1.        0         0         0         0         3  
  2.        0         1         1         0         4  
  3.        0         2         2         0         6  
  4.        0         0         0         1         1  
  5.        0         1         1         1         4  
  6.        0         2         2         1         6  
  7.        1         0         2         2         7  
  8.        1         1         0         2         3  
  9.        1         2         1         2         3  
 10.        1         0         2         3         5  
 11.        1         1         0         3         2  
 12.        1         2         1         3         3  
 13.        2         0         1         4         4  
 14.        2         1         2         4         7  
 15.        2         2         0         4         3  
 16.        2         0         1         5         2  
 17.        2         1         2         5         5  
 18.        2         2         0         5         2 
Table 14.8-1, pages 688 and 689.
tabdisp s b, cellvar(y) by(a) concise

----------+-----------------
          |        b        
  a and s |    0     1     2
----------+-----------------
0         |
        0 |    3     4     6
        1 |    1     4     6
----------+-----------------
1         |
        2 |    7     3     3
        3 |    5     2     3
----------+-----------------
2         |
        4 |    4     7     3
        5 |    2     5     2
----------+-----------------

table b c, cont(sum y) by(a)

----------+-----------------
          |        c        
  a and b |    0     1     2
----------+-----------------
0         |
        0 |    4            
        1 |          8      
        2 |               12
----------+-----------------
1         |
        0 |               12
        1 |    5            
        2 |          6      
----------+-----------------
2         |
        0 |          6      
        1 |               12
        2 |    5            
----------+-----------------

table c b, cont(sum y) row col

----------+---------------------------
          |             b             
        c |     0      1      2  Total
----------+---------------------------
        0 |     4      5      5     14
        1 |     6      8      6     20
        2 |    12     12     12     36
          | 
    Total |    22     25     23     70
----------+--------------------------- 
Table 14.8-2, page 690.

Note: Kirk calls a*b*c residual and calls the Residual b*c*s|a.
anova y a / s|a b c b*c*a

                     Number of obs =      18     R-squared     =  0.9504
                     Root MSE      = .666667     Adj R-squared =  0.8595

            Source |  Partial SS    df       MS           F     Prob > F
        -----------+----------------------------------------------------
             Model |  51.1111111    11  4.64646465      10.45     0.0046
                   |
                 a |  .111111111     2  .055555556       0.03     0.9742
               s|a |  6.33333333     3  2.11111111   
        -----------+----------------------------------------------------
                 b |  .777777778     2  .388888889       0.88     0.4640
                 c |  43.1111111     2  21.5555556      48.50     0.0002
             b*c*a |  .777777778     2  .388888889       0.87     0.4640
                   |
          Residual |  2.66666667     6  .444444444   
        -----------+----------------------------------------------------
             Total |  53.7777778    17  3.16339869 
Use data file lsff43-2, page 693.
use http://www.ats.ucla.edu/stat/stata/examples/kirk/lsff43-2, clear

list

            a         b         c         d         y 
  1.        0         0         0         0         2  
  2.        0         1         3         0         3  
  3.        0         2         2         0         3  
  4.        0         3         1         0         6  
  5.        1         0         1         0         2  
  6.        1         1         0         0         4  
  7.        1         2         3         0         5  
  8.        1         3         2         0         4  
  9.        2         0         2         0         5  
 10.        2         1         1         0         8  
 11.        2         2         0         0         7  
 12.        2         3         3         0         6  
 13.        3         0         3         0         9  
 14.        3         1         2         0         9  
 15.        3         2         1         0        11  
 16.        3         3         0         0        10  
 17.        0         0         0         1         1  
 18.        0         1         3         1         2  
 19.        0         2         2         1         2  
 20.        0         3         1         1         3  
 21.        1         0         1         1         3  
 22.        1         1         0         1         3  
 23.        1         2         3         1         4  
 24.        1         3         2         1         3  
 25.        2         0         2         1         6  
 26.        2         1         1         1         6  
 27.        2         2         0         1         5  
 28.        2         3         3         1         7  
 29.        3         0         3         1         8  
 30.        3         1         2         1         8  
 31.        3         2         1         1        10  
 32.        3         3         0         1         7  
Table 14.9-1, page 693.
tabdisp a b, cellvar(y) by(d)

----------+-----------------------
          |           b           
  d and a |    0     1     2     3
----------+-----------------------
0         |
        0 |    2     3     3     6
        1 |    2     4     5     4
        2 |    5     8     7     6
        3 |    9     9    11    10
----------+-----------------------
1         |
        0 |    1     2     2     3
        1 |    3     3     4     3
        2 |    6     6     5     7
        3 |    8     8    10     7
----------+-----------------------

table a d, cont(sum y) col

----------+--------------------
          |          d         
        a |     0      1  Total
----------+--------------------
        0 |    14      8     22
        1 |    15     13     28
        2 |    26     24     50
        3 |    39     33     72
----------+--------------------

table b d, cont(sum y) col

----------+--------------------
          |          d         
        b |     0      1  Total
----------+--------------------
        0 |    18     18     36
        1 |    24     19     43
        2 |    26     21     47
        3 |    26     20     46
----------+--------------------
Table 14.9-2, page 695.
anova y a b c d a*d b*d c*d

                     Number of obs =      32     R-squared     =  0.9618
                     Root MSE      = .866025     Adj R-squared =  0.9013

            Source |  Partial SS    df       MS           F     Prob > F
        -----------+----------------------------------------------------
             Model |      226.50    19  11.9210526      15.89     0.0000
                   |
                 a |      194.50     3  64.8333333      86.44     0.0000
                 b |        9.25     3  3.08333333       4.11     0.0320
                 c |        7.75     3  2.58333333       3.44     0.0517
                 d |        8.00     1        8.00      10.67     0.0068
               a*d |        2.00     3  .666666667       0.89     0.4747
               b*d |        2.75     3  .916666667       1.22     0.3441
               c*d |        2.25     3         .75       1.00     0.4262
                   |
          Residual |        9.00    12         .75   
        -----------+----------------------------------------------------
             Total |      235.50    31  7.59677419

How to cite this page

Report an error on this page or leave a comment

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.