#————————————————————————————————————————————————————————————————————————————
# Within-Subject Analysis of Variance
# Data frame
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 1a: Within-Subject ANOVA
aov.w(cbind(time1, time2, time3) ~ 1, data = dat)
# Example 1b: Within-Subject ANOVA
# Print descriptive statistics and Paired-samples t-tests
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, descript = TRUE, posthoc = TRUE)
# Example 1c: Within-Subject ANOVA, print eta-squared and omega-squared
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, effsize = TRUE)
#————————————————————————————————————————————————————————————————————————————
# Plot
# Example 2a: Plot results, default setting
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, plot = TRUE)
# Example 2b: Plot results
# No bars, jittered data points without subject-specific lines
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, plot = TRUE,
line = FALSE, jitter = TRUE)
# Example 2c: Plot results using the plot() function, use additional arguments
# see Details in the help page of the function plot.misty.object
object <- aov.w(cbind(time1, time2, time3) ~ 1, data = dat)
plot(object, jitter = TRUE, jitter.alpha = 0.4, title = "Within-Subject ANOVA")
#————————————————————————————————————————————————————————————————————————————
# Create Plot Manually
# Load ggplot2 package
library(ggplot2)
# Create misty object
object <- aov.w(cbind(time1, time2, time3) ~ 1, data = dat)
# Compute Means and difference-adjusted confidence intervals
ci.table <- ci.mean.w(object$data$wide, adjust = TRUE, output = FALSE)$result
# Example 3: Plot
ggplot(object$data$long, aes(time, y, group = 1)) +
geom_errorbar(data = ci.table, aes(variable, m, ymin = low, ymax = upp),
width = 0.1) +
geom_point(data = ci.table, aes(variable, m), stat = "identity", size = 3) +
geom_line(data = ci.table, aes(variable, m), stat = "identity") +
geom_jitter(alpha = 0.2, width = 0.05, height = 0, size = 1.25) +
theme_bw()
#————————————————————————————————————————————————————————————————————————————
# Write Results and Save Plot
if (FALSE) {
# Example 4a: Write results into a text file
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, write = "RM-ANOVA.txt")
# Example 4b: Write results into an Excel file
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, write = "RM-ANOVA.xlsx")
# Example 4c: Save plot as PNG fine
aov.w(cbind(time1, time2, time3) ~ 1, data = dat, plot = TRUE,
filename = "RM-ANOVA.png", width = 6, height = 5)
}
Run the code above in your browser using DataLab