Blocking
Though this is not true, suppose the supplement type is actually a nuisance factor we'd like to control for by blocking, and we're actually only interested in the effect of the dose of Vitamin C on guinea pig tooth growth.
If we block by supplement type, we create groups that are more similar, in that they'll have the same supplement type, allowing us to examine only the effect of dose on tooth length.
We'll use the aov()
function to examine this. aov()
creates a linear regression model by calling lm()
and examining results with anova()
all in one function call. To use aov()
, we'll still need functional notation, as with the randomization exercise, but this time the formula should be len ~ dose + supp
to indicate we've blocked by supplement type. (We'll cover aov()
and anova()
in more detail in the next chapter.)
ggplot2
is loaded for you.
This exercise is part of the course
Experimental Design in R
Exercise instructions
- Make a boxplot to visually examine if the tooth length is different by
dose
.dose
has been converted to a factor variable for you. - Use
aov()
to detect the effect ofdose
andsupp
onlen
. Save as a model object calledToothGrowth_aov
. - Examine
ToothGrowth_aov
withsummary()
to determine if dose has a significant effect on tooth length.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a boxplot with geom_boxplot()
ggplot(___, aes(x = ___, y = ___)) +
___()
# Create ToothGrowth_aov
___ <- aov(___, data = ___)
# Examine ToothGrowth_aov with summary()
___