This post covers my notes of factorial ANOVA methods using R from the book “Discovering Statistics using R (2012)” by Andy Field. Most code and text are directly copied from the book. All the credit goes to him.
Self-test 2 (note that self-test 1 is moved to the later part)
Use ggplot2 to plot boxplots of the attractiveness of the date at each level of alcohol consumption on the x-axis and different panels to represent males and females.
stat.desc for combinations of levels of variables
Levene’s test on interaction
We have F(5, 42) = 1.425, p = .235, which is indicative of the assumption being met.
3. Choose contrasts
One very important consideration here is that if we want to look at Type III sums of squares (see Jane Superbrain Box 11.1) then we must use an orthogonal contrast for these sums of squares to be computed correctly.
4. Do the factorial ANOVA
This command creates a model called gogglesModel, which includes the two independent variables and their interaction.
Output 1
5. Interpret factorial ANOVA
Output 1 tells us that there is a significant main effect of alcohol (p<0.05). It also tells us that the main effect of gender is not significant (p=0.16). Finally, it tells us that the interaction between the effect of gender and the effect of alcohol is significant.
Self-test 3
Plot error bar graphs of the main effects of alcohol and gender.
Note that I’ve used scale_y_continuous() to override the defaults for the y-axis. Specifically, I have used the breaks option to specify the numbering along this axis: breaks=seq(0, 80, by = 10) uses the seq() function to create a sequence of numbers from 0 to 80 in steps of 10. Therefore, we get axis labels at 0, 10, 20, 30, 40, 50, 60, 70, 80 (the defaults were 0, 20, 40, 60, 80).
Self-test 1
Use ggplot2 to plot a line graph (with error bars) of the attractiveness of the date with alcohol consumption on the x-axis and different-coloured lines to represent males and females.
This figure shows that for women, alcohol has very little effect: the attractiveness of their selected partners is quite stable across the three conditions (as shown by the near-horizontal line). However, for the men, the attractiveness of their partners is stable when only a small amount has been drunk, but rapidly declines when 4 pints have been drunk.
Short summary of the three plots
This shows why main effects should not be interpretted when a significant interaction involving those main effects exists.
6. Interpret contrasts
gender1: This is the contrast for the main effect of gender
alcohol1: This contrast compares the no-alcohol group to the two alcohol groups.
alcohol2: This contrast tests whether the mean of the 2-pints group (64.69) is different than the mean of the 4-pints group (46.56).
gender1:alcohol1: This contrast tests whether the effect of alcohol1 described above is different in men and women.
gender1:alcohol2: This contrast tests whether the effect of alcohol2 described above is different in men and women.
7. Simple effects analysis - break down an interaction term (skipped)
This analysis looks at the effect of one independent variable at individual levels of the other independent variable. So, for example, in our beer-goggles data we could do simple effects analysis looking at the effect of gender at each level of alcohol. This would mean taking the average attractiveness of the date selected by men and comparing it to that for women after no drinks, then making the same comparison for 2 pints and then finally for 4 pints.
(skipped)
8. Post hoc test (for illustrative purposes)
The variable alcohol has three levels and so you might want to perform post hoc tests to see where the differences between groups lie.
However, since the interaction between alcohol and gender is significant, we should not interpret alcohol alone.
Therefore, this post hoc test is for illustrative purposes.
Bonferroni post hoc tests using the pairwise.t.test() function and Tukey tests using glht():
The Bonferroni and Tukey tests show the same pattern of results: when participants had drunk no alcohol or 2 pints of alcohol, they selected equally attractive mates. However, after 4 pints had been consumed, participants selected significantly less attractive mates than after both 2 pints (p < .001) and no alcohol (p < .001).
Plots
aov() function automatically generates some plots that we can use to test the assumptions. We can see these graphs by executing:
You will actually see four graphs, but the first two are the most important. The first graph (on the left of the figure) can be used for testing homogeneity of variance. The plot we have does show funnelling (the spread of scores is wider at some points than at others), which implies that the residuals might be heteroscedastic (a bad thing). The second plot (on the right) is a Q-Q plot, which tells us about the normality of residuals in the model. Our plot suggests that we can assume normality of our residuals/errors.
Robust test (skipped)
The residual plot above suggests that a robust test might be in order. However, it has many steps and functions. I’d like to skip this method.
Effect size
Omega squared ($\omega^2$). This measure computes the overall effect size. Section 12.8 provides a omega_factorial() function.
mes(), compute effect sizes for the effect of gender at different levels of alcohol. I’d like to skip this method.
Conclusion
I only keep the R code and some very brief interpretation of the results. To see the rationale of each method or read more description of each method, it is a good idea to read the book sections. For convenience, I have added section numbers for some methods.
Thanks for reading and feel free to correct me if I made any mistake.