问题
I'm trying to conduct a simple slopes analysis for a mixed effects model obtained with lmer
.
The model is similar to the following:
data(Orthodont,package="nlme")
mod <- lme4::lmer(distance ~ age*Sex + (1|Subject), data=Orthodont)
When trying to conduct a simple slopes analysis with the function sim_slopes
in the package interactions
, I obtain the following error message.
interactions::sim_slopes(model=mod, pred=age, modx=Sex)
Error: One of the requested columns does not exist.
Backtrace:
1. interactions::sim_slopes(model = mod, pred = age, modx = Sex)
5. jtools:::summ.merMod(...)
6. jtools:::create_table(...)
In addition: Warning message:
Johnson-Neyman intervals are not available for factor moderators.
Would any one have any thoughts on what the problem might be?
Note that it works well with the package reghelper
, but I need p values for these tests, which reghelper
does not provide.
reghelper::simple_slopes(mod)
The output of sessionInfo()
is:
R version 3.6.0 (2019-04-26) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.2 LTS
Matrix products: default BLAS:
/usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C
LC_TIME=en_CA.UTF-8 [4] LC_COLLATE=en_CA.UTF-8
LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=Cattached base packages: [1] stats graphics grDevices utils
datasets methods baseloaded via a namespace (and not attached):
[1] Rcpp_1.0.1 magrittr_1.5 splines_3.6.0 MASS_7.3-51.1
[5] munsell_0.5.0 colorspace_1.4-1 lattice_0.20-38 rlang_0.3.4
[9] minqa_1.2.4 plyr_1.8.4 tools_3.6.0 grid_3.6.0
[13] gtable_0.3.0 nlme_3.1-140 cli_1.1.0 assertthat_0.2.1
[17] digest_0.6.19 lme4_1.1-21 lazyeval_0.2.2 tibble_2.1.2
[21] crayon_1.3.4 Matrix_1.2-17 reghelper_0.3.4 nloptr_1.2.1[25] ggplot2_3.1.1 interactions_1.1.0 jtools_2.0.1 pander_0.6.3
[29] compiler_3.6.0 pillar_1.4.1 scales_1.0.0 boot_1.3-20
[33] pkgconfig_2.0.2
回答1:
I solved the problem by detaching lmerTest.
回答2:
(Not an answer but way too long for a comment. Will delete later if appropriate.)
In a clean R session, this works for me:
data(Orthodont,package="nlme")
mod <- lme4::lmer(distance ~ age*Sex + (1|Subject), data=Orthodont)
interactions::sim_slopes(model=mod, pred=age, modx=Sex)
sessionInfo()
SIMPLE SLOPES ANALYSIS
Slope of age when Sex = Female:
Est. S.E. t val. p
------ ------ -------- ------
0.48 0.09 5.13 0.00
Slope of age when Sex = Male:
Est. S.E. t val. p
------ ------ -------- ------
0.78 0.08 10.12 0.00
Warning message: Johnson-Neyman intervals are not available for factor moderators.
Here is my sessionInfo()
: the important stuff looks the same as yours (lme4
1.1-21, interactions
1.1.0, jtools
2.0.1), but it's certainly not identical ... ??
R Under development (unstable) (2019-05-21 r76566)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS
[matrix product and locale info deleted]
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 magrittr_1.5 splines_3.7.0 MASS_7.3-51.4
[5] tidyselect_0.2.5 munsell_0.5.0 colorspace_1.4-1 lattice_0.20-38
[9] R6_2.4.0 rlang_0.3.4 minqa_1.2.4 plyr_1.8.4
[13] dplyr_0.8.1 tools_3.7.0 grid_3.7.0 gtable_0.3.0
[17] nlme_3.1-140 cli_1.1.0 digest_0.6.19 assertthat_0.2.1
[21] lme4_1.1-21 lazyeval_0.2.2 tibble_2.1.2 numDeriv_2016.8-1
[25] crayon_1.3.4 Matrix_1.2-17 purrr_0.3.2 nloptr_1.2.1
[29] ggplot2_3.1.1 jtools_2.0.1 interactions_1.1.0 glue_1.3.1
[33] pander_0.6.3 compiler_3.7.0 pillar_1.4.1 scales_1.0.0
[37] lmerTest_3.1-0 boot_1.3-22 pkgconfig_2.0.2
来源:https://stackoverflow.com/questions/56401996/simple-slopes-test-for-mermod-object-with-r-package-interactions-jtools