Introduction
The repeated measures ANOVA makes the following assumptions about the data:
No significant outliers in any cell of the design. This can be checked by visualizing the data using box plot methods and by using the function
identify_outliers()\[rstatix package\].Normality: the outcome (or dependent) variable should be approximately normally distributed in each cell of the design. This can be checked using the Shapiro-Wilk normality test (
shapiro_test()\[rstatix\]) or by visual inspection using QQ plot (ggqqplot()\[ggpubr package\]).Assumption of sphericity: the variance of the differences between groups should be equal. This can be checked using the Mauchly’s test of sphericity, which is automatically reported when using the R function
anova_test()\[rstatix package\].
Note that, if the above assumptions are not met there are a non-parametric alternative (Friedman test) to the one-way repeated measures ANOVA!
Unfortunately, there are no non-parametric alternatives to the two-way and the three-way repeated measures ANOVA. Thus, in the situation where the assumptions are not met, you could consider running the two-way/three-way repeated measures ANOVA on the transformed and non-transformed data to see if there are any meaningful differences.
If both tests lead you to the same conclusions, you might not choose to transform the outcome variable and carry on with the two-way/three-way repeated measures ANOVA on the original data.
It’s also possible to perform robust ANOVA test using the WRS2 R package.
No matter your choice, you should report what you did in your results.
RM Anova in R
Key R functions:
anova_test()\[rstatix package\], a wrapper aroundcar::Anova()for making easy the computation of repeated measures ANOVA. Key arguments for performing repeated measures ANOVA:data: data framedv: (numeric) the dependent (or outcome) variable name.wid: variable name specifying the case/sample identifier.within: within-subjects factor or grouping variable
get_anova_table()\[rstatix package\]. Extracts the ANOVA table from the output ofanova_test(). It returns ANOVA table that is automatically corrected for eventual deviation from the sphericity assumption. The default is to apply automatically the Greenhouse-Geisser sphericity correction to only within-subject factors violating the sphericity assumption (i.e., Mauchly’s test p-value is significant, p <= 0.05). Read more in Chapter @ref(mauchly-s-test-of-sphericity-in-r).
1-way RM Anova
The dataset “selfesteem” contains 10 individuals’ self-esteem score on three time points during a specific diet to determine whether their self-esteem improved.
| id | t1 | t2 | t3 |
|---|---|---|---|
| 1 | 4.005027 | 5.182286 | 7.107831 |
| 2 | 2.558124 | 6.912915 | 6.308434 |
| 3 | 3.244241 | 4.443434 | 9.778410 |
The one-way repeated measures ANOVA can be used to determine whether the means self-esteem scores are significantly different between the three time points. So let’s convert this data frame into long format:
| id | time | score |
|---|---|---|
| 1 | t1 | 4.005027 |
| 2 | t1 | 2.558124 |
| 3 | t1 | 3.244241 |
Descriptive statistics
| time | variable | n | mean | sd |
|---|---|---|---|---|
| t1 | score | 10 | 3.140 | 0.552 |
| t2 | score | 10 | 4.934 | 0.863 |
| t3 | score | 10 | 7.636 | 1.143 |
Assumptions
Outliers
| time | id | score | is.outlier | is.extreme |
|---|---|---|---|---|
| t1 | 6 | 2.045868 | TRUE | FALSE |
| t2 | 2 | 6.912915 | TRUE | FALSE |
There are 2 outliers found in Time1 and Time2. But since they are not extreme outliers and the dataset is small, we can ignore them and work as if our data has no outliers.
Normality
| time | variable | statistic | p |
|---|---|---|---|
| t1 | score | 0.9666901 | 0.8585757 |
| t2 | score | 0.8758846 | 0.1169956 |
| t3 | score | 0.9227150 | 0.3801563 |
As we can see, data for each measurement time is normally distributed. Second assumption for RM Anova is met.
Homogenity of variances
##
## Bartlett test of homogeneity of variances
##
## data: score by time
## Bartlett's K-squared = 4.2084, df = 2, p-value = 0.1219
Finally after checking homogenity of variances we can see that the dataset is perfect for normal RM Anova. There is no need to compute non-parametric alternative: Friedman’s test.
Anova
Let’s now perform the RM Anova analysis:
| Effect | DFn | DFd | F | p | p<.05 | ges |
|---|---|---|---|---|---|---|
| time | 2 | 18 | 55.469 | 0 |
|
0.829 |
We can notice that the p-value obtained from anova_test() is less than siginificance level we checked for. So the selfesteem score differs within different times of checking the score.
Post-hoc tests
| .y. | group1 | group2 | n1 | n2 | statistic | df | p | p.adj | p.adj.signif |
|---|---|---|---|---|---|---|---|---|---|
| score | t1 | t2 | 10 | 10 | -4.967618 | 9 | 7.72e-04 | 2e-03 | ** |
| score | t1 | t3 | 10 | 10 | -13.228148 | 9 | 3.00e-07 | 1e-06 | **** |
| score | t2 | t3 | 10 | 10 | -4.867816 | 9 | 8.86e-04 | 2e-03 | ** |
When we conclude pariwise tests, that means when we compare each possible combination of factors, we can notice that each p-value is way below 0.05 So every mean score taken in specific time is different from the other ones.
Graph Summary
We can conclude that the selfesteem score changed between time of the data collection points.
2-way RM Anova
For Two-Way Repeated Measures ANOVA, “Two-way” means that there are two factors in the experiment, for example, different treatments and different conditions. “Repeated-measures” means that the same subject received more than one treatment and/or more than one condition. Similar to two-way ANOVA, two-way repeated measures ANOVA can be employed to test for significant differences between the factor level means within a factor and for interactions between factors.
Using a standard ANOVA in this case is not appropriate because it fails to model the correlation between the repeated measures, and the data violates the ANOVA assumption of independence. Two-Way Repeated Measures ANOVA designs can be two repeated measures factors, or one repeated measures factor and one non-repeated factor. If any repeated factor is present, then the repeated measures ANOVA should be used.
Please apply Two-way RM-ANOVA to analyze if any of interactions are significant (between time and music, time and image, music and image, or music and time and image)! The response variable is level of stress experienced by a person watching one of 2 movie genres. Interpret your results. Use the following data set:
| PID | stress | image | music | |
|---|---|---|---|---|
| 1 | 1 | 34 | Angry | Disney |
| 61 | 1 | 87 | Happy | Disney |
| 121 | 1 | 49 | Happy | Horror |
| 181 | 1 | 19 | Happy | Disney |
| 241 | 1 | 38 | Happy | Horror |
| 301 | 1 | 26 | Angry | Disney |
Changes in dataset
However, in this dataset, we obtain few observations per same mix of factors:
| PID | image | music | variable | n | mean | sd |
|---|---|---|---|---|---|---|
| 1 | Angry | Disney | stress | 6 | 34.000 | 15.007 |
| 1 | Angry | Horror | stress | 4 | 42.500 | 34.771 |
| 1 | Happy | Disney | stress | 5 | 50.800 | 36.148 |
| 1 | Happy | Horror | stress | 5 | 40.800 | 23.145 |
| 2 | Angry | Disney | stress | 5 | 50.600 | 25.977 |
| 2 | Angry | Horror | stress | 6 | 48.333 | 35.904 |
At the example of PID=1 we can see that, the PersonID 1 gave 6 feedbacks of stress level while watching Angry-Disney movies, 4 times he/she watched Angry-Horror movies etc. So to conlcude furfher studies about if image and music has any impact on stress level of the viewer I will use mean value of the stress level shown in a table above.
| image | music | variable | n | mean | sd |
|---|---|---|---|---|---|
| Angry | Disney | stress | 306 | 48.951 | 28.796 |
| Angry | Horror | stress | 279 | 51.290 | 29.179 |
| Happy | Disney | stress | 296 | 49.963 | 29.217 |
| Happy | Horror | stress | 319 | 51.163 | 29.074 |
Assumptions
Outliers
| image | music | PID | variable | mean | is.outlier | is.extreme |
|---|---|---|---|---|---|---|
| Angry | Disney | 28 | stress | 14.667 | TRUE | FALSE |
| Angry | Disney | 48 | stress | 85.750 | TRUE | FALSE |
| Happy | Horror | 10 | stress | 85.000 | TRUE | FALSE |
| Happy | Horror | 21 | stress | 19.333 | TRUE | FALSE |
| Happy | Horror | 46 | stress | 18.333 | TRUE | FALSE |
We can see that there are not extreme outliers found in our dataset. So we can consider the data as it has no outliers.
Normality
| image | music | variable | statistic | p |
|---|---|---|---|---|
| Angry | Disney | mean | 0.9846672 | 0.6527259 |
| Angry | Horror | mean | 0.9845595 | 0.6576990 |
| Happy | Disney | mean | 0.9889600 | 0.8644835 |
| Happy | Horror | mean | 0.9837373 | 0.6047913 |
We can see that the dataset has normal distribution of means for each mix of factors.
Homogenity of variances
##
## Bartlett test of homogeneity of variances
##
## data: mean by interaction(image, music)
## Bartlett's K-squared = 2.165, df = 3, p-value = 0.5389
As we can see from the p-value, variances are equal.
Two-way RM Anova
| Effect | DFn | DFd | F | p | p<.05 | ges |
|---|---|---|---|---|---|---|
| music | 1 | 58 | 0.461 | 0.500 | 0.002000 | |
| image | 1 | 58 | 0.027 | 0.870 | 0.000108 | |
| music:image | 1 | 58 | 0.228 | 0.635 | 0.001000 |
No p-value is below 0.05, so we cannot reject H0.
Thus the type of movie watched by a participant does not have impact on stress level.