Skip to content

Commit

Permalink
Correctly detect ZI when there is no ziformula (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Nov 3, 2023
1 parent 8e81cc4 commit 919ac84
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/model_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion tests/testthat/test-glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
})

0 comments on commit 919ac84

Please sign in to comment.