I am not sure whether I should use a within only or mixed between-within design for ANOVA in the following case. I have 6 patients who all received two treatments. During the treatment the dependent variable is recorded three times at fixed intervalls. Obviously
Time is a within predictor, but what about
Treatment? I am interested in the difference between the treatments so it might be a between predictor, however because each patient receives both treatments there might be a correlation between the DV for each timepoint within the patients. How can I account for this?
Here is an example dataset:
df <- data.frame(Patient = as.factor(rep(1:3, each=6)), Treatment = as.factor(rep(rep(1:2, each=3), 3)), Time = as.factor(rep(1:3, 6)), DV = c(rnorm(3, 3, 1),rnorm(3, 3.5, 1.2), rnorm(3, 3, 1),rnorm(3, 3.5, 1.2), rnorm(3, 3, 1),rnorm(3, 3.5, 1.2)))
so the data for the first patient looks like:
> head(df) Patient Treatment Time DV 1 1 1 1 2.957971 2 1 1 2 4.232659 3 1 1 3 1.566545 4 1 2 1 3.674350 5 1 2 2 3.222795 6 1 2 3 1.979652
Here is how I used the function
library(ez) # within-only df$wid <- as.factor(paste(df$Patient, df$Treatment, sep=".")) mod1 <- ezANOVA(data = df, dv = DV, wid = wid, within = .(Time, Treatment)) # mixed withind and between mod2 <- ezANOVA(data = df, dv = DV, wid = Patient, within = Time, between = Treatment.) # this doens't work ("One or more cells is missing data.") mod3 <- ezANOVA(data = df, dv = DV, wid = wid, within = .(Time, Treatment), between = Treatment) mod3 <- ezANOVA(data = df, dv = DV, wid = Patient, within = .(Time, Treatment), between = Treatment)
Which one is right? Am I right to be worried about this second within correlation for treatments?
Bonus question: how can I access the model residuals with
ezANOVA? The returned objects do not contain an
aov object, only the tests results:
names(mod1)  "ANOVA" "Mauchly's Test for Sphericity" "Sphericity Corrections"
Suggestions for other packages are also welcome.