Repeated Measure ANOVA
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)! Interpret your results. Use the following data set - myData which connsist of 1200 observation on 60 different people, each person is listennig to music (disney/horror) and at the same time looking on iamge(happy/angry) and then stress level is messured, participant is examinated like that multiple times
Cleaning
first we need to clean our data beacuse as we can see we have a lot of repeated conditions for one participant so we need merge this in order to have each participant with each combination of conditions.
myData_cleaned <- aggregate(myData$stress,
by = list(myData$PID, myData$music,
myData$image),
FUN = 'mean')
colnames(myData_cleaned) <- c("PID","music","image","stress")Descriptive statistics
Vizualization
ggplot(myData_cleaned, aes(x=stress)) +
geom_histogram(bins=30) +
facet_grid(image ~ music) myData_cleaned %>%
ggplot( aes(x=factor(image), y=stress, fill=music, position = "over_lapp")) +
geom_violin(width=1) +
geom_boxplot(width=1, color="black") +
scale_fill_viridis(discrete = TRUE) +
theme(
legend.position="none",
plot.title = element_text(size=11)
) +theme(plot.margin=unit(c(1,2,0,0),"cm")) +
theme(legend.position=c(1,1), legend.justification=c(0,1)) ggtitle("A Violin wrapping a boxplot") ## $title
## [1] "A Violin wrapping a boxplot"
##
## attr(,"class")
## [1] "labels"
we can see outliers here on boxplot but neither of them seems extreme, means are very simmiliar to each other
index <- c(1:239)
ggplot(myData_cleaned, aes(index,y=stress,color = music, alpha = 0.2)) +
geom_point() +
theme(plot.margin=unit(c(1,2,0,0),"cm")) +
theme(legend.position=c(1,1), legend.justification=c(0,1))+
facet_wrap(~image)Summary table
table_sum<- myData_cleaned %>%
group_by(music,image) %>%
get_summary_stats(stress, type = "full",
show = c("n","mean","sd","max","min","se","median"))
table_sum %>%
kbl() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))| music | image | variable | n | mean | sd | max | min | se | median |
|---|---|---|---|---|---|---|---|---|---|
| Disney | Angry | stress | 60 | 49.131 | 11.800 | 73.75 | 21.5 | 1.523 | 48.717 |
| Disney | Happy | stress | 60 | 49.313 | 15.040 | 77.50 | 5.0 | 1.942 | 50.167 |
| Horror | Angry | stress | 60 | 53.441 | 13.227 | 78.00 | 19.5 | 1.708 | 53.278 |
| Horror | Happy | stress | 59 | 47.012 | 15.657 | 90.00 | 11.0 | 2.038 | 47.556 |
Assumptions
Outliers
Identify outliers in each cell design:
table_outlier <- myData_cleaned %>%
group_by(music, image) %>%
identify_outliers(stress)
table_outlier %>%
kbl() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))| music | image | PID | stress | is.outlier | is.extreme |
|---|---|---|---|---|---|
| Disney | Happy | 15 | 18.66667 | TRUE | FALSE |
| Disney | Happy | 17 | 12.00000 | TRUE | FALSE |
| Disney | Happy | 21 | 5.00000 | TRUE | FALSE |
| Disney | Happy | 23 | 16.66667 | TRUE | FALSE |
| Horror | Happy | 1 | 90.00000 | TRUE | FALSE |
no extreme outlires detected in dataset
Normality check
table_normality <- myData_cleaned %>%
group_by(image,music) %>%
shapiro_test(stress)
table_normality %>%
kbl() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))| music | image | variable | statistic | p |
|---|---|---|---|---|
| Disney | Angry | stress | 0.9770062 | 0.3153384 |
| Horror | Angry | stress | 0.9845936 | 0.6489055 |
| Disney | Happy | stress | 0.9643932 | 0.0773124 |
| Horror | Happy | stress | 0.9877208 | 0.8158102 |
ggqqplot(myData_cleaned, "stress", ggtheme = theme_bw())+
facet_grid(image~music) normally distributed, shapiro test shows that for every group has p>0.05 so we cannot rejcet null hyphotesis, also on grpah it shows that all points are in normallity spectrum execpt detected outlier
Anova
res.aov <- myData_cleaned %>% anova_test(dv = stress,wid = PID, within = c(music,image))
res.aov %>%
kbl() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))| Effect | DFn | DFd | F | p | p<.05 | ges |
|---|---|---|---|---|---|---|
| music | 1 | 58 | 0.315 | 0.577 | 0.001 | |
| image | 1 | 58 | 2.027 | 0.160 | 0.011 | |
| music:image | 1 | 58 | 3.863 | 0.054 | 0.017 |
none of interaction is significant
Procedure for nonsignificant 2-way interaction
in ANOVA table we can see that neither of variables has signifficant effect on stress level so we do not need to do pairwise test
Conclusion
ggwithinstats(myData_cleaned,image,stress)ggwithinstats(myData_cleaned,music,stress)Data was normally distributed, it was proved using Shappior-Willks test and with plot, There was some outliers detected but none of them was extreme, outliers were detected with boxplot method Neither of 2-way interaction was significant as well as neither of variable was significant
Conclusion
Mean has no significant diffrence, image or music has no influence on sterss level