The data correspond to an experiment in which a treatment for depression is studied. Two groups of patients - control ("ctr") and treatment ("treated") - have been followed at four different time points: t0 (pre-test) and three post-test follow-up measurements (t1, t2, t3). The dependent variable is a depression score.
Repeated measures ANOVA can be performed in order to determine the effect of the treatment and the effect of time on the depression score.
For a worked tutorial on this analysis, see the Datanovia lesson “Mixed ANOVA in R: One Between- and One Within-Subjects Factor” (https://www.datanovia.com/learn/biostatistics/anova/mixed-anova-in-r).
data("depression")A data frame with 24 rows and 6 columns (stored as a tibble).
participant identifier (1 to 24).
the treatment group, "ctr" (control) or "treated".
the depression score at pre-test.
the depression score at the first post-test follow-up.
the depression score at the second post-test follow-up.
the depression score at the third post-test follow-up.
The depression score is a simulated measure on an arbitrary scale with no real-world units.
A simulated dataset created for teaching two-way mixed ANOVA.
Datanovia tutorial: Mixed ANOVA in R: One Between- and One Within-Subjects Factor.
data(depression)
head(depression)
#> # A tibble: 6 × 6
#> id treatment t0 t1 t2 t3
#> <fct> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 1 ctr 296 175 187 242
#> 2 2 ctr 376 329 236 126
#> 3 3 ctr 309 238 150 173
#> 4 4 ctr 222 60 82 135
#> 5 5 ctr 150 271 250 266
#> 6 6 ctr 316 291 238 194
# Two-way mixed ANOVA: treatment (between) x time (within)
depression_long <- reshape(depression, varying = c("t0", "t1", "t2", "t3"),
v.names = "score", timevar = "time",
direction = "long")
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
#> Warning: number of items to replace is not a multiple of replacement length
summary(aov(score ~ treatment * factor(time) + Error(factor(id)/factor(time)),
data = depression_long))
#> Warning: Error() model is singular
#>
#> Error: factor(id)
#> Df Sum Sq Mean Sq F value Pr(>F)
#> treatment 1 11 11 0.002 0.967
#> factor(time) 1 17550 17550 2.871 0.107
#> Residuals 18 110034 6113
#>
#> Error: factor(id):factor(time)
#> Df Sum Sq Mean Sq
#> factor(time) 3 9274 3091