From b8dce6782f41fcd5c97b418562c4046876ae8115 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 26 Nov 2024 22:56:39 +0100 Subject: [PATCH 1/2] check_model() and other functions not working with only post-"hurdle" glmmTMB model Fixes #781 --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/check_collinearity.R | 2 +- tests/testthat/test-check_collinearity.R | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b6f58b233..3f970c585 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index a181937d8..be90d0056 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/check_collinearity.R b/R/check_collinearity.R index a7e1299c1..1cb0b6913 100644 --- a/R/check_collinearity.R +++ b/R/check_collinearity.R @@ -405,7 +405,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 d62aec75d..a3ce2b54c 100644 --- a/tests/testthat/test-check_collinearity.R +++ b/tests/testthat/test-check_collinearity.R @@ -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) +}) From 966094c9bb5816ecf29409712ec4c58de9d9c4b0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Nov 2024 08:36:40 +0100 Subject: [PATCH 2/2] fix tests --- tests/testthat/test-check_collinearity.R | 2 +- tests/testthat/test-check_model.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-check_collinearity.R b/tests/testthat/test-check_collinearity.R index a3ce2b54c..ea3dd56cd 100644 --- a/tests/testthat/test-check_collinearity.R +++ b/tests/testthat/test-check_collinearity.R @@ -216,7 +216,7 @@ 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", { 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", {