Update May 2017: As it turns out, a lof of what I have written here is kind of wrongish. Some updates are made throughout the post.
I agree a lot with what has been said by Ben Bolker already (thanks for the shout-out to afex::mixed()
) but let me add a few more general and specific thoughts on this issue.
Focus on fixed versus random effects and how to report results
For the type of experimental research that is represented in the example data set from Jonathan Baron you use the important question is usually whether or not a manipulated factor has an overall effect. For example, do we find an overall main effect or interaction of Task
? An important point is that in those data sets usually all factors are under complete experimental control and randomly assigned. Consequently, the focus of interest is usually on the fixed effects.
In contrast, the random effects components can be seen as "nuisance" parameters that capture systematic variance (i.e., inter-individual differences in the size of the effect) that are not necessarily important for the main question. From this point of view the suggestion of using the maximal random effects structure as advocated by Barr et al. follows somewhat naturally. It is easy to imagine that an experimental manipulation does not affect all individuals in the exact same way and we want to control for this. On the other hand, the number of factors or levels is usually not too large so that the danger of overfitting seems comparatively small.
Consequently, I would follow the suggestion of Barr et al. and specify a maximal random effects structure and report tests of the fixed effects as my main results. To test the fixed effects I would also suggest to use afex::mixed()
as it reports tests of effects or factors (instead of test of parameters) and calculates those tests in a somewhat sensible way (e.g., uses the same random effects structure for all models in which a single effect is removed, uses sum-to-zero-contrasts, offers different methods to calculate p-values, ...).
What about the example data
The problem with the example data you gave is that for this dataset the maximal random effects structure leads to an oversaturated model as there is only one data point per cell of the design:
> with(df, table(Valence, Subject, Task))
, , Task = Cued
Subject
Valence Faye Jason Jim Ron Victor
Neg 1 1 1 1 1
Neu 1 1 1 1 1
Pos 1 1 1 1 1
, , Task = Free
Subject
Valence Faye Jason Jim Ron Victor
Neg 1 1 1 1 1
Neu 1 1 1 1 1
Pos 1 1 1 1 1
Consequently, lmer
chokes on the maximal random effects structure:
> lmer(Recall~Task*Valence + (Valence*Task|Subject), df)
Error: number of observations (=30) <= number of random effects (=30) for term
(Valence * Task | Subject); the random-effects parameters and the residual variance
(or scale parameter) are probably unidentifiable
Unfortunately, there is to my knowledge no agreed upon way to deal with this problem. But let me sketch and discuss some:
A first solution could be to remove the highest random slope and test the effects for this model:
require(afex)
mixed(Recall~Task*Valence + (Valence+Task|Subject), df)
Effect F ndf ddf F.scaling p.value
1 Task 6.56 1 4.00 1.00 .06
2 Valence 0.80 2 3.00 0.75 .53
3 Task:Valence 0.42 2 8.00 1.00 .67
However, this solution is a little ad-hoc and not overly motivated.
Update May 2017: This is the approach I am currently endorsing. See this blog post and the draft of the chapter I am co-authoring, section "Random Effects Structures for Traditional ANOVA Designs".
An alternative solution (and one that could be seen as advocated by Barr et al.'s discussion) could be to always remove the random slopes for the smallest effect. This has two problems though: (1) Which random effects structure do we use to find out what the smallest effect is and (2) R is reluctant to remove a lower-order effect such as a main effect if higher order effects such as an interaction of this effect is present (see here). As a consequence one would need to set up this random effects structure by hand and pass the so constructed model matrix to the lmer call.
A third solution could be to use an alternative parametrization of the random effects part, namely one that corresponds to the RM-ANOVA model for this data. Unfortunately (?), lmer
doesn't allow "negative variances" so this parameterization doesn't exactly correspond to the RM-ANOVA for all data sets, see discussion here and elsewhere (e.g. here and here). The "lmer-ANOVA" for these data would be:
> mixed(Recall~Task*Valence + (1|Subject) + (1|Task:Subject) + (1|Valence:Subject), df)
Effect F ndf ddf F.scaling p.value
1 Task 7.35 1 4.00 1.00 .05
2 Valence 1.46 2 8.00 1.00 .29
3 Task:Valence 0.29 2 8.00 1.00 .76
Given all this problems I simply wouldn't use lmer
for fitting data sets for which there is only one data point per cell of the design unless a more agreed upon solution for the problem of the maximal random effects structure is available.
Instead, I would One also could still use the classical ANOVA. Using one of the wrappers to car::Anova()
in afex
the results would be:
> aov4(Recall~Task*Valence + (Valence*Task|Subject), df)
Effect df MSE F ges p
1 Valence 1.44, 5.75 4.67 1.46 .02 .29
2 Task 1, 4 4.08 7.35 + .07 .05
3 Valence:Task 1.63, 6.52 2.96 0.29 .003 .71
Note that afex
now also allows to return the model fitted with aov
which can be passed to lsmeans
for post-hoc tests (but for test of effects the ones reported by car::Anova
are still more reasonable):
> require(lsmeans)
> m <- aov4(Recall~Task*Valence + (Valence*Task|Subject), df, return = "aov")
> lsmeans(m, ~Task+Valence)
Task Valence lsmean SE df lower.CL upper.CL
Cued Neg 11.8 1.852026 5.52 7.17157 16.42843
Free Neg 10.2 1.852026 5.52 5.57157 14.82843
Cued Neu 13.0 1.852026 5.52 8.37157 17.62843
Free Neu 11.2 1.852026 5.52 6.57157 15.82843
Cued Pos 13.6 1.852026 5.52 8.97157 18.22843
Free Pos 11.0 1.852026 5.52 6.37157 15.62843
Confidence level used: 0.95