diff --git a/NEWS.md b/NEWS.md index 321412b00..d4f14ab62 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,6 +21,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 diff --git a/R/check_collinearity.R b/R/check_collinearity.R index 742abcb14..b5019c5c3 100644 --- a/R/check_collinearity.R +++ b/R/check_collinearity.R @@ -414,7 +414,7 @@ check_collinearity.zerocount <- function(x, .check_collinearity <- function(x, component, ci = 0.95, verbose = TRUE) { - 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)) { diff --git a/tests/testthat/test-check_collinearity.R b/tests/testthat/test-check_collinearity.R index f14f8186a..8bab16003 100644 --- a/tests/testthat/test-check_collinearity.R +++ b/tests/testthat/test-check_collinearity.R @@ -222,5 +222,19 @@ test_that("check_collinearity, hurdle/zi models w/o zi-formula", { test_that("check_collinearity, invalid data", { dd <- data.frame(y = as.difftime(0:5, units = "days")) m1 <- lm(y ~ 1, data = dd) - expect_error(check_collinearity(m1), "Can't extract variance-covariance matrix") + expect_message(check_collinearity(m1), "Could not extract the variance-covariance") +}) + +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) }) diff --git a/tests/testthat/test-check_model.R b/tests/testthat/test-check_model.R index 2b1141d26..216062a08 100644 --- a/tests/testthat/test-check_model.R +++ b/tests/testthat/test-check_model.R @@ -40,7 +40,7 @@ test_that("`check_outliers()` works if convergence issues", { test_that("`check_model()` for invalid models", { dd <- data.frame(y = as.difftime(0:5, units = "days")) m1 <- lm(y ~ 1, data = dd) - expect_error(check_model(m1)) + expect_message(check_model(m1), regex = "Date variables are not") }) test_that("`check_model()` works for quantreg", {