[R] [effects] Wrong xlevels in effects plot for mixed effects model when multiline = TRUE
j|ox @end|ng |rom mcm@@ter@c@
Mon Nov 9 19:51:33 CET 2020
This looks like a bug in plot.eff(), which I haven't yet tracked down,
but the following should give you what you want:
eff <- Effect(c("gProt", "Age"), m, xlevels = list(gProt = 1:6 * 30,
eff <- predictorEffect("Age", m, xlevels = list(gProt = 1:6 * 30))
A couple of comments on your code, unrelated to the bug in plot.eff():
You don't need allEffects() because there's only one high-order fixed
effect in the model, I(gProt/10 - 6.2):I(Age/10 - 7.2) (i.e., the
interaction of gProt with Age).
x.var isn't intended as an argument for plot() with allEffects() because
there generally isn't a common horizontal axis for all of the high-order
Finally, thank you for the bug report. Barring unforeseen difficulties,
we'll fix the bug in due course.
I hope this helps,
John Fox, Professor Emeritus
Hamilton, Ontario, Canada
On 2020-11-09 8:06 a.m., Gerrit Eichner wrote:
> Dear list members,
> I observe a strange/wrong graphical output when I set the xlevels
> in (e. g.) allEffects for an lmer model and plot the effects with
> multiline = TRUE. I have compiled a reprex for which you need the
> lmer model and the environment in which the model was fitted. They
> are contained in the zip file at
> After unpacking the following should work:
> m <- readRDS("m.rds") # The lmer-model.
> G1 <- readRDS("G1.rds") # Environment in which the model
> # was fitted; needed by alaEffects.
> summary(m) # Just to see the model.
> aE <- allEffects(m, xlevels = list(gProt = 1:6 * 30))
> # Non-default values for xlevels.
> plot(aE) # Fine.
> plot(aE, x.var = "Age") # Fine.
> plot(aE, lines = list(multiline = TRUE)) # Fine.
> plot(aE, lines = list(multiline = TRUE),
> x.var = "Age") # Nonsense.
> Anybody any idea about the reason, my mistake, or a
> workaround? Thx for any hint!
> Regards -- Gerrit
> > sessionInfo()
> R version 4.0.2 (2020-06-22)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 18363)
> Matrix products: default
>  LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
>  LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
>  LC_TIME=German_Germany.1252
> attached base packages:
>  stats graphics grDevices utils datasets methods base
> other attached packages:
>  effects_4.2-0 carData_3.0-4
> loaded via a namespace (and not attached):
>  Rcpp_1.0.5 lattice_0.20-41 MASS_7.3-53 grid_4.0.2
>  nlme_3.1-149 survey_4.0 estimability_1.3 minqa_1.2.4
>  Matrix_1.2-18 boot_1.3-25 splines_4.0.2 statmod_1.4.34
>  tools_4.0.2 survival_3.2-3 yaml_2.2.1 compiler_4.0.2
>  mitools_2.4 insight_0.9.5 nnet_7.3-14
> Dr. Gerrit Eichner Mathematical Institute, Room 212
> gerrit.eichner using math.uni-giessen.de Justus-Liebig-University Giessen
> Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help