florianhartig / DHARMa

Diagnostics for HierArchical Regession Models
http://florianhartig.github.io/DHARMa/
208 stars 22 forks source link

simulateResiduals fails on glmmTMB model with rank_check = "adjust" #373

Open gordy2x opened 1 year ago

gordy2x commented 1 year ago

There is now a (optional) argument in glmmTMB that drops terms that make the design matrix rank-deficient (see https://github.com/glmmTMB/glmmTMB/issues/522#issuecomment-1472885734), this is what lme4 does by default. I can run simulateResiduals on an lme4 object but not on a glmmTMB object with rank_check = "adjust".

library(glmmTMB)
library(lme4)
library(DHARMa)
set.seed(101)
dd <- data.frame(z = rnorm(100), 
                 x1 = 1:100, x2 = 2:101,
                 re = rep(1:20, each = 5))

mod_lme4 <- lmer(z ~ x1 + x2 + (1|re), data = dd)
simulateResiduals(mod_lme4, n = 5)

mod_TMB <- glmmTMB(z ~ x1 + x2 + (1|re), data = dd, 
                   control = glmmTMBControl(rank_check = "adjust"))
simulateResiduals(mod_TMB, n = 5)
reiniervlinschoten commented 1 year ago

The issue is not in DHARMa, but in the predict function of glmmTMB, see my comment in the other issue. I think @florianhartig can close this as the problem is not in this repo.

florianhartig commented 1 year ago

Thanks Reinier ... I'll leave it open for now to check later if this has been fixed in glmMTMB, but will likely not address this in DHARMa.

bbolker commented 1 year ago

Resolved now with remotes::install_github("glmmTMB/glmmTMB/glmmTMB@rankdef_NA")

florianhartig commented 1 year ago

Hi Ben, many thanks! I'll keep this open until the problem is resolved in CRAN!

reiniervlinschoten commented 1 year ago

Awesome, thank you very much for fixing this!