-
Notifications
You must be signed in to change notification settings - Fork 0
/
effects_model.qmd
416 lines (293 loc) · 25.4 KB
/
effects_model.qmd
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
---
title: "Effects Model"
execute:
echo: false
format:
html:
fig-width: 10.5
fig-height: 7.5
---
```{=html}
<script type="text/javascript">
function showhide(id) {
var e = document.getElementById(id);
e.style.display = (e.style.display == 'block') ? 'none' : 'block';
}
</script>
```
# Introduction
## Models
In science, statistics, mathematics, etc. we are interested in discovering and describing truth about the world we live in. We can use models to represent a phenomenon or system. The model's purpose may be to describe and explain something about the way things work and/or to make prediction. An ANOVA model is a model that uses mathematical terms and constructs, in the form of an equation. The ANOVA model quantifies the relationship between factor(s) and a response.
If we were able to observe all items in a population we would be able to quantify with exactness how a factor variable is related to a response variable with an ANOVA model. This "true", or exact quantification of how the two variables relate is called a parameter. However, with rare exceptions, we cannot observe every item in a population. Instead, we must rely on a sample to calculate *estimates* of the parameter.
By the end of this section you should know how to interpret the terms in an ANOVA model (i.e. know what they mean), and also perform the calculations necessary to estimate ANOVA model parameters.
## Toothbrush Example
Consider an experiment conducted to test 4 different types of toothbrushes: manual, oscillating, sonic and ultrasonic. The response variable is percent of area on teeth that has plaque. Twenty-four individuals participate in the experiment, yielding 6 observations per treatment. We will discuss the creation of an ANOVA model using the context of this specific example. In this section and "Calculating Effect Sizes" section we will be referring to estimates of model parameters using this sample data.
Up to this point we have primarily been interested in calculating means in order to compare toothbrushes. If the mean percent of teeth surface area with plaque was 23.09 for a manual brush, you would want to know how that value compares to the other types of brushes. A graph or table reporting the other sample means would be necessary to provide context. @fig-means depicts the data points and the mean for each factor level.
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(pander)
library(mosaic)
```
```{r}
#| message: false
bf1 <- read_csv("data/toothpaste_BF2.csv") %>% select(-Toothpaste) %>%
mutate(brush_num = case_when(
Brush == "Manual" ~ 1,
Brush == "Oscillating" ~ 2,
Brush == "Sonic" ~ 3,
Brush == "Ultrasonic" ~4
))
mu <- bf1 %>%
group_by(Brush) %>%
summarise(Brush_mean = mean(Plaque))
grandmean <- mean(bf1$Plaque)
xaxis_limits <- c(.25, 4.75)
```
```{r}
#| label: fig-means
#| fig-cap: "Brush means and grand mean"
plot(Plaque~brush_num, data=bf1, pch=16, xaxt='n',xlim = xaxis_limits, ylab= "% Teeth Area with Plaque", xlab="", main="Visualizing Toothbrush Data")
#cex=.8,
axis(1, at=c(1,2,3,4), labels=c("Manual", "Oscillating", "Sonic", "Ultrasonic"))
lines(xaxis_limits, rep(grandmean, 2), lty=1, col = "firebrick")
text(4.5,grandmean-.5, "Grand mean", col = "firebrick")
text(4.5,grandmean-1.25, "= 22.765", col = "firebrick")
#Puts the dashed group mean line for manual
lines(c(1-.2,1+.21), rep(mu[1,2],2), lty=2)
text(1-.4,mu[1,2], expression(bar(y)[man]), cex=1.2)
#Puts the dashed group mean line for oscillating
lines(c(2-.2,2+.21), rep(mu[2,2],2), lty=2)
text(2-.4,mu[2,2], expression(bar(y)[osc]), cex = 1.2)
#Puts the dashed group mean line for sonic
lines(c(3-.2,3+.21), rep(mu[3,2],2), lty=2)
text(3-.4,mu[3,2], expression(bar(y)[sonic]), cex = 1.2)
#Puts the dashed group mean line for ultrasonic
lines(c(4-.2,4+.21), rep(mu[4,2],2), lty=2)
text(4-.4,mu[4,2], expression(bar(y)[ultra]), cex = 1.2)
```
```{r oldjunk, eval = FALSE, include = FALSE}
#lines(rep(1+.21,2), c(ai[1],mu), lty=2, col='firebrick')
lines(c(1-.2,1+.21), rep(ai[1],2), lty=2)
text(1-.4,ai[1], expression(mu[1]))
#text(1+.21, (ai[1]+mu)/2, expression(alpha[1]), pos=4, cex=0.8)
#lines(rep(2+.21,2), c(ai[2],mu), lty=2, col='firebrick')
lines(c(2-.2,2+.21), rep(ai[2],2), lty=2)
text(2-.4,ai[2], expression(mu[2]))
#text(2+.21, (ai[2]+mu)/2, expression(alpha[2]), pos=4, cex=0.8)
#lines(rep(3+.21,2), c(ai[3],mu), lty=2, col='firebrick')
lines(c(3-.2,3+.21), rep(ai[3],2), lty=2)
text(3-.4,ai[3], expression(mu[3]))
#text(3+.21, (ai[3]+mu)/2, expression(alpha[3]), pos=4, cex=0.8)
lines(rep(3-.1,2), c(ai[3],y$yi[25]), lty=2, col='firebrick')
lines(c(3-.2,3), rep(y$yi[25],2), lty=2)
text(3-.21,y$yi[25], expression(y[3][","][5] == mu[3]+epsilon[3][","][5]), pos=2, cex=0.8)
text(3-.1, (y$yi[25]+ai[3])/2, expression(epsilon[3][","][5]), pos=2, cex=0.8)
```
In an earlier, introductory statistics class you most likely learned how to use sample means in order to test whether populations means for different groups are equal using analysis of variance (ANOVA). This hypothesis test of multiple population means is valid and works when you only have 1 factor. This is often called the cell means model.[^1] However, it is limited in its ability to include more factors or more complicated designs.
There is another metric we use to compare factor levels: the effect size. Reporting the effect of a factor level has the benefit of providing some context on how that factor level is influencing the response variable relative to other levels of the same factor. Using effect sizes (as opposed to factor level means) allows us to model and test much more complicated scenarios than a simple one factor experiment.
[^1]: The algebraic form of the cell means model is
$$
y_\text{ij} = \mu_i + \epsilon_\text{ij}
$$
Where $y_\text{ij}$ is an observation, $\mu_i$ is the mean of factor level $i$, and $\epsilon_\text{ij}$ is the residual for each observation. The ANOVA F-test hypothesis for this model is $H_0: \text{All means are equal to each other}$.
# Calculating Effect Sizes {#sec-effects}
In the case of the toothbrush example, the effect of an ultrasonic toothbrush is estimated by subtracting the grand mean from the mean of ultrasonic brush observations. If the grand mean of the observations was 22.765 and the mean for ultrasonic was 25.313, we get
$$
\text{Effect}_\text{ultra} = \bar{y}_\text{ultra} - \bar{y}_\text{grand} = 25.313 - 22.765 = 2.548
$$ {#eq-effect_ultra}
Thus, use of an ultrasonic toothbrush increases the mean percent area with plaque by 2.548 relative to the grand mean. Therefore, the ultrasonic toothbrush's effectiveness at removing plaque is estimated to be worse than average.
In like manner, the estimated effect size for the other factor levels is calculated
$$
\text{Effect}_\text{manual} = \bar{y}_\text{manual} - \bar{y}_\text{grand} = 23.093 - 22.765 = 0.328
$$ {#eq-factor_manual}
$$
\text{Effect}_\text{oscillating} = \bar{y}_\text{oscillating} - \bar{y}_\text{grand} = 19.977 - 22.765 = -2.788
$$ {#eq-factor_osc}
$$
\text{Effect}_\text{sonic} = \bar{y}_\text{sonic} - \bar{y}_\text{grand} = 22.675 - 22.765 = -0.09
$$ {#eq-factor_sonic}
@fig-effects shows a visual representation of effect size for oscillating and ultrasonic brushes. The effect sizes for manual and sonic brushes could also have been drawn, but are omitted so that the chart does not become too cluttered.
```{r}
#| label: fig-effects
#| fig-cap: "Effects illustrated for oscillating and ultrasonic brushes in blue. Effects rounded to 2 decimal places"
plot(Plaque~brush_num, data=bf1, pch=16, xaxt='n',xlim = xaxis_limits, ylab= "% Teeth Area with Plaque", xlab="", main="Visualizing Toothbrush Data")
axis(1, at=c(1,2,3,4), labels=c("Manual", "Oscillating", "Sonic", "Ultrasonic"))
lines(xaxis_limits, rep(grandmean, 2), lty=1, col = "firebrick")
text(4.5,grandmean-.5, "Grand mean", col = "firebrick")
text(4.5,grandmean-1.25, "= 22.765", col = "firebrick")
#Puts the dashed group mean line for manual
lines(c(1-.2,1+.21), rep(mu[1,2],2), lty=2)
text(1-.4,mu[1,2], expression(bar(y)[man]), cex = 1.2)
#Puts the dashed group mean line for oscillating
lines(c(2-.2,2+.21), rep(mu[2,2],2), lty=2)
text(2-.4,mu[2,2], expression(bar(y)[osc]), cex = 1.2)
#Puts the dashed group mean line for sonic
lines(c(3-.2,3+.21), rep(mu[3,2],2), lty=2)
text(3-.4,mu[3,2], expression(bar(y)[sonic]), cex = 1.2)
#Puts the dashed group mean line for ultrasonic
lines(c(4-.2,4+.21), rep(mu[4,2],2), lty=2)
text(4-.4,mu[4,2], expression(bar(y)[ultra]), cex = 1.2)
#Oscillating effect line and text
lines(rep(2-.1,2), c(mu[2,2], grandmean), lty=3, col = "cornflowerblue")
text(2-.05, mean(c(mu[[2,2]], grandmean)), expression(effect[osc]==-2.79), col = "cornflowerblue",
pos=2, cex = 1.2)
#Ultrasonic effect line and text
lines(rep(4-.1,2), c(mu[4,2], grandmean), lty=3, col = "cornflowerblue")
text(4-.05, mean(c(mu[[4,2]], grandmean)), expression(effect[ultra]== 2.55), col = "cornflowerblue",
pos=2, cex = 1.2)
```
The effect size of a factor level can be thought of as the difference between a factor level's mean and its partial fit[^2]. Or in other words, the difference between what you would predict for a given observation and what you would predict for that same observation without knowing which level of the factor it belongs to.
[^2]: Partial fit is a term that refers to an estimated model, or estimated prediction, using only some of the factors. Often, in ANOVA, partial fit refers to a model or prediction estimated using just outside factors. Thus, for this model @eq-general-effects-rule could be restated as Factor level effect size = Factor level mean - partial fit.
::: callout-tip
## General rule to calculate effect size
$$
\text{Factor level effect size} = \text{Factor level mean} - \text{sum of effects of all outside factors}
$$ {#eq-general-effects-rule}
:::
### Effect of the Grand Mean Factor
Using @eq-general-effects-rule we can also estimate the effect of the grand mean factor. Grand mean only has 1 level and it includes all the observations, so the factor level mean is the same as the mean of all the observations, 22.765. The "sum of effects of all outside factors" is 0 since there are no factors outside of grand mean. Therefore, the effect size for the grand mean factor is simply the grand mean. In this case, 22.765.
### Effects of the Residual Error Factor
What about factor effects for various levels of residual error? We will show how this is done by working through an example for a specific observation. Let's consider the observation with a value of 17.62 from the oscillating group. As a reminder, toothbrush type and benchmark are both outside of residual error (see [Factor Structure](factor_structure.qmd) for a review of inside vs. outside factors).
::: column-page
![Factor Structure Diagram for Toothbrush Study with 1 Factor](images/toothbrush_bf1_colored_factors.JPG){#fig-toothbrush_bf1_colored_factors}
:::
There is only one observation in each box of the residual error factor. Therefore, the factor level mean for this observation is just the observation itself, 17.62. Next, to use the general rule we must find the effects of outside factors: toothbrush type and grand mean. The observation we are interested in belongs to the oscillating toothbrush group; we have already estimated the effect of the oscillating toothbrush to be -2.788. We estimated that the effect of grand mean factor is 22.765. Therefore, the residual error calculation is contained in @eq-obs1-effect :
$$
17.62 - (22.765 + -2.788) = -2.357
$$ {#eq-obs1-effect}
This means that this individual's plaque percent area was 2.357 lower than the average plaque percent area of those who used an oscillating brush. (Less plaque is a good thing!) We cannot tell exactly what caused the residual error. It could be a result of differences in how vigorously people brush, variations in the manufacture of the brushes, differences in how researchers assessed plaque from one person to another and an infinite number of other things. If the experiment implemented randomization properly and was designed and executed well, these residual error effects (i.e. the unexplained error) should behave randomly. In fact, they should behave like a normally distributed random variable...more on that in [the Assumptions section](assumptions.qmd).
We will repeat the residual error[^3] calculation process for the outlying point in the ultrasonic level of toothbrush, which has a percent teeth area with plaque value of 32.74. The first step in applying the general rule is to find the factor level mean. In the residual error factor, each level only contains one observation, so the residual error factor level mean for this observation is just the observation itself, 32.74. The second step is to sum the effects of outside factors: grand mean and toothbrush. The grand mean's effect is simply the grand mean, 22.765. The effect of toothbrush in this case is 2.548 because the observation belongs to the ultrasonic group. The estimation of the residual error is therefore contained in @eq-obs2-effect :
[^3]: You can think of an effect as a deviation from a mean. Other synonyms for deviation are error and variance. When you calculate an effect, you are also calculating a deviation or error. Thus, residual error effect is a bit redundant. Residual error and residual effect may be used interchangeably.
$$
32.74 - (22.765 + 2.548) = 7.427
$$ {#eq-obs2-effect}
These two residual errors are depicted in green in @fig-resids.
```{r}
#| label: fig-resids
#| fig-cap: "Residual error effects (rounded to two decimal places) in green, illustrated for two example points"
plot(Plaque~brush_num, data=bf1, pch=16, xaxt='n',xlim = xaxis_limits, ylab= "% Teeth Area with Plaque", xlab="", main="Visualizing Toothbrush Data")
axis(1, at=c(1,2,3,4), labels=c("Manual", "Oscillating", "Sonic", "Ultrasonic"))
lines(xaxis_limits, rep(grandmean, 2), lty=1, col = "firebrick")
text(4.5,grandmean-.5, "Grand mean", col = "firebrick")
text(4.5,grandmean-1.25, "= 22.765", col = "firebrick")
#Puts the dashed group mean line for manual
lines(c(1-.2,1+.21), rep(mu[1,2],2), lty=2)
text(1-.4,mu[1,2], expression(bar(y)[man]), cex = 1.2)
#Puts the dashed group mean line for oscillating
lines(c(2-.2,2+.21), rep(mu[2,2],2), lty=2)
text(2-.4,mu[2,2], expression(bar(y)[osc]), cex = 1.2)
#Puts the dashed group mean line for sonic
lines(c(3-.2,3+.21), rep(mu[3,2],2), lty=2)
text(3-.4,mu[3,2], expression(bar(y)[sonic]), cex = 1.2)
#Puts the dashed group mean line for ultrasonic
lines(c(4-.2,4+.21), rep(mu[4,2],2), lty=2)
text(4-.4,mu[4,2], expression(bar(y)[ultra]), cex = 1.2)
#Oscillating effect line and text
lines(rep(2-.1,2), c(mu[2,2], grandmean), lty=3, col = "cornflowerblue")
text(2-.05, mean(c(mu[[2,2]], grandmean)), expression(effect[osc]==-2.78), col = "cornflowerblue",
pos=2)
#Ultrasonic effect line and text
lines(rep(4-.1,2), c(mu[4,2], grandmean), lty=3, col = "cornflowerblue")
text(4-.05, mean(c(mu[[4,2]], grandmean)), expression(effect[ultra]== 2.55), col = "cornflowerblue",
pos=2)
#Residual error within oscillating
lines(rep(2+.1,2), c(17.62,mu[2,2]), lty=3, col = "darkgreen")
lines(c(2, 2+.21), rep(17.62,2), lty = 3, col = "darkgreen")
text(2+.1, mean(c(17.62,mu[[2,2]])), expression(y-bar(y)[osc]==-2.36), col = "darkgreen",
pos=4)
#Residual error within ultra
lines(rep(4+.1,2), c(32.74,mu[4,2]), lty=3, col = "darkgreen")
lines(c(4, 4+.21), rep(32.74,2), lty = 3, col = "darkgreen")
text(4+.1, mean(c(mu[[4,2]], 32.74)), expression(y-bar(y)[ultra] == 7.43), col = "darkgreen",pos=4)
```
Hopefully you can see that if you have the effect for each of the factors in the factor structure diagram you can add them together to arrive at an individual observation. The assembly line metaphor that George Cobb[^4] uses to explain this phenomenon is helpful in understanding how this all fits together.
[^4]: Cobb, George. *Introduction to Design and Analysis of Experiments*. Wiley, 2014. <!-- used MLA formatting. I have no bibliography or list of sources for data started -->
## Assembly Line Metaphor
You can imagine that each data point in your data set is created by going down an assembly line, much like you would find in a factory that makes cars or appliances. All points start with the grand mean value. As it progresses through the assembly line the data point is altered to reflect the effect of the factor levels it belongs to.
<!-- ![](imaassembly_line.jpg){width="300" fig-align="center"} -->
![](images/assembly_line.jpg){fig-align="center"}
In the toothbrush **and** toothpaste experiment all the points start the assembly line at the same value: the grand mean of the data set. The first station on the line receives the data point and adds or subtracts to it based on the type of brush it is. For example, the value would be added upon if the brush type was "manual" because the mean plaque percentage for the manual type was higher than the grand mean. The next station alters the value depending on which toothpaste was used: off-brand or name brand. After going through each station (one station for each factor) in the assembly line the data point arrives at the last station.
The last station is worked by a person who makes random adjustments! Some adjustments will be big, and some will be small; some will be positive, and some will be negative. (In a typical factory this person would be fired. But we would rather have randomness than unknown, systematic adjustments , i.e. bias). These random adjustments are driven by any/all factors that we did not explicitly measure.
For example, variability in the experimental unit's diet, hardness of the water used when brushing, the impact of flossing, outside temperature, and the price of rice in China are all factors that were not taken into account. Effects from these and an infinite number of other factors are all lumped into the residual error factor effects. The effects of factors unrelated to the response should be negligible. Effects from other factors that were sufficiently randomized should usually cancel each other out. The point is that all these factor's effects show up in one (hopefully small) adjustment at the last station and are referred to as "unexplained variance" (review [Sources of Variance](sources_of_variances.qmd)).
Though the adjustments at this last station for residual error are (assumed) random, they do follow a pattern. Namely, the mean of the adjustments is zero and they follow a normal distribution.
# A Formal Model and Notation
It is helpful to recognize that each factor influences, or has an effect on, the response variable. You can combine all these effects to "build" an observation. However, when we get the observation it comes already built. We will need to break it back down into its component parts; like reverse engineering the dataset to be able to explain why each data point is the way that it is.
Taking it a step further, the variance in a set of observations can also be broken down into its component parts. This is called an analysis of variance (ANOVA). Before going farther, it will be helpful to create a formal, mathematical model to describe how these factor effects combine to arrive at a single observation. This will be illustrated with just a single observation first.
The fifth observation in the oscillating brush group had a value of 17.62. In @sec-effects we used the general rule (@eq-general-effects-rule) to calculate the following effects:
$$
\text{Effect}_\text{grand mean} = 22.765
$$
$$
\text{Effect}_\text{oscillating} = -2.788
$$
$$
\text{Effect}_\text{residual} = -2.357
$$
We can represent this observation as the sum of its factor level effects.
$$
17.62 = 22.765 + (-2.788) + (-2.357)
$$ {#eq-one-obs}
@fig-one-obs-build puts this in context of our factor structure diagram.
::: column-page
![An observation can be broken into the sum of its factor effects](images/toothbrush_one_obs_build.JPG){#fig-one-obs-build fig-align="center"}
:::
@fig-all-obs-build shows this same calculation for all the observations. (Effect sizes are rounded to two decimal places).
::: column-page
![Decomposition of all observations into their factor effects (rounded to 2 decimal places)](images/toothbrush_all_obs_build.JPG){#fig-all-obs-build fig-align="center"}
:::
::: {#key-properties .callout-important}
## Note
Notice that the sum of the effects across the treatment factor (toothbrush) equal zero.
$$
0.33 + -2.79 + -.09 + 2.55 = 0
$$
The sum of all the residual errors *within* a treatment factor level also equal zero. For example, for the manual brush the summed residuals are:
$$
-3.97 + 1.12 + 3.79 + -1.49 + 0.31 + 0.26 = 0
$$
Because of the way effect size is calculated, this will [always]{.underline} be the case, regardless of the number of levels or the number of replicates. This result will continue to hold even as we add more structural factors.
Also take notice of the pattern of repeating values within a factor level. These patterns can help us better understand degrees of freedom.
:::
We can write a general form of the model as:
$$
observation = effect_\text{grand mean} + effect_\text{brush} + effect_\text{residual}
$$
Rather than writing "effect" and "observation", let's introduce symbols to represent the effects and observations. We will use a different symbol for each factor effect, and we will use y to represent an observation.
- $\mu$ is the effect for grand mean.
- $\alpha_i$ refers to the effect of the factor that is varied in the experiment; in our case the factor is toothbrush. The subscript $i$ indicates which level of the factor the effect is for: $i=1$ is manual, $i=2$ is oscillating, $i=3$ is sonic, $i=4$ is ultrasonic.
- $\epsilon_\text{ij}$ is the residual for each observation. The residual term will have a matching subscript for each factor in the study (in this case $i$) to indicate which factor level the observation belongs to; plus another subscript to indicate the replicate number within that factor level (or in the case of multiple factors, it is the replicate number within a factor level combination).
- $y_\text{ij}$ is an observation. Since each observation has a residual, $y$'s subscripts will match epsilon's ($\epsilon$) subscript. It will tell us exactly which replicate within a factor level is being referenced.
We can rewrite @eq-one-obs symbolically:
$$
y_\text{12} = \mu + \alpha_1 + \epsilon_\text{12}
$$
@fig-notation-factor-structure shows how this new notation can be used to reference any and all parts of our factor structure.
::: column-page
![Symbolic representation for every data point in the factor structure](images/toothbrush_notation_factor_structure.JPG){#fig-notation-factor-structure fig-align="center"}
:::
::: callout-tip
## General form of effects model with one structural factor
$$
y_\text{ij} = \mu + \alpha_i + \epsilon_\text{ij}
$$ {#eq-general-form}
This is called an effects model (as opposed to a means model) because it shows how each observation is the sum of factor effects. This can be expanded to more complicated designs by adding a term to the model for each factor.[^5]
:::
[^5]: The model for the experiment that includes toothpaste brand and toothbrush type is
$$
y_\text{ijk} = \mu + \alpha_i + \beta_j + (\alpha\beta)_\text{ij} + \epsilon_\text{ijk}
$$
Here
- $\alpha$ is the effect of toothbrush, and $i$ goes from 1 to 4 since there are 4 toothbrush types
- $\beta$ is the effect of toothpaste, and $j$ is either 1 or 2 since there are 2 levels (Name brand and Generic brand).
- $\alpha\beta)_\text{ij}$ is the interaction term. An interaction is discussed on the [BF[2]](bf2.qmd) page.
- $\epsilon$ is the residual error term, and $k$ is the replicate count within a factor level combination.
At this point you should begin to see how the factor structure diagram can help us put together a mathematical model. Each factor in the diagram corresponds to a different term in the mathematical model.
We represent the observations with lower case English letters because they are known values (we observed them!). Greek letters are used to represent unknown, population parameters. The data is used to estimate those parameters. To represent an estimate of the effect we will place a hat on the parameter: $\hat{\mu}$, $\hat{\alpha}$, and $\hat{\epsilon}$. Commonly $\hat{\epsilon}$ is also expressed as $e$; we will use these interchangeably in this book. Other books may represent these quantities with different symbols.
You can also see that calculating means is a crucial part of calculating effect estimates. As you already know, a bar is added over $y$ to represent a mean of observed values. You can use dots in the subscripts of $\bar{y}$ to indicate which values you are averaging over.
For example, the mean of the observations in the first level of a treatment factor would be represented as $\bar{y}_{1\cdot}$. The 1 in the subscript indicates the mean only includes values from the first level of the treatment factor, and the dot indicates all the replicates are included. You can think of the "." as meaning "include all the values of the subscript". In our toothbrush example, $\bar{y}_{1\cdot}$ is our estimate of the mean percent area covered by plaque after using a manual toothbrush, because a subscript $i$ value of 1 corresponds to manual, and the dot indicates all (6) replicates of the manual brush are included in the mean.
$$
\bar{y}_{1\cdot} = \frac{19.12 + 24.21 + 26.88 + 21.6 + 23.4 + 23.35}{6} = 23.09
$$ {#eq-ybar-1dot}
Similarly, $\bar{y}_{\cdot\cdot}$ represents an estimate of the grand mean. The dot in the first position indicates we should include all levels of the treatment factor (toothbrush) and the second dot indicates we should include all the replicates.