# Linear mixed effect model - Single Trials vs Aggregation [duplicate]

I have a repeated measures design with two factors (A,B). For each subject, variable C is measured 7 to 10 times in each combination of A and B.

What I usually did was do first calculate the mean across for each combination of A and B for each participants and calculated my model with:

lmer(C~A+B+(1|Subject) # I assume A and B to not interact with each other


However, one reviewer asked me to use individual trials instead of the mean for each subject and combination of A and B.

But I don't know how to create such a model. Is it the same as the one written above but without calculating the mean first? Or do I have to specify the trials as some kind of random factor? I do not assume that there is a trend over time in my trials for each combination of A and B. So at best their variation (I am not sure if the assumption can be made, that they are normally distributed, but might be the case) should somehow be included for each subject and each combination of A and B.

## marked as duplicate by kjetil b halvorsen, Peter Flom - Reinstate Monica♦Jul 26 at 12:31

To use individual trials, you will first need to set up your data properly. For example, if your factors A and B have two levels each, then:

Subject    Trial   A    B     C

1         1     A1   B1   24
1         1     A1   B2   20
1         1     A2   B1   18
1         1     A2   B2   21
1         2     A1   B1   17
1         2     A1   B2   23
1         2     A2   B1   25
1         2     A2   B2   19
Etc.


This layout assumes that a trial is a repetition which involves the same participant going through all possible combinations of levels of A (i.e., A1 and A2) and levels of B (i.e., B1 and B2) to generate a set of C values. (In the above, I used some toy values for C.)

Once the data are set up properly, you can convert Subject and Trial to factors in R and then fit a model like this:

lmer(C ~ A + B + (1|Subject)


This model formulation uses Subject as a random grouping factor.

• Thank you for the answer, it looks quite useful to me. But just to make sure: If I create a factor out of trial, it does not assume some relationships i dont want to include (I will shorten Trial with T, Subject with S). For example S1T1A1B1 is not more related to S2T1A1B1 than to S2T2A1B1. And similarly S1T1A1B1 is not more related to S1T1A1B1 than to S1T2A1B1. Is this correct? In other words instead of using the correct Trial number, i could easily use the row number, and the result would be identical? – Mr Pi Jul 24 at 16:53
• I tried my last idea, it did not yield the same results. In fact the row number approach could not be calculated. Therefore I have to assume, that same factor levels of different combinations are in fact related and that is something I do not want – Mr Pi Jul 24 at 17:11
• @MrPi: Your questions prompted me to check in with other statisticians on how one should analyze data such as yours. The answers I received suggested that we should include Subject as a random effect (but not Trial), so I edited my answer above to reflect that. – Isabella Ghement Jul 29 at 14:59
• Thank you, its great we reached the same conclusion. I like having a second opinion :-) As your answer is more detailed than mine, i set yours as the accepted answer and removed mine. – Mr Pi Jul 30 at 7:07