\section*{Factorial Designs---Examples}
Factorial designs with each factor at two levels are extremely
important in practice.  Many experiments, especially industrial ones,
have factors at 2 levels.  Things like (off,on), (high, low),
(treatment, placebo).

To perform a general factorial design, select a fixed number of levels
for each factor in the design.  If the levels are $l_1, l_2, \ldots,
l_k$, then such an experiment is called an
$l_1 \times l_2 \times \cdots \times \l_k$ factorial design.  When
$l_k = 2 $ for all $k$ then it is called a $2^k$ factorial design.  

Factorial designs, and in particular $2^k$ factorial design are
important because:
\begin{itemize}
\item They require relatively few runs per factor studied.
\item It is possible to run {\em fractional\/} designs that are even
  more economical---at some expense in accuracy/estimability.
\item They are easy to interpret, and some simple effects can be seen
  with common sense and a little arithmetic. (Hence, it is easier to
  convince your boss of what is happening)
\end{itemize}

There are many standard notations for a (say) $2^3$ design.  If the
three factors are T, C, and K, each at 2 levels, then here are just
some of the ways such a design is represented.

\begin{tabular}{c c c c c c c c}
Run & T & C & K&\ \ \ \ \ & T & C & K \\ \hline
1 &$-$ &$-$ &$-$ &1& 0 & 0 & 0 \\
2 &$+$ &$-$ &$-$ &t& 1 & 0 & 0 \\
3 &$-$ &$+$ &$-$ &c& 0 & 1 & 0 \\
4 &$+$ &$+$ &$-$ &tc&1 & 1 & 0 \\
5 &$-$ &$-$ &$+$ &k &0 & 0 & 1 \\
6 &$+$ &$-$ &$+$ &tk&1 & 0 & 1 \\
7 &$-$ &$+$ &$+$ &ck&0 & 1 & 1 \\
8 &$+$ &$+$ &$+$&tck&1 & 1 & 1 \\
\end{tabular}

Here is data from a particular experiment, coded in a couple of
different ways.  The original data were part of a pilot plant
investigation of a process and have been simplified for this example.
There are two quantitative predictors (temperature and concentration) and a
qualitative predictor (catalyst).  The response is the chemical yield.

\begin{center}
\begin{tabular}{c c c c c }
\hline
test & temp & concentration & catalyst & yield \\
condition & (C) & (\%) & (A or B) & (grams) \\
number & T & C & K & y \\ \hline
\multicolumn{5}{c}{Original units of variables} \\
\\
1 & 160 & 20 & A & 60 \\
2 & 180 & 20 & A & 72 \\
3 & 160 & 40 & A & 54 \\
4 & 180 & 40 & A & 68 \\
5 & 160 & 20 & B & 52 \\
6 & 180 & 20 & B & 83 \\
7 & 160 & 40 & B & 45 \\
8 & 180 & 40 & B & 80 \\
\\
\multicolumn{5}{c}{Coded units of variables} \\
1 & $-$ & $-$ & $-$ & 60 \\
2 & $+$ & $-$ & $-$ & 72 \\
3 & $-$ & $+$ & $-$ & 54 \\
4 & $+$ & $+$ & $-$ & 68 \\
5 & $-$ & $-$ & $+$ & 52 \\
6 & $+$ & $-$ & $+$ & 83 \\
7 & $-$ & $+$ & $+$ & 45 \\
8 & $+$ & $+$ & $+$ & 80 \\ \hline
\end{tabular}\\
\end{center}
\ \vspace*{2ex} \\
with \\
\vspace*{2ex}
\begin{center}
\begin{tabular}[c]{c c c c c c}
\multicolumn{2}{c}{Temperature} & \multicolumn{2}{c}{Concentration} &
\multicolumn{2}{c}{Catalyst}  \\
$-$ & $+$ & $-$ & $+$ & $-$ & $+$ \\
160 & 180 & 20 & 40 & A & B \\
\end{tabular} \\
\end{center}

Lets try a quick analysis of these data, in the first form.
Here is the data
\begin{verbatim}
Run Temp  Conc Caty Yield
1   160   20   A   60
2   180   20   A   72
3   160   40   A   54
4   180   40   A   68
5   160   20   B   52
6   180   20   B   83
7   160   40   B   45
8   180   40   B   80
\end{verbatim}

and reading the data into S
\begin{verbatim}
> chem <- read.table("chemical.dat", header=T)                         
> chem
  Run Temp Conc Caty Yield 
1   1  160   20    A    60
2   2  180   20    A    72
3   3  160   40    A    54
4   4  180   40    A    68
5   5  160   20    B    52
6   6  180   20    B    83
7   7  160   40    B    45
8   8  180   40    B    80
> mychem <- data.frame(Run=chem$Run, Temp=as.factor(chem$Temp),
+ Conc=as.factor(chem$Conc), Caty=chem$Caty, Yield=chem$Yield)
> chem <- mychem
> rm(mychem)
> chem
  Run Temp Conc Caty Yield 
1   1  160   20    A    60
2   2  180   20    A    72
3   3  160   40    A    54
4   4  180   40    A    68
5   5  160   20    B    52
6   6  180   20    B    83
7   7  160   40    B    45
8   8  180   40    B    80
\end{verbatim}

Note the ``fancy'' footwork to make sure we have factors.  
\begin{verbatim}
> plot.factor(chem, y=Yield)
> interaction.plot(Temp, Conc, Yield)
> interaction.plot(Temp, Caty, Yield)
> interaction.plot(Conc, Caty, Yield)
\end{verbatim}

\psfig{figure=factorial1.eps,angle=-90,width=5.6in}
\psfig{figure=factorial2.eps,angle=-90,width=5.6in}

And now the simple ANOVA.
\begin{verbatim}
> mymod <- aov(Yield ~ Temp + Conc + Caty + Temp*Caty, data=chem)
> anova(mymod)
Analysis of Variance Table

Response: Yield

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq F Value     Pr(F) 
Temp       1    1058.0 1058.000   634.8 0.0001371
Conc       1      50.0   50.000    30.0 0.0119669
Caty       1       4.5    4.500     2.7 0.1988922
Temp:Caty  1     200.0  200.000   120.0 0.0016286
Residuals  3       5.0    1.667                  

> plot(mymod)
\end{verbatim}

\psfig{figure=factorial3.eps,angle=-90,width=5.6in}

If one really wanted to look at all the two-way effects one might do
\begin{verbatim}
> mymod <- aov(Yield ~ Temp + Conc + Caty + Temp*Caty +             
+ Temp*Conc + Caty*Conc, data=chem)
> anova(mymod)
Analysis of Variance Table

Response: Yield

Terms added sequentially (first to last)
          Df Sum of Sq Mean Sq F Value     Pr(F) 
Temp       1    1058.0  1058.0    2116 0.0138374
Conc       1      50.0    50.0     100 0.0634510
Caty       1       4.5     4.5       9 0.2048328
Temp:Caty  1     200.0   200.0     400 0.0318045
Temp:Conc  1       4.5     4.5       9 0.2048328
Caty:Conc  1       0.0     0.0       0 1.0000000
Residuals  1       0.5     0.5                  
\end{verbatim}

One might also wish to do a QQ plot of the model effects
\begin{verbatim}
> mymod <- aov(Yield ~ Temp + Conc + Caty + Temp*Caty, data=chem)   
> qqnorm(mymod)                                                  
\end{verbatim}

\psfig{figure=factorial4.eps,angle=-90,width=5.6in}

\section*{Fractional Factorial Designs---Examples}
Factorial designs are great, but the number of runs required for a
full $2^k$ design increases exponentially in $k$.  When $k$ is large
(say bigger than 4 or 5) it is often a good idea to run a fraction of
the design---and recover a fraction of the possible information.
Hopefully one designs the experiment to recover a useful fraction of
the information.

Consider a two-level design with seven variables.  A complete
factorial design would require $2^7 = 128$ runs, which might be a
prohibative number.  These 128 degress of freedom would be partioned
into main effects and interactions, as follows \\
\begin{verbatim}
average  main  2-fact  3-fact  4-fact  5-fact  6-fact  7-fact
  1       7      21     35      35      21      7       1
\end{verbatim}

The high order interactions are probably {\bf not} very interesting.
If we were to drop them from the model (assume they are zero!), it
would be very much like assuming that the higher order terms of a
Taylor Series expansion are zero. (Actually, a Fourier series
expansion is the better model, but you get the idea).  
The aim of a fractional factorial design is to run the experiment so
that the high order interactions (which we might assume to be zero)
are confounded with things that we would like to know.

The best way to proceed is via an example.
First lets generate the design and add the data.
\begin{verbatim}
> reactor <- fac.design(c(2,2,2,2,2))
> attach(reactor, pos=1)
> Resp <- c(61,53,63,61,53,56,54,61,69,61,94,93,66,60,95,98,
+ 56,63,70,65,59,55,67,65,44,45,78,77,49,42,81,82)
> length(Resp)
[1] 32
> detach(1, save="newreact")
> reactor <- newreact
> rm(newreact)
\end{verbatim}

Now lets just print out the data to look at.
\begin{verbatim}
> reactor
    A  B  C  D  E Resp 
 1 A1 B1 C1 D1 E1   61
 2 A2 B1 C1 D1 E1   53
 3 A1 B2 C1 D1 E1   63
 4 A2 B2 C1 D1 E1   61
 5 A1 B1 C2 D1 E1   53
 6 A2 B1 C2 D1 E1   56
 7 A1 B2 C2 D1 E1   54
 8 A2 B2 C2 D1 E1   61
 9 A1 B1 C1 D2 E1   69
10 A2 B1 C1 D2 E1   61
11 A1 B2 C1 D2 E1   94
12 A2 B2 C1 D2 E1   93
13 A1 B1 C2 D2 E1   66
14 A2 B1 C2 D2 E1   60
15 A1 B2 C2 D2 E1   95
16 A2 B2 C2 D2 E1   98
17 A1 B1 C1 D1 E2   56
18 A2 B1 C1 D1 E2   63
19 A1 B2 C1 D1 E2   70
20 A2 B2 C1 D1 E2   65
21 A1 B1 C2 D1 E2   59
22 A2 B1 C2 D1 E2   55
23 A1 B2 C2 D1 E2   67
24 A2 B2 C2 D1 E2   65
25 A1 B1 C1 D2 E2   44
26 A2 B1 C1 D2 E2   45
27 A1 B2 C1 D2 E2   78
28 A2 B2 C1 D2 E2   77
29 A1 B1 C2 D2 E2   49
30 A2 B1 C2 D2 E2   42
31 A1 B2 C2 D2 E2   81
32 A2 B2 C2 D2 E2   82
\end{verbatim}

Now suppose that we had not run the entire experiment, but only some
of the runs, in particular, runs
\begin{verbatim}
> runs
 [1]  2  3  5  8  9 12 14 15 17 20 22 23 26 27 29 32
\end{verbatim}

So our data might have been,
\begin{verbatim}
> half.reactor <- reactor[runs,]
> half.reactor
    A  B  C  D  E Resp 
 2 A2 B1 C1 D1 E1   53
 3 A1 B2 C1 D1 E1   63
 5 A1 B1 C2 D1 E1   53
 8 A2 B2 C2 D1 E1   61
 9 A1 B1 C1 D2 E1   69
12 A2 B2 C1 D2 E1   93
14 A2 B1 C2 D2 E1   60
15 A1 B2 C2 D2 E1   95
17 A1 B1 C1 D1 E2   56
20 A2 B2 C1 D1 E2   65
22 A2 B1 C2 D1 E2   55
23 A1 B2 C2 D1 E2   67
26 A2 B1 C1 D2 E2   45
27 A1 B2 C1 D2 E2   78
29 A1 B1 C2 D2 E2   49
32 A2 B2 C2 D2 E2   82
\end{verbatim}

The variables are feed rate (10, 15), catalyst (1\%, 2\%), agitation
rate (100,120), temp (140, 180), concentration (3\%, 6\%) and the
response is the percentage of the ingredients that reacted.

How would we analyse these data?  First off we might like to know what
effects are ``aliased'' with what other effects.  Aliasing means that
a contrast for one effect is exactly the same as a contract for
another.  Here is the alias pattern for these data.
\begin{verbatim}
> alias(half.reactor, ~ (A+B+C+D+E)^4)
Model 
 ~ (A + B + C + D + E)^4

Complete 
        (Intercept)  A  B  C  D  E A:B A:C A:D A:E B:C B:D B:E C:D C:E D:E 
  A:B:C                                                                 1 
  A:B:D                                                             1     
  A:B:E                                                         1         
  A:C:D                                                     1             
  A:C:E                                                 1                 
  A:D:E                                             1                     
  B:C:D                                         1                         
  B:C:E                                     1                             
  B:D:E                                 1                                 
  C:D:E                             1                                     
A:B:C:D                          1                                        
A:B:C:E                       1                                           
A:B:D:E                    1                                              
A:C:D:E                 1                                                 
B:C:D:E              1                                                    
\end{verbatim}

It is important to note that the main effects and two-factor
interactions are aliased with three- and four- factor interactions.
This is a very desirable type of design (but how did we generate it?).

What about a quick (for now) analysis of these data?
\begin{verbatim}
> attach(half.reactor, pos=1)
> mymod <- aov(Resp ~ (A+B+C+D+E) + B*D + D*E )
> anova(mymod)
Analysis of Variance Table

Response: Resp

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq  F Value     Pr(F) 
A          1     16.00   16.000   2.3594 0.1630778
B          1   1681.00 1681.000 247.8894 0.0000003
C          1      0.00    0.000   0.0000 1.0000000
D          1    600.25  600.250  88.5161 0.0000134
E          1    156.25  156.250  23.0415 0.0013553
B:D        1    462.25  462.250  68.1659 0.0000348
D:E        1    361.00  361.000  53.2350 0.0000842
Residuals  8     54.25    6.781                   
> 
\end{verbatim}

What would this have looked like with the full data???
\begin{verbatim}
> anova(mymod)
Analysis of Variance Table

Response: Resp

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq  F Value     Pr(F) 
A          1    15.125   15.125   1.3432 0.2578723
B          1  3042.000 3042.000 270.1499 0.0000000
C          1     3.125    3.125   0.2775 0.6031664
D          1   924.500  924.500  82.1018 0.0000000
E          1   312.500  312.500  27.7521 0.0000211
B:D        1  1404.500 1404.500 124.7290 0.0000000
D:E        1   968.000  968.000  85.9648 0.0000000
Residuals 24   270.250   11.260                   
\end{verbatim}

The answer is only slightly different!

\section*{Yet more design examples}
Hera are some more examples of designs, and
essentially an end to  our discussion of ANOVA.  Some of the calculations
I'll do (particularly figuring out alias patterns in S) take much more
computer power than they should.  

The material is copied from Chapter 13 of Box, Hunter, and Hunter,
{\em Statistics for Experimenters.\/}

\subsection*{Example 13.1}
Here we are asked to figure out what the alias pattern is.  My version
of this follows.  First we enter the data (this is by now a common
thing for us to do).  I added a Response because S seemed to want
that in the the subsequent calculations.
\begin{verbatim}
> rr
  V1 V2 V3 V4 V5 Resp 
1  0  0  0  1  0    1
2  1  0  0  1  1    2
3  0  1  0  0  1    3
4  1  1  0  0  0    4
5  0  0  1  0  1    5
6  1  0  1  0  0    6
7  0  1  1  1  0    7
8  1  1  1  1  1    8
\end{verbatim}
Then attach the dataset and ask for the alias pattern
\begin{verbatim}
> attach(rr)
> alias(Resp ~ (V1+V2+V3+V4+V5)^5 )
Model 
Resp ~ (V1 + V2 + V3 + V4 + V5)^5

Complete 
               (Intercept) V1 V2 V3 V4 V5 V1:V2 V1:V3 
         V1:V4                          1            
         V1:V5                       1               
         V2:V3                       1               
         V2:V4                    1                  
         V2:V5                                   1   
         V3:V4                 1                     
         V3:V5                             1         
         V4:V5              1                        
      V1:V2:V3                          1            
      V1:V2:V4                                   1   
      V1:V2:V5                    1                  
      V1:V3:V4                             1         
      V1:V3:V5                 1                     
      V1:V4:V5  1                                    
      V2:V3:V4  1                                    
      V2:V3:V5              1                        
      V2:V4:V5                             1         
      V3:V4:V5                                   1   
   V1:V2:V3:V4              1                        
   V1:V2:V3:V5  1                                    
   V1:V2:V4:V5                 1                     
   V1:V3:V4:V5                    1                  
   V2:V3:V4:V5                          1            
V1:V2:V3:V4:V5                       1               
\end{verbatim}

Lets follow through on this.  We have a $1/4$ fraction of the full
design so we expect (if the design was well done) that each estimable
effect will be aliased with three other effects.  The output tells us
that the estimable effects (the first row) are the main effects and a
couple of two-way interactions.  All the other two-way, three-way and
higher interactions are confounded/aliased with the estimable effects.
So, {\tt V1} is the same as {\tt V4:V5} {\tt V2:V3:V5} and 
{\tt V1:V2:V3:V4}.  This is a special kind of design, consructed with
considerable care.

\subsection*{Example 13.2}

It should be clear from the text that one can ``analyse'' these data
without much work, but some supporting calculations are as follows.
\begin{verbatim}
> e2
  V1 V2 V3 V4 Resp 
1  0  0  0  0   20
2  1  0  0  1   14
3  0  1  0  1   17
4  1  1  0  0   10
5  0  0  1  1   19
6  1  0  1  0   13
7  0  1  1  0   14
8  1  1  1  1   10
> anova(mymod <- aov(Resp ~ V1 + V2 + V3 + V4, data=e2))
Analysis of Variance Table

Response: Resp

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq  F Value     Pr(F) 
V1         1    66.125 66.12500 144.2727 0.0012415
V2         1    28.125 28.12500  61.3636 0.0043321
V3         1     3.125  3.12500   6.8182 0.0796050
V4         1     1.125  1.12500   2.4545 0.2151699
Residuals  3     1.375  0.45833                   
> anova(mymod <- aov(Resp ~ (V1 + V2 + V3 + V4)^2, data=e2))
Analysis of Variance Table

Response: Resp

Terms added sequentially (first to last)
      Df Sum of Sq Mean Sq 
V1     1    66.125  66.125
V2     1    28.125  28.125
V3     1     3.125   3.125
V4     1     1.125   1.125
V1:V2  1     0.125   0.125
V1:V3  1     1.125   1.125
V1:V4  1     0.125   0.125
\end{verbatim}

To treat it as a replicated design on just the first two variables,
the appropriate ANOVA is
\begin{verbatim}
> anova(mymod <- aov(Resp ~ V1 + V2, data=e2))              
Analysis of Variance Table

Response: Resp

Terms added sequentially (first to last)
          Df Sum of Sq Mean Sq  F Value       Pr(F) 
V1         1    66.125  66.125 58.77778 0.000601443
V2         1    28.125  28.125 25.00000 0.004104716
Residuals  5     5.625   1.125                     
\end{verbatim}

% Local Variables: 
% mode: latex
% TeX-master: t
% TeX-master: t
% End: 

