Thanks to @amoeba and using @BenBolker's brief remark here
Extensions such as allowing different residual variances or different variance-covariance matrices of random effects per (fixed-effect) group can be achieved, somewhat clunkily, by using the dummy()
helper function to construct an indicator variable to multiply by individual levels of interest.
we got to the bottom of the problem.
The solution is following:
Y ~ X*Condition +
(X*Condition | Subject) +
(0 + dummy(Condition, "A") + X:dummy(Condition, "A") | Trial) +
(0 + dummy(Condition, "B") + X:dummy(Condition, "B") | Trial)
The summary(model)
in random effects yields:
Groups Name Variance Std.Dev. Corr
subject (Intercept) 0.89343 0.9452
X 0.11695 0.3420 -0.85
ConditionB 0.66731 0.8169 -0.33 0.06
X:ConditionB 0.07391 0.2719 0.34 -0.05 -0.47
Trial dummy(Condition, "A") 0.63854 0.7991
dummy(Condition, "A"):X 0.09372 0.3061 -0.76
Trial.1 dummy(Condition, "B") 0.88833 0.9425
dummy(Condition, "B"):X 0.12175 0.3489 -0.60
which now makes perfect sense, because only correlations that can be calculated are between intercepts and slopes for a certain condition (because they are estimated for the same trials). Correlations between Conditions are senseless.
Furthermore, coef(model)$Trial
now shows logical values:
dummy(Condition, "A") dummy(Condition, "A"):X dummy(Condition, "B") dummy(Condition, "B"):X (Intercept) X ConditionB X:ConditionB
A1 0.9198822 0.0209849 0 0 2.703544 -0.9929765 -0.07102448 0.2415836
A2 -1.3029020 0.3894812 0 0 2.703544 -0.9929765 -0.07102448 0.2415836
A3 1.1294702 -0.2475288 0 0 2.703544 -0.9929765 -0.07102448 0.2415836
B1 0.000000000 0.0000000000 1.21725268 -0.305314643 2.703544 -0.9929765 -0.07102448 0.2415836
B2 0.000000000 0.0000000000 0.88317976 -0.209529267 2.703544 -0.9929765 -0.07102448 0.2415836
B3 0.000000000 0.0000000000 0.27859781 -0.065708851 2.703544 -0.9929765 -0.07102448 0.2415836
- Fixed effects are the same for all trials
- dummy(Condition, "A") intercepts and dummy(Condition, "A"):X slopes are calculated only for Condition A, in Condition B trials they are estimated to be 0, and vice versa.
N.B. When specifying random effects for this purpose, it is important to:
- specify random effects for different groups of trials independently, not under the same
|Trial
. If you don't do that, lme4
will estimate random effects for all trials, not just for the given condition.
- include 0, so as to prevent
lme4
from including a general random intercept across all trials.