# Random effects specification for within-subjects design

I am measuring response times in a behavioral task. The study design has two within-subjects factors: Context (high/low) and Condition (easy/medium/hard). I want to include random intercepts and slopes for both main effects as well as the highest-order within-subjects interaction term (as advised in Barr, 2013). Here is how I have specified my model:

m.1 <- glmer(RT ~ Context * Condition + (1+Context*Condition|Subject),
family = Gamma, data = df, control=glmerControl(optimizer="nloptwrap2"))


However, I am having some trouble understanding how the above model (m.1) differs from the following model specification (m.2)

m.2 <- glmer(RT ~ Context * Condition + (1|Subject) + (1|Subject:Condition) +
(1|Subject:Context) + (1|Subject:Context:Condition),
family = Gamma, data = df, control=glmerControl(optimizer="nloptwrap2"))


Specifically, because this is a fully within-subjects design, I do not understand why the following random effect terms are not essentially equivalent (i.e., both allowing the effect of Condition to vary across Subjects):

(1|Subject:Condition)
(1+Condition|Subject)


Update: As requested by amoeba, here are random effect variance estimates from each model (n.b. 'Group' factor = 'Context'):

m.1

Random effects:
Groups   Name              Variance  Std.Dev. Corr
Subject  (Intercept)       0.0022827 0.04778
Condition1        0.0004068 0.02017  -0.24
Condition2        0.0001646 0.01283   0.36 -0.69
Group1            0.0004263 0.02065  -0.20  0.04 -0.08
Condition1:Group1 0.0002221 0.01490  -0.22 -0.19  0.21  0.65
Condition2:Group1 0.0001072 0.01035   0.32  0.18 -0.40 -0.39 -0.71
Residual                   0.0321836 0.17940
Number of obs: 1445, groups:  Subject, 25


m.2

Random effects:
Groups                  Name        Variance  Std.Dev.
Subject:Group:Condition (Intercept) 0.0003518 0.01876
Subject:Condition       (Intercept) 0.0001530 0.01237
Subject:Group           (Intercept) 0.0005468 0.02338
Subject                 (Intercept) 0.0020285 0.04504
Residual                            0.0325439 0.18040
Number of obs: 1445, groups:  Subject:Group:Condition, 144;     Subject:Condition, 75; Subject:Group, 49; Subject, 25

• +1. Have you verified that these terms are not equivalent, or are you just assuming that they are not? It might help if you included the output of these models on your data showing that you get different results. I have recently asked a (long-ish) question that is basically about this very issue: stats.stackexchange.com/questions/232109. Unfortunately there is no satisfactory answer, and I've been planning to write an answer myself based on what I understood since then, but did not get to it yet. Still, you might find a lot of further links there, some of them useful. – amoeba Dec 1 '16 at 21:15
• Here is what I believe might be a direct answer to your question: (1|Subject)+(1|Subject:Condition) estimates two variance parameters and nothing else. In contrast, (1+Condition|Subject) estimates 3 variance parameters (because your Condition has 3 levels) plus 3 correlations between them. Even if you wrote (1|Subject)+(0+Condition|Subject) you would still get 3 variance parameters and 1 correlation between 2 variances coming from Condition levels. You should get more similar results with Context instead of Condition because it only has 2 levels, not 3. – amoeba Dec 1 '16 at 21:20
• amoeba, I hope my edit answers the question in your first comment. – Rmg Dec 1 '16 at 21:46
• Your explanation makes sense in terms of the number of random effect parameters that are estimated in each model. I'm still a little confused about which syntax is most sensible though. Perhaps it (at least in part) boils down to whether I would like to include random effects for the correlations between parameters. Thank you for sharing your link - I will have a read to see if it clears anything up for me. – Rmg Dec 1 '16 at 21:55
• Thanks for the update, it confirms what I wrote above. Note that it's not only the presence/absence of correlations: the number of variance parameters also changes. What is more sensible is a difficult question and a matter of opinion. If you go with the Barr2013 "make it maximal" advice, then I guess you should prefer the first syntax as it's much more flexible. If you want to stay close to the classical repeated-measures ANOVA framework, then it's the second syntax. – amoeba Dec 1 '16 at 22:25