# Multiple measurements per trial in R

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

• I am thinking of possibly doing a randomized block design, and treating each of the 5 trials as blocks. Is this approach statistically sound? – Kenshin Apr 7 '14 at 2:07
• Or can I simply have multiple rows in R with the same subject-treatment combination. Will this be handled correctly with the aov() or lm() function? – Kenshin Apr 8 '14 at 7:08
• Hey Mew, what is the problem with my answer? It answers your questions. The thing is it is not working with just aov, you need something else. – Henrik Apr 15 '14 at 8:13

Time to shine for afex (full disclosure: I am the author).
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.