使用 R 包交互 (jtools) 对 merMod 对象进行简单斜率测试
Simple slopes test for merMod object with R package interactions (jtools)
我正在尝试对使用 lmer
获得的混合效应模型进行简单的斜率分析。
模型类似如下:
data(Orthodont,package="nlme")
mod <- lme4::lmer(distance ~ age*Sex + (1|Subject), data=Orthodont)
当尝试使用包 interactions
中的函数 sim_slopes
进行简单的斜率分析时,我收到以下错误消息。
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.
有没有人知道问题出在哪里?
请注意,它与包 reghelper
配合使用效果很好,但我需要这些测试的 p 值,reghelper
没有提供。
reghelper::simple_slopes(mod)
sessionInfo()
的输出是:
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.1
locale: [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=C
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.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
(不是答案,但对于评论来说太长了。如果合适,稍后会删除。)
在干净的 R 会话中,这对我有用:
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.
这是我的sessionInfo()
:重要的东西看起来和你的一样(lme4
1.1-21,interactions
1.1.0,jtools
2.0.1) , 但它肯定不相同...... ??
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
我通过分离 lmerTest 解决了这个问题。
我正在尝试对使用 lmer
获得的混合效应模型进行简单的斜率分析。
模型类似如下:
data(Orthodont,package="nlme")
mod <- lme4::lmer(distance ~ age*Sex + (1|Subject), data=Orthodont)
当尝试使用包 interactions
中的函数 sim_slopes
进行简单的斜率分析时,我收到以下错误消息。
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.
有没有人知道问题出在哪里?
请注意,它与包 reghelper
配合使用效果很好,但我需要这些测试的 p 值,reghelper
没有提供。
reghelper::simple_slopes(mod)
sessionInfo()
的输出是:
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
(不是答案,但对于评论来说太长了。如果合适,稍后会删除。)
在干净的 R 会话中,这对我有用:
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.
这是我的sessionInfo()
:重要的东西看起来和你的一样(lme4
1.1-21,interactions
1.1.0,jtools
2.0.1) , 但它肯定不相同...... ??
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
我通过分离 lmerTest 解决了这个问题。