Error: $ operator not defined for this S4 class when trying to run vuong() function

Error: $ operator not defined for this S4 class when trying to run vuong() function

我正在尝试 运行 使用 pscl 中的 vuong() 函数进行 Vuong 测试,以比较两个使用相同数据的 lmer() 模型。但是,每次我 运行 它时,我都会收到以下错误消息:

> vuong(mod1, mod2)
Error: $ operator not defined for this S4 class

我已经尝试重新启动 R 并更新我的包,但我仍然遇到同样的错误。

这些是我加载的包:

# ---- Load libraries ----
library(ggplot2)
library(pscl)
library(lmtest)
library(lme4)
library(car)

这是我的R版本 运行ning:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=C                    LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] car_3.0-11    carData_3.0-4 lme4_1.1-27   Matrix_1.2-18 lmtest_0.9-38 zoo_1.8-9     pscl_1.5.5    ggplot2_3.3.5

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1  purrr_0.3.4       splines_4.0.2     haven_2.4.3       lattice_0.20-41   colorspace_2.0-2 
 [7] vctrs_0.3.8       generics_0.1.0    mgcv_1.8-31       utf8_1.2.2        rlang_0.4.11      nloptr_1.2.2.2   
[13] pillar_1.6.3      foreign_0.8-80    glue_1.4.2        withr_2.4.2       DBI_1.1.1         readxl_1.3.1     
[19] lifecycle_1.0.1   munsell_0.5.0     gtable_0.3.0      cellranger_1.1.0  zip_2.2.0         labeling_0.4.2   
[25] rio_0.5.27        forcats_0.5.1     curl_4.3.2        fansi_0.5.0       Rcpp_1.0.6        scales_1.1.1     
[31] abind_1.4-5       farver_2.1.0      digest_0.6.28     hms_1.1.1         stringi_1.7.4     openxlsx_4.2.4   
[37] dplyr_1.0.7       grid_4.0.2        tools_4.0.2       magrittr_2.0.1    tibble_3.1.4      crayon_1.4.1     
[43] pkgconfig_2.0.3   MASS_7.3-51.6     ellipsis_0.3.2    data.table_1.14.2 assertthat_0.2.1  minqa_1.2.4      
[49] R6_2.5.1          boot_1.3-25       nlme_3.1-148      compiler_4.0.2 

是不是我加载的包有问题导致这个功能无法使用?或者我可以尝试解决此问题的其他解决方案吗?

我也尝试了 运行 其他模型类型(例如 lm instear of lmer),但所有组合 return 都出现相同的错误,所以我不怀疑它与数据有关 and/or型号。

如有任何帮助,我们将不胜感激!

如您所见,pscl::vuong 不适用于 lmer 型号。

有一个 nonnest 包具有 vuongtest 功能。来自该帮助页面中的示例:

## Supplying custom vcov function
require(lme4)
require(merDeriv)

fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy, REML=FALSE)
fm2 <- lmer(Reaction ~ Days + (Days || Subject), sleepstudy, REML=FALSE)

vcl <- function(obj) vcov(obj, full=TRUE)
vuongtest(fm1, fm2, vc1=vcl, vc2=vcl, nested=TRUE)