```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(DoE.base)
library(doetools)
```

## Review

* A full factorial design with $k$ factors requires $2^k$ runs.

* A half factorial design uses only $2^{k-1}$ runs.
  * Begin with a base design.
  * Set the remaining factor equal to an interaction (generator, $E=AB$)
  * Compute the defining relation ($I = \ldots$) and confounding/alias structure.

\pause
* Half-fractional factorials in action
* Today we define quarter- or eighth-factorial designs!

## A large ($2^5$) unreplicated study

```{r}
tumor <- read.csv("TumorInhibition.csv")
head(tumor)
```

## Let's pretend it was a $2^{5-1}$ half-fractional

```{r}
half_tumor <- tumor[tumor$half==1, ]
half_tumor
```

## Step 2: Look at the data
```{r fig.width=5, fig.height=3}
farplot(half_tumor, response="inhibition", factors=c("A","B","C","D","E"))
```

## Step 3: Fit a linear model

```{r echo=FALSE}
model <- lm(inhibition ~ A*B*C*D*E, data=tumor)
```

```{r}
half_model <- lm(inhibition ~ A*B*C*D*E, data=half_tumor)
```

::: columns
:::: column
```{r}
show_effects(half_model, scaling=2, intercept=FALSE, order="abs", n=18)
```
::::

:::: column
```{r}
show_effects(model, scaling=2, intercept=FALSE, order="abs", n=18)
```
::::
:::

## Visualizing with half-normal plots

```{r results=FALSE, fig.width=5, fig.height=2.75}
daewr::halfnorm(na.omit(get_effects(half_model)))
daewr::halfnorm(get_effects(model))
```

## Quarter factorial ($2^{k-2}$) designs

Let's create a $2^{5-2}$ design (8 runs, factors $ABCDE$).

\pause
Start with a base $2^3$ design (factors $ABC$).

\pause
Define $D=AB$ and $E=AC$.
\[ D^2 = I = ABD,\quad		E^2 = I = ACE \]

\pause
Also, $I^2 = I = (ABD)(ACE) = BCDE$.

\pause
**Defining relation:** $I = ABD = ACE = BCDE$

## Confounding in our $2^{5-2}$ design

**Defining relation:** $I = ABD = ACE = BCDE$
\[ A(I) = A(ABD) = A(ACE) = A(BCDE) \]
\pause
\[ A + BD + CE + ABCDE \]
\pause
\[ B + AD + ABCE + CDE \]
\[ C + ABCD + AE + BDE \]
\[ D + AB + ACDE + BCE \]
\[ E + ABDE + AC + BCD \]
\pause
\[ BC + ACD + ABE + DE \]
\[ BE + ADE + ABC + CD \]

## Eighth fractional design: $2^{6-3}$

Factors $A$, $B$, $C$, $D=AB$, $E=AC$, $F=BC$
\pause
\[ I = ABD = ACE = BCF \]
\pause
Also, all combinations:
\begin{align*}
  I^2 &= I = (ABD)(ACE) = BCDE \\
  I^2 &= I = (ABD)(BCF) = ACDF \\
  I^2 &= I = (ACE)(BCF) = ABEF \\
  I^3 &= I = (ABD)(ACE)(BCF) = DEF
\end{align*}

**Defining relation:**
\[ I = ABD = ACE = BCF = BCDE = ACDF = ABEF = DEF \]

## Which generator should I choose?

A generator’s optimality is assessed with three criteria:

* **Resolution:** difference in the level of confounding.

* **Aberration:** the multiplicity of the worst confounding.

* **Clarity:** # of confounded main effects or two-way interactions.

## Criterion #1: Design Resolution

The resolution of a fractional design is the length of the shortest word in the defining relation.


\newcommand\iii{\ensuremath{\mathrm{III}}}
\newcommand\iv{\ensuremath{\mathrm{IV}}}

For the $2^{5-2}$ design generated by D=AB and E=AC, the definig relation is	
\[ I = ABD = ACE = BCDE \]
This is a Resolution \iii\ design. (Resolution is written with Roman numerals.)

## Resolution measures the degree of confounding

A resolution $R$ design has no $i$-level interaction aliased with effects lower than $R-i$.

\pause
Resolution \iii\

* Main effects ($i=1$) are confounded with secondary ($3-1 = 2$) interactions.

\pause
Resolution \iv\

* Main effects ($i=1$) are confounded with tertiary ($4-1 = 3$) interactions.

* TWIs ($i=2$) are confounded with other TWIs ($4-2 = 2$).

## Resolution and nested factorial designs

A design with resolution $R$ contains a full factorial design for  any subset of $k = R-1$ factors.

\pause
\medskip
If after the fractional experiments you drop to $k$ factors you can re-analyze the data for all the interactions.

## Criterion #2: Design Aberration

* **Resolution:** Length of the shortest word in the defining relation.

* **Aberration:** Number of words with length equal to the resolution.

\pause
\medskip
\begin{center}
$I = ABCDF = ABCEG = DEFG\quad$	resolution \iv, aberration 1

$I = ABCF = ADEG = BCDEFG\quad$	resolution \iv, aberration 2
\end{center}

\pause
\medskip
We favor the design with the lower aberration. It will have fewer main effects confounded with low-order interactions.

## Criterion #3: Clear Effects

A main effect or two-way interaction effect is **clear** if it is only confounded with higher order terms (three-way or higher).

\pause
\medskip
Clear effects always lead to tradeoffs. For a $2^{6-2}$ design:
\begin{align*}
  I &= ABCE = ABDF = CDEF &\quad	\text{6 main effects clear} \\
  I &= ABE = ACDF = BCDEF &\quad 	\text{3 main effects $+$ 6 TWIs clear} 
\end{align*}

## Overall design guidelines

1. Choose the highest **resolution** that fits your budget.
2. For that resolution, choose the **minimum aberration** design.
3. If you have particular effects that you know are signficant, try to choose a factor or generator that clears them.
