# Two-way ANCOVA with a between-subject variable in R

I have a dataset with a 2x2x2 design: Group (CTL vs. SC) x Session (Sess 1 vs. Sess 2) x Treatment (Treat vs. Placebo). The dependent variable is Response Time. I also have a variable Age. I would like to do an ANCOVA using Age as a covariate. To visualize data:

input <- mydata[,c("Group","Treatment","Session","ResponseTime","Age")]

Group Treatment      Session   ResponseTime   Age
<chr> <chr>        <chr>     <dbl>          <dbl>
1 CTL   Placebo      Sess1     0.0126         53
2 CTL   Placebo      Sess1     0.0480         30
3 CTL   Placebo      Sess1     0.0318         58
4 CTL   Placebo      Sess1     0.747          28
5 CTL   Placebo      Sess2     0.150          28
6 CTL   Placebo      Sess2     0.0149         41
...


Using example from this, I did the following:

options(contrasts = c("contr.treatment", "contr.poly"))

model.1 = lm (Value ~ Group*Session*Treatment + Age + Group:Session:Treatment,
data = mydata)
library(car)
Anova(model.1, type="II")


I'm unclear whether I placed Group where it belongs as it is a between- not within-subject variable. I think Age is used correctly as a covariate here but could someone take a quick look at let me know whether this is correct?

The way that you have modeled your data includes no subject identifiers at all; age might be specific to an individual but it does not by itself identify one. So your model doesn't involve any within-subject analyses; it effectively assumes that each observation is independent. If you think that's the correct way to proceed, then your model is OK. (Note that your inclusion of the 3-way Group:Session:Treatment interaction in the formula wasn't needed as the specification of Group*Session*Treatment automatically generates that interaction along with all the 2-way interactions.)