Closed singmann closed 3 years ago
Hey @singmann, sorry if this is an obvious question, I am new to R and statistics in general.. I just bumped into this issue, having even more deviating results than in your example (highly significant v.s not significant at all). I was wondering, which result is correct, after all? Best regards, Mischa
The issue above comes from refit = TRUE
versus refit = FALSE
. For afex
mixed
objects the default is refit = FALSE
, whereas for lme4
objects the default is refit = TRUE
(as can be seen by the message "refitting model(s) with ML (instead of REML)").
What is correct, depends on your use case. If the models differ in their fixed effects structure and they were fit with REML (instead of ML) then refit = TRUE
has to be the case.
However, in the present example the fixed effects structure is the same, so the anova()
results from afex
mixed
objects are correct and can be replicated with lme4
if refit = FALSE
:
anova(m1$full_model, m2$full_model, refit = FALSE)
# Data: data
# Models:
# m2$full_model: score ~ Machine + (1 + re1.Machine1 + re1.Machine2 || Worker)
# m1$full_model: score ~ Machine + (Machine | Worker)
# npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
# m2$full_model 7 233.75 247.67 -109.88 219.75
# m1$full_model 10 230.51 250.40 -105.25 210.51 9.2424 3 0.02624
#
# m2$full_model
# m1$full_model *
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
So this issue shows actually expected behaviour and should probably be closed.
See also the comments on ?anova.merMod
:
refit
: logical indicating if objects of class lmerMod should be refitted with ML before comparing models. The default is TRUE to prevent the common mistake of inappropriately comparing REML-fitted models with different fixed effects, whose likelihoods are not directly comparable.
Commenting because I just ran into the same 'issue' - I do wonder if it isn't reasonable to match the defaults of anova.merMod
, or at least add a warning, either when calling the function or in some documentation, rather than silently using the opposite behaviour. I must admit that when I used the anova
call on two mixed
objects and it ran without issue I (perhaps foolishly) assumed it was simply forwarding the .$full_model
field to anova.merMod
, especially because anova.mixed
doesn't have any documentation. I only figured out there even was an anova.mixed
method by calling methods(anova)
, and only found out about the refit option by going into the source code in this repo.
Maybe my use case isn't the default though, I understand if you think differently about this!
Created on 2020-12-02 by the reprex package (v0.3.0)