
% \documentclass[serif]{beamer} % Serif for Computer Modern math font.
\documentclass[serif, handout]{beamer} % Handout mode to ignore pause statements

\hypersetup{colorlinks,linkcolor=,urlcolor=red}

\usefonttheme{serif} % Looks like Computer Modern for non-math text -- nice!
\setbeamertemplate{navigation symbols}{} % Suppress navigation symbols
% \usetheme{Berlin} % Displays sections on top
\usetheme{Frankfurt}  % Displays section titles on top: Fairly thin but still swallows some material at bottom of crowded slides
%\usetheme{Berkeley}

\usepackage[english]{babel}
\usepackage{amsmath} % for binom
\usepackage{euscript} % for \EuScript
% \usepackage{graphicx} % To include pdf files!
% \definecolor{links}{HTML}{2A1B81}
% \definecolor{links}{red}
\setbeamertemplate{footline}[frame number] 

\mode<presentation>
% \mode<handout>{\setbeamercolor{background canvas}{bg=black!5}}

% Comment this out for handout
\title{Analysis of Fractional Factorial Designs\footnote{See last slide for copyright information.}}
\subtitle{STA442/2101 Fall 2018}
\date{} % To suppress date

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
  \titlepage
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Fractional Factorial Designs} \pause
%\framesubtitle{} 
  \begin{itemize}
    \item So far, we have considered only \emph{complete factorials}. \pause
    \item In a complete factorial, there are observations at all treatment combinations.
 \pause
    \item In a fractional factorial, some cells in the design are deliberately empty. \pause
    \item Why? Usually expense. 
  \end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Models for fractional factorial designs} \pause
%\framesubtitle{} 
  \begin{itemize}
    \item You can still fit a regression model if you are willing to make some assumptions.
 \pause
    \item Usually, assume one or more interactions are absent. \pause
    \item  It�s another example of the tradeoff between assumptions and amount of data. \pause 
    \item The more data you have, the less you have to assume.
  \end{itemize}
\end{frame}
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
\begin{frame}
\frametitle{The simplest example: Two by two} \pause
\framesubtitle{Omit the red cell} 
\begin{center}               
\begin{tabular}{l} ~ \\ A = Yes \\ A = No  \end{tabular}  % Left labels, kind of crude
\begin{tabular}{|c|c|c|}  
\multicolumn{1}{c}{B = Yes} & \multicolumn{1}{c}{B = No}  \\ \hline
 $\mu_{11}$ & $\mu_{12}$   \\ \hline
 $\mu_{21}$ & {\color{red} $\mu_{22}$ }   \\ \hline 
\end{tabular}\pause
\end{center}               
No interaction means the effect of $A$ is the same for both levels of $B$. \pause 
$\mu_{11}-\mu_{21} = \mu_{12}-\mu_{22} \pause  \Leftrightarrow 
{\color{red}\mu_{22}} = {\color{red}\mu_{12}-\mu_{11}+\mu_{21}}$ \pause

And the difference between marginal means for $A$ is \pause
\begin{eqnarray*}
    & & \frac{1}{2}(\mu_{11}+\mu_{12})-\frac{1}{2}(\mu_{21}+{\color{red}\mu_{22} }) \\ \pause
    &=& \frac{1}{2}\left(\rule{0mm}{4mm} \mu_{11}+\mu_{12}-\mu_{21}-({\color{red}\mu_{12}-\mu_{11}+\mu_{21}}) \right) \\ \pause
    &=& \frac{1}{2}\left(\rule{0mm}{4mm} \mu_{11}+\mu_{12}-\mu_{21}-\mu_{12}+\mu_{11}-\mu_{21} \right) \\ \pause
    &=& \frac{1}{2}\left(\rule{0mm}{4mm} 2\mu_{11}-2\mu_{21} \right) \\ \pause
    &=& \mu_{11}-\mu_{21}
\end{eqnarray*} 
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Extensions} \pause
%\framesubtitle{} 
  \begin{itemize}
    \item In a $2 \times 2 \times \cdots \times 2$ factorial, \pause You can sacrifice any cell you want in exchange for the highest-way interaction. \pause
    \item Chapter 6A in Cochran and Cox's \emph{Design of experiments} has a lot of rules that apply to balanced designs. \pause
    \item Here's another approach. 
  \end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{For larger designs} \pause
%\framesubtitle{} 
  \begin{itemize}
    \item All the standard tests are tests of whether contrasts or collections of contrasts equal zero. \pause
    \item You can sacrifice any contrast in exchange for a cell by \pause 
        \begin{itemize}
            \item Choosing one of the $\mu$ parameters involved in the contrast. \pause
            \item Solving for it. \pause
            \item Letting that cell be empty. \pause
        \end{itemize}
    \item You can do this for more than one contrast (and cell). \pause
    \item How do you know what contrasts to test for the remaining effects? \pause
    \item Substitute the solution(s) for the $\mu$ parameter(s). \pause
    \item Calculate the contrast you would usually test. \pause
    \item And simplify. \pause
    \item Just as in the $2 \times 2$ example. \pause
    \item The hardest part is knowing what contrasts correspond to an effect of interest for larger designs. \pause
    \item There is a systematic way to find out.
  \end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Effect coding} \pause
%\framesubtitle{} 
  \begin{itemize}
    \item Pick an interaction or set of interactions to sacrifice. \pause
    \item The number of potential empty cells equals the number of $\beta$s set to zero. \pause
    \item Each $\beta$ is zero if and only if a linear combination of the $\mu$ values is zero. \pause
    \item It's a matter of going back and forth between cell means coding and effect coding. \pause
    \item To get an explicit formula for the $\beta$ parameters of effect coding in terms of the $\mu$ parameters of cell means coding. 
  \end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Example: Crop yield study}
\framesubtitle{Three Fertilizers by Sprinkler versus Drip Irrigation} \pause
\begin{columns}  
\column{1.2\textwidth}
\begin{displaymath}
    E[Y|\mathbf{X}] = \beta_0 + \beta_1 f_1 +  \beta_2 f_2 + \beta_3 w + \beta_4 f_1w + \beta_5 f_2w
\end{displaymath} \pause
{ \scriptsize
\begin{center}
\begin{tabular}{|c|r|r|r|r|r|r|l|}  \hline
Fertilizer & Water      & $f_1$ & $f_2$ & $w$ & $f_1w$ & $f_2w$ &
$E[Y|\mathbf{X}]$ \\ \hline \hline
    1      &  Sprinkler &   1   &   0   &  1  &   1    &   0   &
$\mu_{11}=\beta_0+\beta_1+\beta_3+\beta_4$ \\ \hline
    1      &  Drip      &   1   &   0   & -1  &  -1    &   0    &
$\mu_{12}=\beta_0+\beta_1-\beta_3-\beta_4$ \\ \hline
    2      &  Sprinkler &   0   &   1   &  1  &   0    &   1    &
$\mu_{21}=\beta_0+\beta_2+\beta_3+\beta_5$ \\ \hline
    2      &  Drip      &   0   &   1   & -1  &   0    &  -1    &
$\mu_{22}=\beta_0+\beta_2-\beta_3-\beta_5$ \\ \hline
    3      &  Sprinkler &  -1   &  -1   &  1  &  -1    &  -1    &
$\mu_{31}=\beta_0-\beta_1-\beta_2+\beta_3-\beta_4-\beta_5$ \\ \hline
    3      &  Drip      &  -1   &  -1   & -1  &   1    &   1    &
$\mu_{32}=\beta_0-\beta_1-\beta_2-\beta_3+\beta_4+\beta_5$ \\ \hline
\end{tabular}
\end{center} \pause
\label{effcodingwork}  % Label must come after the table or numbering is wrong.
} % End size
  \begin{itemize}
    \item The $\mu_{ij}$ are linear combinations of the $\beta_j$. \pause
    \item And the coefficients are sitting right there in the table.
  \end{itemize}

\end{columns}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Matrix form}
%\framesubtitle{} 
\begin{displaymath}
\left( \begin{array}{rrrrrr}
1 &   1   &   0   &  1  &   1    &   0  \\
1 &   1   &   0   & -1  &  -1    &   0  \\
1 &   0   &   1   &  1  &   0    &   1  \\
1 &   0   &   1   & -1  &   0    &  -1  \\
1 &  -1   &  -1   &  1  &  -1    &  -1  \\
1 &  -1   &  -1   & -1  &   1    &   1  \\
\end{array} \right) 
\left( \begin{array}{c} \beta_0 \\ \beta_1 \\ \beta_2 \\ \beta_3 \\  
\beta_4  \\ \beta_5 \\ \beta_6 \end{array} \right) = 
\left( \begin{array}{c} \mu_{11} \\ \mu_{12} \\ \mu_{21} \\ \mu_{22} \\  
\mu_{31}  \\ \mu_{32} \end{array} \right)
\end{displaymath} \pause
\begin{eqnarray*}
    \mathbf{A}\boldsymbol{\beta} & = & \boldsymbol{\mu} \\ \pause
    \boldsymbol{\beta} & = & \mathbf{A}^{-1}\boldsymbol{\mu}
\end{eqnarray*} \pause
This is really nice because it shows the equivalence of the two dummy variable coding schemes.
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}[fragile]
\frametitle{Can even do most of the job with R} \pause
\framesubtitle{$\boldsymbol{\beta} = \mathbf{A}^{-1}\boldsymbol{\mu}$} 
{\scriptsize
\begin{verbatim}
> A = rbind(  c(1, 1, 0, 1, 1, 0), 
+             c(1, 1, 0,-1,-1, 0),
+             c(1, 0, 1, 1, 0, 1),
+             c(1, 0, 1,-1, 0,-1),
+             c(1,-1,-1, 1,-1,-1),
+             c(1,-1,-1,-1, 1, 1) )
> solve(A) # Inverse
           [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
[1,]  0.1666667  0.1666667  0.1666667  0.1666667  0.1666667  0.1666667
[2,]  0.3333333  0.3333333 -0.1666667 -0.1666667 -0.1666667 -0.1666667
[3,] -0.1666667 -0.1666667  0.3333333  0.3333333 -0.1666667 -0.1666667
[4,]  0.1666667 -0.1666667  0.1666667 -0.1666667  0.1666667 -0.1666667
[5,]  0.3333333 -0.3333333 -0.1666667  0.1666667 -0.1666667  0.1666667
[6,] -0.1666667  0.1666667  0.3333333 -0.3333333 -0.1666667  0.1666667
> 0.1666667 * 6
[1] 1
\end{verbatim} \pause
} % End size
{\footnotesize
  \begin{itemize}
    \item This identifies the linear combination of $\mu$s that correspond to each $\beta$. \pause
    \item Still have to solve for the cell mean you're omitting, and substitute. \pause
    \item But at least now we know what linear combinations to calculate.
  \end{itemize}
} % End size
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Which cells can we omit?}
\framesubtitle{And still be able to test the remaining effects}  \pause
  \begin{itemize}
    \item Try omitting one or more cells. \pause
    \item Solve for that $\mu$ in terms of the other $\mu$s. \pause
    \item Substitute the solution for the missing cell mean(s). \pause
    \item Set the contrast(s) you want the test to zero (get these from $\mathbf{A}^{-1}$) \pause
    \item Simplify. \pause
    \item If you get $0=0$, you've omitted the wrong cells. \pause
    \item Otherwise, you know what special hypotheses to test.
  \end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Copyright Information}

This slide show was prepared by  \href{http://www.utstat.toronto.edu/~brunner}{Jerry Brunner},
Department of Statistics, University of Toronto. It is licensed under a 
\href{http://creativecommons.org/licenses/by-sa/3.0/deed.en_US}
     {Creative Commons Attribution - ShareAlike 3.0 Unported License}. Use any part of it as you like and share the result freely. The \LaTeX~source code is available from the course website:
\href{http://www.utstat.toronto.edu/~brunner/oldclass/appliedf18} {\small\texttt{http://www.utstat.toronto.edu/$^\sim$brunner/oldclass/appliedf18}}

\end{frame}

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

A = rbind(  c(1, 1, 0, 1, 1, 0), 
            c(1, 1, 0,-1,-1, 0),
            c(1, 0, 1, 1, 0, 1),
            c(1, 0, 1,-1, 0,-1),
            c(1,-1,-1, 1,-1,-1),
            c(1,-1,-1,-1, 1, 1) )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{} \pause
%\framesubtitle{} 
  \begin{itemize}
    \item  \pause
    \item  \pause
    \item 
  \end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


{\LARGE
\begin{displaymath}
    
\end{displaymath} }

\begin{displaymath}
    \left(
    \begin{array}{ccc}
    \sum_{i=1}^n (x_{i1}-\overline{x}_1)^2 &
    \sum_{i=1}^n (x_{i1}-\overline{x}_1)(x_{i2}-\overline{x}_2) & 
    \sum_{i=1}^n (x_{i1}-\overline{x}_1)(x_{i3}-\overline{x}_3)\\
    \end{array}
    \right)
\end{displaymath} 


===============


===============


===============


===============



