glmmTMB拟合Gamma/ziGamma模型时负对数似然NaN错误求助
glmmTMB拟合Gamma/ziGamma模型时负对数似然NaN错误的解决方案求助
在使用glmmTMB包拟合Gamma族模型时,遇到如下错误:
Error in fitTMB(TMBStruc) : negative log-likelihood is NaN at starting parameter values
复现代码
1. Gamma族模型报错
testdata<-data.frame(DV=1+sample(0:100), pred=sample(-50:50)) hmod<-glmmTMB(formula=DV~pred, data=testdata,family=Gamma)
错误信息:
Error in fitTMB(TMBStruc) : negative log-likelihood is NaN at starting parameter values
2. ziGamma模型同样报错
testdata<-data.frame(DV=sample(0:100), pred=sample(-50:50)) hmod<-glmmTMB(formula=DV~pred, ziformula=~pred, data=testdata,family=ziGamma)
错误信息:
Error in fitTMB(TMBStruc) : negative log-likelihood is NaN at starting parameter values
3. 仅截距项的ziGamma模型(收敛但有NA警告)
hmod<-glmmTMB(formula=DV~1, ziformula=~pred, data=testdata,family=ziGamma)
警告信息:
Warning messages: 1: In (function (start, objective, gradient = NULL, hessian = NULL, : NA/NaN function evaluation 2: In (function (start, objective, gradient = NULL, hessian = NULL, : NA/NaN function evaluation 3: In (function (start, objective, gradient = NULL, hessian = NULL, : NA/NaN function evaluation 4: In (function (start, objective, gradient = NULL, hessian = NULL, : NA/NaN function evaluation
已尝试的解决方法
- 从源码重装了Matrix、TMB和glmmTMB包,问题未解决
- 参考旧帖建议将Matrix降级至1.6-2,但此举会破坏lme4等其他依赖包,因此寻求其他可行解决方案
会话信息
sessionInfo() # R version 4.4.1 (2024-06-14 ucrt) # Platform: x86_64-w64-mingw32/x64 # Running under: Windows 10 x64 (build 19045) # # Matrix products: default # # # locale: # [1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 # [3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C # [5] LC_TIME=English_United Kingdom.utf8 # # time zone: Europe/Vienna # tzcode source: internal # # attached base packages: # [1] stats graphics grDevices utils datasets methods base # # other attached packages: # [1] glmmTMB_1.1.10 lmerTest_3.1-3 lme4_1.1-35.5 Matrix_1.7-1 mgcv_1.9-1 nlme_3.1-164 # [7] ggplot2_3.5.1 stringr_1.5.1 dplyr_1.1.4 magrittr_2.0.3 # # loaded via a namespace (and not attached): # [1] sandwich_3.1-1 utf8_1.2.4 generics_0.1.3 stringi_1.8.4 lattice_0.22-6 # [6] grid_4.4.1 estimability_1.5.1 mvtnorm_1.3-2 this.path_2.5.0 survival_3.6-4 # [11] multcomp_1.4-26 fansi_1.0.6 scales_1.3.0 TH.data_1.1-2 codetools_0.2-20 # [16] numDeriv_2016.8-1.1 reformulas_0.4.0 Rdpack_2.6.1 cli_3.6.3 rlang_1.1.4 # [21] rbibutils_2.3 munsell_0.5.1 splines_4.4.1 withr_3.0.2 tools_4.4.1 # [26] nloptr_2.1.1 coda_0.19-4.1 minqa_1.2.8 colorspace_2.1-1 boot_1.3-30 # [31] vctrs_0.6.5 R6_2.5.1 zoo_1.8-12 lifecycle_1.0.4 emmeans_1.10.5 # [36] MASS_7.3-60.2 pkgconfig_2.0.3 pillar_1.9.0 gtable_0.3.6 glue_1.8.0 # [41] Rcpp_1.0.13-1 tibble_3.2.1 tidyselect_1.2.1 rstudioapi_0.17.1 xtable_1.8-4 # [46] TMB_1.9.15 compiler_4.4.1
内容的提问来源于stack exchange,提问作者Arpaxad
相关产品推荐
相关产品推荐

