dat <- data.frame(time1 = c(3, 2, 1, 4, 5, 2, 3, 5, 6, 7),
time2 = c(4, 3, 6, 5, 8, 6, 7, 3, 4, 5),
time3 = c(1, 2, 2, 3, 6, 5, 1, 2, 4, 6))
# Example 1: Repeated measures ANOVA
aov.w(cbind(time1, time2, time3) ~ 1, data = dat)
# Example 2: Repeated measures ANOVA
# print results based on all sphericity corrections
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, print = "all")
# Example 3: Repeated measures ANOVA
# print effect size measures
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, effsize = TRUE)
# Example 4: Repeated measures ANOVA
# do not print hypotheses and descriptive statistics,
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, descript = FALSE, hypo = FALSE)
if (FALSE) {
# Example 5: Write results into a text file
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, write = "RM-ANOVA.txt")}
# Example 6: Repeated measures ANOVA
# plot results
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, plot = TRUE)
# Load ggplot2 package
library(ggplot2)
if (FALSE) {
# Save plot, ggsave() from the ggplot2 package
ggsave("Repeated_measures_ANOVA.png", dpi = 600, width = 4.5, height = 4)}
# Example 7: Repeated measures ANOVA
# extract plot
p <- aov.w(cbind(time1, time2, time3) ~ 1, data = dat, output = FALSE)$plot
p
# Extract data
plotdat <- aov.w(cbind(time1, time2, time3) ~ 1, data = dat, output = FALSE)$data
# Draw plot in line with the default setting of aov.w()
ggplot(plotdat$long, aes(time, y, group = 1L)) +
geom_point(aes(time, y, group = id),
alpha = 0.1, position = position_dodge(0.05)) +
geom_line(aes(time, y, group = id),
alpha = 0.1, position = position_dodge(0.05)) +
geom_point(data = plotdat$ci, aes(variable, m), stat = "identity", size = 4) +
stat_summary(aes(time, y), fun = mean, geom = "line") +
geom_errorbar(data = plotdat$ci, aes(variable, m, ymin = low, ymax = upp), width = 0.1) +
theme_bw() + xlab(NULL) +
labs(subtitle = "Two-Sided Confidence Interval") +
theme(plot.subtitle = element_text(hjust = 0.5),
plot.title = element_text(hjust = 0.5))
Run the code above in your browser using DataLab