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)
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.)

If you do wish to account for differences among subjects (as is good practice if individual subjects were presented with multiple tests) then you should be including subjects as random effects. The lme4 package is a popular way to include both fixed and random effects in a model. See this page and this page for useful help on how to specify your models. With proper coding, the programs in that package can figure out the between/within groupings and analyze the data accordingly.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.