-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05-blocking_factorial.Rmd
471 lines (352 loc) · 28.8 KB
/
05-blocking_factorial.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# Blocking in factorial designs {#block-factorial}
We now consider splitting the treatments in a factorial design into blocks. As in Chapter \@ref(blocking), the simplest factorial blocked design is a **randomised complete block design**, where the blocks are large enough for a complete replicate of the factorial treatments to occur in each block. Analysis then proceeds as in Chapter \@ref(blocking), with the contrasts of interest being those corresponding to the factorial effects (main effects and interactions).
However, the number of treatments grows rapidly in a factorial design, and it is unusual for the block sizes to be sufficiently large to accomodate a complete replication within each block. Hence, **incomplete block designs** must be employed. While balanced incomplete block designs (Section \@ref(sec-bibd)) can be used, they do not tend to have good statistical properties and their construction is complicated. In this chapter, we will focus on a class of methods specific to splitting a two-level factorial design in to blocks who common size $k$ is a power of two.
## Two examples
We will use two simple examples to illustrate this approach, based on a $2^3$ experiment with factors labelled $A$, $B$ and $C$ (Table \@ref(tab:example-factorial)).
```{r example-factorial, message = F}
example.design <- FrF2::FrF2(nruns = 8, nfactors = 3, randomize = F)
knitr::kable(example.design, caption = "Treatments from a $2^3$ factorial design", align = rep("r", 3))
```
:::{.example #block-frac-1}
Consider splitting the treatments between two blocks of size $2^{3-1}=4$. One choice is given in Table \@ref(tab:block-frac-1).
```{r block-frac-1}
block1 <- c(1, 2, 2, 1, 2, 1, 1, 2)
example.design.a <- cbind(example.design, Block = block1)
knitr::kable(example.design.a, caption = "Treatments from a $2^3$ factorial design split into two blocks of size four.", align = rep("r", 4))
```
To assess the impact of this choice of blocking scheme on the analysis of the experiment, we need to consider the (unscaled) contrasts corresponding to all the factorial effects, see Table \@ref(tab:block-frac-1-mm).
```{r block-frac-1-mm}
X <- model.matrix( ~ Block + (A + B + C)^3, data = example.design.a)
Xdf <- data.frame(X[, -1])
colnames(Xdf) <- c("Block", "A", "B", "C", "A:B", "A:C", "B:C", "A:B:C")
Xdf <- dplyr::mutate(Xdf, Treatment = 1:8, .before = Block)
knitr::kable(Xdf, caption = "Unscaled factorial effect contrasts for a $2^3$ design with one possible assignment of treatments to blocks")
```
Each contrast vector in Table \@ref(tab:block-frac-1-mm) is orthogonal, in the sense of -1 and +1 occuring equally often (twice) in each block, except for the contrast vector for the three-factor interaction. This vector has all -1 entries occuring in block 1, and all +1 entries occuring in block 2.
The difference in average response between blocks 1 and 2 in this design is estimated by
$$
\widehat{\beta_1 - \beta_2} = \frac{1}{4}\left\{(y_{11} + y_{14} + y_{16}+ y_{17}) - (y_{22} + y_{23} + y_{25} + y_{28})\right\}\,,
$$
where $\beta_i$ is the effect of the $i$th block in unit-block-treatment model \@ref(eq:block-model) and $y_{ij}$ is the response from applying treatment $j$ to a unit in block $i$ ($i = 1, 2;\, j = 1, \ldots, 8$).
This contrast is **exactly** the same as the contrast for estimating the three-factor interaction.
$$
\mathrm{Int}(A, B, C) = \frac{1}{4}\left\{(y_{11} + y_{14} + y_{16}+ y_{17}) - (y_{22} + y_{23} + y_{25} + y_{28})\right\}\,.
$$
Hence this choice of blocking makes it impossible for us to estimate this interaction. If the contrast is large, we would anticipate it was because there is a large difference in average response between blocks, not because of the three-factor interaction.
So why choose this particular blocking? Well, it is impossible to split this set of treatments into incomplete blocks (with $k<8$) and not lose some information about the factorial effects.
1. From effect hierarchy, the three-factor interaction is the least likely factorial effect to be important, and hence this is the interaction we care least about losing information about. Choosing any of the other factorial effects to determine the blocking would be a worst choice^[In the absence of any prior information telling us that certain effects are of particular interest, we always favour losing information on higher order effects.]
2. What about if we don't use a column of Table \@ref(tab:block-frac-1-mm) to assign treatments to blocks? We now longer lose all information about a particular factorial effect, but instead we lose some information about many, or even all, factorial effects.
We can study this information lose by assessing all ${8 \choose 4}! = `r choose(8, 4)`$ possible assignments of treatments to blocks. For each, we will calculate the average variance of the main effect and two-factor interaction contrasts (up to a constant $\sigma^2$).
```{r block-assignment, message = F, warning = F}
no.assign <- choose(8, 4)
assignments <- combinat::combn(8, 4)
yfake <- rnorm(8)
Xadf <- cbind(Xdf[, c(-1, -9)], y = yfake)
avgvar <- NULL
for(i in 1:no.assign) {
B <- rep(1, 8)
B[assignments[, i]] <- -1
Xadf$Block <- B
temp.lm <- lm(y ~ Block + (A + B + C)^2, data = Xadf)
temp.lm$residuals <- yfake
temp.lm$df.residual <- 8
vmat <- vcov(temp.lm) / (summary(temp.lm)$sigma^2)
vars <- (diag(vmat[-c(1:2), -c(1:2)]))
tidyr::replace_na(vars, Inf)
avgvar[i] <- sum(tidyr::replace_na(vars, Inf)) / 6
}
knitr::kable(table(avgvar), col.names = c("Avg. variance", "Freq."))
```
From our study, we see that there are two allocations of treatments to blocks that give us the smallest average variance of $0.125\sigma^2$. These two allocations are those that use the three-factor interaction column to assign treatments to blocks. For 32 other allocations, the average variance $0.188\sigma^2$, and hence an efficiency of $`r 0.125/0.188`$ compared to the first two allocations. There are also 36 allocations that have infinite average variance; these allocations use one of the six main effect or two-factor interaction columns to assign treatments to blocks. For any of these choices, the corresponding factorial effect cannot be estimated, equivalent to the estimator having infinite variance.
We now compare our original design to one of the 32 allocations with average variance $0.188\sigma^2$ (chosen arbitrarily).
```{r partial-confounding}
Xa <- as.matrix(Xdf[, -c(1)])
Xb <- Xa
B <- rep(1, 8)
B[assignments[, 2]] <- -1
Xb[,1] <- B
```
```{r cor-optimal}
knitr::kable(cor(Xa), caption = "Scaled inner-products between contrast vectors for $2^3$ with treatments assigned to blocks so $\\mathrm{Blocks} = ABC$.")
```
```{r cor-partial}
knitr::kable(cor(Xb), caption = "Scaled inner-products between contrast vectors for $2^3$ with treatments assigned to blocks arbitrarily.")
```
From Table \@ref(tab:cor-optimal), we can see that the block contrast is orthogonal to (has zero inner product with) all the main effect and two-factor interaction contrasts. In comparison, the design with arbitrary treatment assignment has non-zero inner products between blocks and the main effect contrasts (Table \@ref(tab:cor-partial)). However, this design does allow estimation of the three-factor interaction (although it too has non-zero inner-product with the block contrast).^[Also, simultaneous estimation of the intercept, blocking effect and all 8 factorial effects is not possible, as there are insufficient degrees of freedom. In fact, the rank of the combined treatment and block model matrices for the unit-block-treatment model (\@ref(eq:block-plm)) is t+b-3.]
Clearly, if interest is in estimation of the main effects and two-factor interactions, it is best to use the design which assigns treatments to blocks via the three-factor interaction contrast coefficients.
:::
::: {.definition #confounding}
A factorial effect is said to be **confounded** with blocks if the same contrast in the observations estimates both the factorial effect and a difference between blocks.
:::
In Example \@ref(exm:block-frac-1), the three-factor interaction $ABC$ is confounded with blocks. We write $\mathrm{Blocks} = ABC$ as a shorthand to represent this confounding.
::: {.example #block-frac-2}
Now consider splitting the treatments between four blocks of size $2^{3-2}=2$. One choice is given in Table \@ref(tab:block-frac-2).
```{r block-frac-2}
block2 <- c(4, 3, 2, 1, 1, 2, 3, 4)
example.design.b <- cbind(example.design, Block = block2)
knitr::kable(example.design.b, caption = "Treatments from a $2^3$ factorial design split into four blocks of size two.", align = rep("r", 4))
```
Clearly, we cannot use a single factorial contrast (taking only two values) to divide treatments between four blocks. The obvious extension to the approach from Example \@ref(exm:block-frac-1) is to use the combination of two columns. Here, we have used the contrasts for the $AB$ and $AC$ interactions.
```{r block-frac-2-mm}
X <- model.matrix( ~ Block + (A + B + C)^3, data = example.design.b)
Xdf <- data.frame(X[, -1])
colnames(Xdf) <- c("Block", "A", "B", "C", "A:B", "A:C", "B:C", "A:B:C")
Xdf <- dplyr::mutate(Xdf, Treatment = 1:8, .before = Block)
knitr::kable(Xdf, caption = "Unscaled factorial effect contrasts for a $2^3$ design with one possible assignment of treatments to four blocks of size two.")
```
In Table \@ref(tab:block-frac-2-mm) we can see that the contrasts for $AB$ and $AC$ are confounded with blocks (the contrast coefficients are constant within each blocks).
- Block 1 contains treatments 4 and 5, which have $AB = +1$ and $AC = -1$.
- Block 2 contains treatments 3 and 6, which have $AB = -1$ and $AC = +1$.
- Block 3 contains treatments 2 and 7, whicn have $AB = AC = -1$.
- Block 4 contains treatments 1 and 8, which have $AB = AC = +1$.
However, by confounding interactions $AB$ and $AC$ we have also confounded the elementwise (Hadamard) product of these two interactions:
$$
AB \odot AC = A \odot B \odot A \odot C = B \odot C = BC\,.
$$
If the contrast vectors for $AB$ and $AC$ are constant, the contrast vector for interaction $BC$ must also be constant. Hence, interaction $BC$ is also confounded with blocks.
We write this confounding as
$$
\mathrm{Block}_1 = AB\,,\quad \mathrm{Block}_2 = AC\,,\quad \mathrm{Block}_3 = \mathrm{Block}_1\times\mathrm{Block}_2 = BC\,.
$$
Clearly, alternative blocking schemes are possible. However, we must be careful not to inadvertently confound low-order factorial effects. For example, if we chose to confound the three-factor interaction $ABC$ with blocks, along with one two-factor interaction, say $BC$, then we also confound
$$
ABC \odot BC = A \odot B \odot C \odot B \odot C = A\,.
$$
Hence, the main effect of factor $A$ is also confounded with blocks. This is clearly undesirable, e.g. by effect hierarchy.
We shouldn't be surprised that a third factorial effect was confounded with blocks. In the unit-block-treatment model \@ref(eq:block-plm), the rank of the block model matrix $X_1$ is equal to 3, and hence there will be three degrees of freedom required to estimate the blocking effects.
As in Example \@ref(exm:block-frac-1), we could also explore alternative blocking schemes that do not completely confound factorial effects with blocks. However, as before, these alternatives would lead to higher average variance for the estimation of main effects compared to the design that confounds the three two-factor interactions.^[This design is too small to split into four blocks and still be able to estimate all two-factor interactions clear of blocks.]
:::
::: {.definition #block-clear-effects}
In a blocked factorial design, those effects which are not confounded with blocks are called **clear**.
:::
In Example \@ref(exm:block-frac-1), the clear effects are $A$, $B$, $C$, $AB$, $AC$ and $BC$. In Example \@ref(exm:block-frac-2), the clear effects are $A$, $B$, $C$ and $ABC$.
## General method of constructing a confounded block design
To arrange a $2^{f}$ design in $b=2^{q}$ blocks of size $k=2^{f-q}$:
- choose $q$ independent factorial contrasts for the **defining blocks**. Typically, we choose higher-order interactions (due to effect hierarchy):
$$
\mathrm{Block}_{1}=\boldsymbol{c}_{1},\ldots,\mathrm{Block}_{q} = \boldsymbol{c}_{q}\,.
$$
- all the hadamard products of $\boldsymbol{c}_{1},\dots,\boldsymbol{c}_{q}$ are also confounded with blocks:
$$
\begin{array}{ccc}
\mathrm{Block}_{1}\mathrm{Block}_{2}&=&\boldsymbol{c}_{1}\odot\boldsymbol{c}_{2} \\
\mathrm{Block}_{1}\mathrm{Block}_{3}&=&\boldsymbol{c}_{1}\odot\boldsymbol{c}_{3} \\
\vdots&=&\vdots\\
\mathrm{Block}_{1}\mathrm{Block}_{2}\dots \mathrm{Block}_{q}&=&\boldsymbol{c}_{1}\odot\boldsymbol{c}_{2}\odot\dots\odot \boldsymbol{c}_{q}\
\end{array}
$$
- in total, $2^q -1$ factorial effects will be confounded with blocks.
For example, a $2^{8}$ design in $b = 2^{3}=8$ blocks of size $k = 2^{8-3}=2^{5}=32$. We choose the following $q=3$ defining blocks:
$$
\mathrm{Block}_{1}=ACEGH\,,\quad \mathrm{Block}_{2}=BCFGH\,,\quad \mathrm{Block}_{3}= BDEGH\,.
$$
We obtain the other confounded effects by hadamard multiplication:
\begin{eqnarray}
\mathrm{Block}_{1}\odot \mathrm{Block}_{2} & = & ABEF \nonumber\\
\mathrm{Block}_{1}\odot \mathrm{Block}_{3} & = & ABCD \nonumber\\
\mathrm{Block}_{2}\odot \mathrm{Block}_{3} & = & CDEF \nonumber\\
\mathrm{Block}_{1}\odot \mathrm{Block}_{2} \odot \mathrm{Block}_{3} & = & ADFGH\,. \nonumber
\end{eqnarray}
It is also straightforward to find blocked fractional factorial designs using `FrF2` in `R`. For example, to find the two $2^3$ designs at the start of this chapter, with blocks of size $k=4$ and $k=2$, we simply set the `blocks` argument equal to the number of blocks $b$, see Tables \@ref(tab:frf2-block-1) and \@ref(tab:frf2-block-2)^[The additional `R` code is to tidy up the output.].
```{r frf2-block-1}
block1.frf2 <- FrF2::FrF2(nruns = 8, nfactors = 3, blocks = 2,
alias.info = 3, randomize = F)
block1 <- data.frame(model.matrix(~ Blocks + (A + B + C)^3, block1.frf2))
block1 <- dplyr::mutate(block1, Treatment = 1:8, .before = Blocks1)
knitr::kable(block1[, -1], col.names = c("Treatment", "Block", "A", "B", "C",
"A:B", "A:C", "B:C", "A:B:C"),
caption = "$2^3$ factorial design in two blocks of size four")
```
```{r frf2-block-2}
block2.frf2 <- FrF2::FrF2(nruns = 8, nfactors = 3, blocks = 4,
alias.info = 3, randomize = F, alias.block.2fis = T)
block2 <- data.frame(model.matrix(~ Blocks + (A + B + C)^3, block2.frf2))
block2 <- dplyr::mutate(block2, Treatment = 1:8, .before = Blocks1)
knitr::kable(block2[, -1],
col.names = c("Treatment", "Block1", "Block2", "Block3",
"A", "B", "C",
"A:B", "A:C", "B:C", "A:B:C"),
caption = "$2^3$ factorial design in four blocks of size two")
```
In each case, `FrF2` returns for us the design, in coded $\pm 1$ units (or the unscaled factorial constrast coefficients), including columns giving the contrast coefficients for estimating the block effects. The function automatically tries to find the best allocation of treatments to blocks, in terms of maximising the number of lower-order factorial effects which are clear of blocks. In the second example, we set `alias.block.2fis = T` to allow `FrF2` to confound two-factor interactions with blocks, otherwise a solution could not be found.
Setting `alias.info = 3` ensures `FrF2` returns information about confounding between blocks and three-factor interactions^[By default, `FrF2` only returns information about confounding involving two-factor interactions. Unfortunately, it is not possible to get `FrF2` to return information about confounding involving four-factor or higher interactions.] We extract this information using `design.info`^[We previously have not explicitly loaded packages before. However, `design.info` is actually extracting *attributes* of the `FrF2` object, and I couldn't find a way to make this work without loading the package!].
```{r FrF2-info, message = F}
library(FrF2)
design.info(block1.frf2)$aliased.with.blocks
design.info(block2.frf2)$aliased.with.blocks
```
We can also specify which factorial effects we wish to confound with blocks, rather than letting `FrF2` choose. For the $2^8$ example above, we can specify the three defining blocks
$$
\mathrm{Block}_{1}=ACEGH\,,\quad \mathrm{Block}_{2}=BCFGH\,,\quad \mathrm{Block}_{3}= BDEGH\,,
$$
the `blocks` argument
```{r FrF2-choose-confounding}
block3.frf2 <- FrF2::FrF2(nruns = 2^8, nfactors = 8,
alias.info = 3, randomize = F, blocks = c("ACEGH", "BCFGH", "BDEGH"))
```
## Analysis of a confounded factorial design
We can analyse a confounded design by by combining ideas from Chapters \@ref(blocking) and \@ref(factorial). The most straightforward approach is to add a block effect to the regression model introduced in Section \@ref(fac-reg). Let $X$ be the $n\times d$ model matrix with columns corresponding to the $d = 2^f - b$ unscaled contrast coefficients for the estimable factorial effects (i.e. those **not** confounded with blocks). As no factorial effects that have been confounded with blocks are estimable, the $X$ matrix cannot include columns corresponding to these effects. We write a block-regression model as
$$
\bY = \boldsymbol{1}_n\beta_0 + X\boldsymbol{\beta} + Z\boldsymbol{\gamma} + \boldsymbol{\varepsilon}\,,
$$
where in a (necessary) change of notation, $Z$ is the $n \times b$ model matrix for blocks (previously referred to as $X_1$) and $\boldsymbol{\gamma} = (\gamma_1,\ldots, \gamma_b)^{\mathrm{T}}$ is the vector of block effects (previously called $\boldsymbol{\beta}$). The errors remain independent and identically normally distributed with constant variance. Recall that for equal block sizes
$$
Z = \bigoplus_{i = 1}^b \boldsymbol{1}_{k} = \begin{bmatrix}
\boldsymbol{1}_{k} & \boldsymbol{0}_{k} & \cdots & \boldsymbol{0}_{k} \\
\boldsymbol{0}_{k} & \boldsymbol{1}_{k} & \cdots & \boldsymbol{0}_{k} \\
\vdots & & \ddots & \vdots \\
\boldsymbol{0}_{k} & \boldsymbol{0}_{k} & \cdots & \boldsymbol{1}_{k} \\
\end{bmatrix}\,.
$$
The normal equations take the form
\begin{align}
n\hat{\beta}_0 + \boldsymbol{1}_n^{\mathrm{T}}X\hat{\boldsymbol{\beta}} + \boldsymbol{1}_n^{\mathrm{T}}Z\hat{\boldsymbol{\gamma}} & = \boldsymbol{1}_n^{\mathrm{T}}\bY\,, (\#eq:fact-blocks-normal-1)\\
X^{\mathrm{T}}\boldsymbol{1}_n\hat{\beta}_0 + X^{\mathrm{T}}X\hat{\boldsymbol{\beta}} + X^{\mathrm{T}}Z\hat{\boldsymbol{\gamma}} & = X^{\mathrm{T}}\bY\,, (\#eq:fact-blocks-normal-2)\\
Z^{\mathrm{T}}\boldsymbol{1}_n\hat{\beta_0} + Z^{\mathrm{T}}X\hat{\boldsymbol{\beta}} + Z^{\mathrm{T}}Z\hat{\boldsymbol{\tau}} & = Z^{\mathrm{T}}\bY\,. (\#eq:fact-blocks-normal-3)\\
\end{align}
However, we have that $X^{\mathrm{T}}\boldsymbol{1}_n = \boldsymbol{0}_{d}$, as all factorial contrasts are orthogonal to the constant vector. Also, $X^{\mathrm{T}}Z = \boldsymbol{0}_{d\times b}$, as each factorial contrasts takes values -1 and +1 an equal number of times in each block. Also, $X^{\mathrm{T}}X = nI_{d}$, as all the vectors of factorial contrast coefficients are orthogonal. Hence, the regression coefficients $\boldsymbol{\beta}$ can be estimated independently of the intercept and block effects, with reduced normal equations
$$
n\hat{\boldsymbol{\beta}} = X^{\mathrm{T}}\bY\,.
$$
Obviously, there is a unique solution for $\hat{\boldsymbol{\beta}}$,
$$
\hat{\boldsymbol{\beta}} = \frac{1}{n}X^{\mathrm{T}}\bY\,,
$$
with estimators of the factorial effects having the form $2\hat{\boldsymbol{\beta}}$ (see Section \@ref(fac-reg)).
For a simulated response in Example \@ref(exm:block-frac-2), we can perform this analysis in `R` using `lm`.
```{r confounded-analysis, message = F, warning = F}
ex2.df <- dplyr::mutate_at(Xdf,c("Block"), factor)
X <- model.matrix(~ Block + (A + B + C)^3, ex2.df)
coef.values <- c(0, 2, 6, 12, 4, 0, 3, 0, 2, 0, 0)
y <- X %*% coef.values + rnorm(8, 0, 1)
betahat <- t(X[, c(5, 6, 7, 11)]) %*% y / nrow(X)
betahat # coef estimates, obtained directly
ex2.df <- data.frame(ex2.df, y = y)
ex2.lm <- lm(y ~ Block + A + B + C + A:B:C, data = ex2.df)
anova(ex2.lm)
coef(ex2.lm)[5:8] # coef estimates
2 * coef(ex2.lm)[5:8] # factorial effects
```
As the two-factor interactions are confounded with blocks, we can get an equivalent analysis by including these factorial effects but excluding blocks.
```{r fact-lm2, warning = F}
ex2.lm2 <- lm(y ~ (A + B + C)^3, data = ex2.df)
anova(ex2.lm2)
coef(ex2.lm2)
```
But we must keep in mind that the degrees of freedom and coefficient estimates for the two-factor interactions are actually associated with blocks.
## Exercises
1. Suppose that a single replicate $2^5$ factorial experiment is to be arranged in $b=4$ blocks, each containing $k=8$ treatments.
How many interactions need to be confounded with blocks in this experiment? Can these be chosen independently? Select suitable interactions which could be confounded with blocks and write down the treatments in one block corresponding to your choice.
<details>
<summary><b>Solution</b></summary>
To run a $2^5$ experiment in $b=4$ blocks requires $b-1=3$ interactions to be confounded and these cannot be chosen independently; the choice of two determines the third.
Confounding the interactions $ABCD$, $CDE$ and their product $ABE$ may be a sensible choice, as no main effects or two-factor interactions are then confounded with blocks. (Other choices are acceptable).
To find a block for this choice, we can solve the equations
$ABCD$ = 1, $CDE$ = -1
which gives the treatments
| A | B | C | D | E |
| -: | -: | -: | -: | -: |
| -1 | -1 | -1 | -1 | -1 |
| 1 | 1 | -1 | -1 | -1 |
| -1 | -1 | 1 | 1 | -1 |
| 1 | 1 | 1 | 1 | -1 |
| 1 | -1 | 1 | -1 | 1 |
| -1 | 1 | 1 | -1 | 1 |
| 1 | -1 | -1 | 1 | 1 |
| -1 | 1 | -1 | 1 | 1 |
This same block can be found using `FrF2`.
```{r block-ex1}
block.2.5 <- FrF2::FrF2(nruns = 2^5, nfactors = 5, blocks = c("ABCD", "CDE"))
subset(block.2.5, Blocks == 3)
```
</details>
2. Suppose a $2^7$ design is arranged in $b=8$ blocks with the defining blocks $\mathrm{Block}_1 = ABC$, $\mathrm{Block}_2 = DEF$ and $\mathrm{Block}_3 = AFG$.
a. Find all the interactions that are confounded with blocks.
b. An alternative blocking scheme has $\mathrm{Block}_1 = ABCD$, $\mathrm{Block}_2 = ABEF$ and $\mathrm{Block}_3 = ACEG$. Find all the confounded interactions in this design, and compare with the original blocking scheme.
<details>
<summary><b>Solution</b></summary>
a. $\mathrm{Block}_1 = ABC$, $\mathrm{Block}_2 = DEF$, $\mathrm{Block}_1\mathrm{Block}_2 = ABCDEF$, $\mathrm{Block}_3 = AFG$, $\mathrm{Block}_1\mathrm{Block}_3 = BCFG$, $\mathrm{Block}_2\mathrm{Block}_3 = ADEG$, $\mathrm{Block}_1\mathrm{Block}_2\mathrm{Block}_3 = BCDEG$.
b. For the alternative blocking scheme, $\mathrm{Block}_1 = ABCD$, $\mathrm{Block}_2 = ABEF$, $\mathrm{Block}_1\mathrm{Block}_2 = CDEF$, $\mathrm{Block}_3 = ACEG$, $\mathrm{Block}_1\mathrm{Block}_3 = BDEG$, $\mathrm{Block}_2\mathrm{Block}_3 = BCFG$, $\mathrm{Block}_1\mathrm{Block}_2\mathrm{Block}_3 = ADFG$.
The second scheme does not confound any three-factor interactions with blocks, unlike the original scheme.
</details>
3. Suppose that the $2^3$ design
| Run | A | B | C | AB | AC | BC | ABC |
| --: | -: | -: | -: | -: | -: | -: | --: |
| 1 | -1 | -1 | -1 | +1 | +1 | +1 | -1 |
| 2 | -1 | -1 | +1 | +1 | -1 | -1 | +1 |
| 3 | -1 | +1 | -1 | -1 | +1 | -1 | +1 |
| 4 | -1 | +1 | +1 | -1 | -1 | +1 | -1 |
| 5 | +1 | -1 | -1 | -1 | -1 | +1 | +1 |
| 6 | +1 | -1 | +1 | -1 | +1 | -1 | -1 |
| 7 | +1 | +1 | -1 | +1 | -1 | -1 | -1 |
| 8 | +1 | +1 | +1 | +1 | +1 | +1 | +1 |
is arranged in two blocks with runs 1, 2, 5 and 7 in block 1 and runs 3, 4, 6 and 8 in block 2.
a. Show that a contrast vector defining the difference between the two blocks is not identical to any of the seven contrast vectors in the table and, therefore, it is not confounded with any of the factorial effects.
b. Show that the block effect is not orthogonal to some of the factorial effects. Identify these effects. Discuss why it is undesirable to use this blocking scheme.
<details><summary><b>Solution</b></summary>
a. A unscaled contrast vector (with coefficients -1/+1) has been added to the table below. It is clearly not identical to any of the other columns, and hence no factorial effects have been completely confounded with blocks.
| Run | A | B | C | AB | AC | BC | ABC | Block |
| --: | -: | -: | -: | -: | -: | -: | --: | ----: |
| 1 | -1 | -1 | -1 | +1 | +1 | +1 | -1 | -1 |
| 2 | -1 | -1 | +1 | +1 | -1 | -1 | +1 | -1 |
| 3 | -1 | +1 | -1 | -1 | +1 | -1 | +1 | +1 |
| 4 | -1 | +1 | +1 | -1 | -1 | +1 | -1 | +1 |
| 5 | +1 | -1 | -1 | -1 | -1 | +1 | +1 | -1 |
| 6 | +1 | -1 | +1 | -1 | +1 | -1 | -1 | +1 |
| 7 | +1 | +1 | -1 | +1 | -1 | -1 | -1 | -1 |
| 8 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 |
b. The inner products of each effect column with the blocking column are given by
| A | B | C | AB | AC | BC | ABC |
| -: | -: | -: | -: | -: | -: | --: |
| 0 | +4 | +4 | -4 | +4 | 0 | 0 |
The blocking effect is not orthogonal to the main effects of $B$ or $C$ or the interactions $AB$ and $AC$. Two of the main effects are *partially* confounded with the blocking effect, and the variances of the estimators of these effects will inflated. Therefore, this scheme is not desirable. In general, we may prefer to completely confound a smaller number of higher-order factorial effects with blocks, in order to have greater clarity in our design and to not lose information about main effects.
</details>
4. In the Chapter \@ref(factorial) exercises we studied the reactor experiment, a $2^5$ full factorial experiment with the following data:
```{r reactor-data-2, message = F}
reactor.frf2 <- FrF2::FrF2(nruns = 32, nfactors = 5, randomize = F,
factor.names = c("FR", "Cat", "AR", "Temp", "Conc"))
y <- 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)
reactor <- data.frame(reactor.frf2, pre.react = y)
knitr::kable(reactor, caption = "Reactor experiment.")
```
Assume now that this experiment was performed in $b=4$ blocks, confounding the interactions between `FR`, `Cat` and `AR` and between `FR`, `Temp` and `Conc`. Obtain the anova table for this new experiment, and estimate the interactions that are not confounded with blocks. Use Lenth's method to decide which effects are important.
<details><summary><b>Solution</b></summary>
For ease of notation, we will label the factors
| Factor | Label |
| -----: | ----: |
| `FR` | A |
| `Cat` | B |
| `AR` | C |
| `Temp` | D |
| `Conc` | E |
The design has defining blocks $\mathrm{Block}_1 = ABC$ and $\mathrm{Block}_2 = ADE$, and hence also confounds $\mathrm{Block}_1\mathrm{Block}_2 = BCDE$. We can assign treatments to blocks according to the four combinations of any pair of these interactions. In the code chunk below, we use the pipe operator (`|>`) to combine our data processing steps.
```{r block-assign}
fac_to_numeric <- function(x) as.numeric(as.character(x))
reactor <- reactor |> dplyr::mutate(block1 = fac_to_numeric(FR) * fac_to_numeric(Cat) *
fac_to_numeric(AR),
block2 = fac_to_numeric(FR) * fac_to_numeric(Temp) *
fac_to_numeric(Conc)) |>
dplyr::arrange(block1, block2) |>
dplyr::mutate(block = factor(rep(1:4, rep(8, 4)))) |>
dplyr::relocate(block) |>
dplyr::select(!c(block1, block2))
knitr::kable(reactor, caption = "Reactor experiment in blocks.")
```
We can produce an ANOVA table with the following code; `lm` and `anova` should automatically get the degrees of freedom correct (thr functions will recognise that three interactions are confounded with blocks and not estimable). The three confounded interactions do not appear in the `anova` output.
```{r block-4-anova, warning = F}
reactor.lm <- lm(pre.react ~ block + (FR + Cat + AR + Temp + Conc) ^ 5, data = reactor)
anova(reactor.lm)
```
Estimates of the clear factorial effects can be obtained as twice the corresponding regression coefficients. They are unchanged from the analysis of the unblocked design, as they are estimated independently of the blocks.
```{r block-4-fact-effects, warning = F}
fac.effs <- data.frame(fac.effs = 2 * coef(reactor.lm)[-(1:4)])
fac.effs <- tidyr::drop_na(fac.effs)
rownames(fac.effs) <- rownames(anova(reactor.lm))[-c(1, 30)]
knitr::kable(fac.effs, caption = "Reactor experiment: estimates of clear factorial effects", col.names = c("Estimate"))
```
Using Lenth's method produces very similar results to before, albeit using three fewer factorial effects (those confounded with blocks), as the pseudo-standard error hasn't changed^[As the median of the estimated factorial effects is still `r median(fac.effs$fac.effs)`.]
```{r block-4-lenth}
unrepx::hnplot(fac.effs$fac.effs, horiz = F, method = "Lenth", alpha = 0.05)
```
</details>