Solved – Multiple measurements per trial in R

anovarepeated measures

Suppose I wish to assess reaction time of individuals before and after treatment, using R code.

Now to analyse the results if I had additional treatments, I could use repeated measurements ANOVA in R, using the aov() function. These approaches however assume that there is only one measurement of reaction time per person, per treatment.

However suppose that for each individual, we measure their reaction time 5 times before treatment and 5 times after treatment. How should I adjust the t-test or repeated measurements ANOVA to account for this?

I know I could simply average prior to analysis, but is it also possible to include all the 5 trials in the analysis in R and if so how ?

Note the data might look something like this:

Subject Treatment Time     Result
Subj1   Coke      Morning  15 
Subj1   Coke      Morning  14
Subj1   Water     Morning  17
Subj1   Water     Morning  20
Subj2   Coke      Morning  45
Subj2   Coke      Morning  46
Subj2   Water     Morning  58
Subj2   Water     Morning  75

Best Answer

Time to shine for afex (full disclosure: I am the author).

There are two options on what to do:

  1. As you said, use standard repeated measures ANOVA and aggregate over the measurements. afex offers a bunch of convenience functions automatically aggregating the data, e.g.,
    aov.car(Result ~ 1 + Error(Subj/Treatment*Time), data)
  2. Alternatively, you can use a linear mixed model which use all data points (i.e., data will not be aggregated) and use mixed which fits those via lme4::lmer and obtains p-values via pbkrtest::KRmodcomp:
    mixed(Result ~ Treatment*Time + (Treatment*Time|Subj), data

Note, both examples assume that Time has more than one level. IN case you use mixed models, it is a good idea to read something on them, see ?mixed for good starting points or search on CrossValidated.