I am struggling a bit in the implementation and interpretation of repeated-measures ANOVA in R. Lots of tutorials are available, but most of the time they deal with rather complicated schemes, thus after several hours of reading I am more confused than ever.

We have subjects, for which we measured a certain parameter (measured value) a 3 consecutive time points. My data looks like this:

Subject  Time  Measured.Value
   A       1          5
   A       2          7
   A       3          9
   B       1          6
   B       2          4
   B       3          8
   C       1          3
   C       2          5
   C       3          6    

I want to assess if the measured values are significantly different between time points. I used the following function in R:

my.data$Subject <- factor(my.data$Subject)
my.data$Time <- factor(my.data$Time)
my.aov <- with(my.data, aov(Measured.Value ~ Time + Error(Time)))

I am doing this right?


1 Answer 1


Your error term is not quite correct.

Assuming you've got a balanced design, the repeated measures ANOVA model using aov is

aov(Measured.Value ~ Time + Error(Subject/Time), data = my.data)

The term Error(Subject/Time) models the subject-specific variance; or in the language of mixed-effect models: Subject is your random and Time your fixed effect, and Time is nested (i.e. repeatedly measured) within Subject.

Two more comments:

  1. Keep in mind that aov only allows for random effects if the design is balanced (which is the case for the sample data you provide). If you've got an unbalanced design (e.g. due to missing observations), you will need to use a mixed-effect model.

  2. It's a bit odd to use ANOVA to model a time dependence. I am assuming here that Time is a categorical variable.

  • 1
    $\begingroup$ Thanks! I see the error and I will correct that in my model. Time is indeed a categorical variable: subjects have been sampled at 2 time points each, and the time points are the same for all subjects. $\endgroup$ Oct 17, 2018 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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