From b04038af58651351e4fd56cfaef91eabb9c7700a Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Nov 2023 22:39:48 +0100 Subject: [PATCH] Correctly detect ZI when there is no ziformula --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/model_info.R | 2 +- tests/testthat/test-glmmTMB.R | 17 ++++++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5b054470f..96170961c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: insight Title: Easy Access to Model Information for Various Model Objects -Version: 0.19.6.5 +Version: 0.19.6.6 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index 831c78cee..c9d087f4c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,9 @@ * Fixed issue in `find_formula()` for models of class `gamlss` when the `random()` function was used with namespace in the formula (i.e. `... + gamlss::random()`). +* `model_info()` now detects models with zero-inflation part from package + *glmmTMB* when models have truncated-families but no `ziformula`. + # insight 0.19.6 ## General diff --git a/R/model_info.R b/R/model_info.R index e9454ca15..0769312e0 100644 --- a/R/model_info.R +++ b/R/model_info.R @@ -1109,7 +1109,7 @@ model_info.glmmTMB <- function(x, ...) { check_if_installed("lme4") faminfo <- stats::family(x) - zero_inflated <- !is_empty_object(lme4::fixef(x)$zi) + zero_inflated <- !is_empty_object(lme4::fixef(x)$zi) || startsWith(faminfo$family, "truncated") .make_family( x = x, diff --git a/tests/testthat/test-glmmTMB.R b/tests/testthat/test-glmmTMB.R index d35606337..b1a1125e3 100644 --- a/tests/testthat/test-glmmTMB.R +++ b/tests/testthat/test-glmmTMB.R @@ -8,7 +8,7 @@ skip_if_not_installed("glmmTMB") # fish$livebait <- as.factor(fish$livebait) # fish$camper <- as.factor(fish$camper) -data("fish") +data("fish", package = "insight") m1 <- glmmTMB::glmmTMB( count ~ child + camper + (1 | persons), ziformula = ~ child + camper + (1 | persons), @@ -970,3 +970,18 @@ test_that("model_info, ordered beta", { expect_true(out$is_orderedbeta) expect_identical(out$family, "ordbeta") }) + + +test_that("model_info, recognize ZI even without ziformula", { + skip_if_not_installed("glmmTMB") + data("fish", package = "insight") + fish$count <- fish$count + 1 + m1 <- glmmTMB::glmmTMB( + count ~ child + camper + (1 | persons), + data = fish, + family = glmmTMB::truncated_nbinom1() + ) + out <- model_info(m1) + expect_true(out$is_zero_inflated) + expect_true(out$is_hurdle) +})