[R] [effects] Wrong xlevels in effects plot for mixed effects model when multiline = TRUE
John Fox
j|ox @end|ng |rom mcm@@ter@c@
Mon Nov 9 19:51:33 CET 2020
Dear Gerrit,
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,
Age=60:100))
plot(eff, lines=list(multiline=TRUE))
or
eff <- predictorEffect("Age", m, xlevels = list(gProt = 1:6 * 30))
plot(eff, lines=list(multiline=TRUE))
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
effect plots.
Finally, thank you for the bug report. Barring unforeseen difficulties,
we'll fix the bug in due course.
I hope this helps,
John
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/
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
> https://jlubox.uni-giessen.de/dl/fiSzTCc3bW8z2npZvPpqG1xr/m-and-G1.zip
> 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.
>
> library(effects)
> 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
>
>
> PS:
> > 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
>
> locale:
> [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
> [5] LC_TIME=German_Germany.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] effects_4.2-0 carData_3.0-4
>
> loaded via a namespace (and not attached):
> [1] Rcpp_1.0.5 lattice_0.20-41 MASS_7.3-53 grid_4.0.2
> DBI_1.1.0
> [6] nlme_3.1-149 survey_4.0 estimability_1.3 minqa_1.2.4
> nloptr_1.2.2.2
> [11] Matrix_1.2-18 boot_1.3-25 splines_4.0.2 statmod_1.4.34
> lme4_1.1-23
> [16] tools_4.0.2 survival_3.2-3 yaml_2.2.1 compiler_4.0.2
> colorspace_1.4-1
> [21] 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
> http://www.uni-giessen.de/eichner
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list