Skip to content

Commit

Permalink
check_model() and other functions not working with only post-"hurdle"…
Browse files Browse the repository at this point in the history
… glmmTMB model

Fixes #781
  • Loading branch information
strengejacke committed Nov 26, 2024
1 parent 7f550c3 commit b8dce67
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 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: performance
Title: Assessment of Regression Models Performance
Version: 0.12.4.8
Version: 0.12.4.9
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 @@ -18,6 +18,9 @@
* `check_outliers()` did not warn that no numeric variables were found when only
the response variable was numeric, but all relevant predictors were not.

* `check_collinearity()` did not work for glmmTMB models when zero-inflation
component was set to `~0`.

# performance 0.12.4

## Changes
Expand Down
2 changes: 1 addition & 1 deletion R/check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ check_collinearity.zerocount <- function(x,


.check_collinearity <- function(x, component, ci = 0.95, verbose = TRUE) {

Check warning on line 407 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_collinearity.R,line=407,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 44 to at most 40.

Check warning on line 407 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_collinearity.R,line=407,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 44 to at most 40.
v <- insight::get_varcov(x, component = component, verbose = FALSE)
v <- .safe(insight::get_varcov(x, component = component, verbose = FALSE))

# sanity check
if (is.null(v)) {
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,17 @@ test_that("check_collinearity, invalid data", {
m1 <- lm(y ~ 1, data = dd)
expect_error(check_collinearity(m1), "Can't extract variance-covariance matrix")
})

test_that("check_collinearity, glmmTMB hurdle w/o zi", {
skip_if_not_installed("glmmTMB")
data(Salamanders, package = "glmmTMB")
mod_trunc_error <- glmmTMB::glmmTMB(
count ~ spp + mined + (1 | site),
data = Salamanders[Salamanders$count > 0, , drop = FALSE],
family = glmmTMB::truncated_nbinom2(),
ziformula = ~ 0,
dispformula = ~ 1
)
out <- check_collinearity(mod_trunc_error)
expect_equal(out$VIF, c(1.03414, 1.03414), tolerance = 1e-3)
})

0 comments on commit b8dce67

Please sign in to comment.