Repeated Measure ANOVA
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.
Descriptive statistics
<- ggboxplot(
bxp x = "time", y = "score",
selfesteem, color = "time", palette = "jco"
) bxp
ggplot(selfesteem, aes(x=time,y=score))+
geom_violin()+
stat_summary(fun = "mean",
geom = "crossbar",
width = 0.5,
colour = "red")+
geom_jitter(aes(color =time))+
scale_color_manual(values = c('#4B0082','#4682B4','#FF0000'))
<- selfesteem %>%
table group_by(time) %>%
get_summary_stats(score, type = "full",
show = c("n","mean","sd","max","min","se","q1","q3","median"))
kbl(table)
time | variable | n | mean | sd | max | min | se | q1 | q3 | median |
---|---|---|---|---|---|---|---|---|---|---|
t1 | score | 10 | 3.140 | 0.552 | 4.005 | 2.046 | 0.174 | 2.914 | 3.486 | 3.212 |
t2 | score | 10 | 4.934 | 0.863 | 6.913 | 3.908 | 0.273 | 4.411 | 5.301 | 4.601 |
t3 | score | 10 | 7.636 | 1.143 | 9.778 | 6.308 | 0.361 | 6.700 | 8.440 | 7.463 |
Assumptions
Normality check
<- selfesteem %>%
table group_by(time) %>%
shapiro_test(score)
kbl(table)
time | variable | statistic | p |
---|---|---|---|
t1 | score | 0.9666901 | 0.8585757 |
t2 | score | 0.8758846 | 0.1169956 |
t3 | score | 0.9227150 | 0.3801563 |
ggqqplot(selfesteem, "score", ggtheme = theme_bw(),facet.by="time")
shapiro_test and qqplot shows that data is normally distributed
Outlier
<- selfesteem %>%
table group_by(time) %>%
identify_outliers(score)
kbl(table)
time | id | score | is.outlier | is.extreme |
---|---|---|---|---|
t1 | 6 | 2.045868 | TRUE | FALSE |
t2 | 2 | 6.912915 | TRUE | FALSE |
there is two outliers but none of them is extreme so data meets assumption that there is no significant ouliers
Anova
<-anova_test(selfesteem,dv = score, wid = id, within = time)
res.aov
kbl(res.aov)
|
|
|
data meets assumption of sphericity(p>0.05) and anova test shows that there is significant differnce in mean’s between time groups (F(2,18) = 55.469, p < 0.05) ### Post-hoc tests
Pairwise comparisons
<- selfesteem %>%
pwc pairwise_t_test(score~time, paired = TRUE
)kbl(pwc)
.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 | ** |
Conclusions
ggwithinstats(selfesteem,time,score)
A repeated measure anova was conducted to analyze if there is significant difference in score of self esteem depending on time group There were 2 ouliers but none of them were extreme, the outliers were assest with boxplot method. Data was normally distributed and it was checked with Shapiro-Wilks normality test and qqplot, (p > 0.05 for every group ) assumption of spherical was met (p = 0.092 > 0.05) anova test showed there was statistically significant difference in means (p = 0.0000000201) pairwise comparison showed that there is significant difference in every group and the biggest difference is between groups t1,t3, differences in groups t3,t2 and t2,t1 are simmilar the biggest score participants showed in time t3.