Skip to content

Commit 2dfeea2

Browse files
authored
check_model() and other functions not working with only post-"hurdle" glmmTMB model (#782)
1 parent 14a121f commit 2dfeea2

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
* `check_outliers()` did not warn that no numeric variables were found when only
2222
the response variable was numeric, but all relevant predictors were not.
2323

24+
* `check_collinearity()` did not work for glmmTMB models when zero-inflation
25+
component was set to `~0`.
26+
2427
# performance 0.12.4
2528

2629
## Changes

R/check_collinearity.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ check_collinearity.zerocount <- function(x,
414414

415415

416416
.check_collinearity <- function(x, component, ci = 0.95, verbose = TRUE) {
417-
v <- insight::get_varcov(x, component = component, verbose = FALSE)
417+
v <- .safe(insight::get_varcov(x, component = component, verbose = FALSE))
418418

419419
# sanity check
420420
if (is.null(v)) {

tests/testthat/test-check_collinearity.R

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,19 @@ test_that("check_collinearity, hurdle/zi models w/o zi-formula", {
222222
test_that("check_collinearity, invalid data", {
223223
dd <- data.frame(y = as.difftime(0:5, units = "days"))
224224
m1 <- lm(y ~ 1, data = dd)
225-
expect_error(check_collinearity(m1), "Can't extract variance-covariance matrix")
225+
expect_message(check_collinearity(m1), "Could not extract the variance-covariance")
226+
})
227+
228+
test_that("check_collinearity, glmmTMB hurdle w/o zi", {
229+
skip_if_not_installed("glmmTMB")
230+
data(Salamanders, package = "glmmTMB")
231+
mod_trunc_error <- glmmTMB::glmmTMB(
232+
count ~ spp + mined + (1 | site),
233+
data = Salamanders[Salamanders$count > 0, , drop = FALSE],
234+
family = glmmTMB::truncated_nbinom2(),
235+
ziformula = ~ 0,
236+
dispformula = ~ 1
237+
)
238+
out <- check_collinearity(mod_trunc_error)
239+
expect_equal(out$VIF, c(1.03414, 1.03414), tolerance = 1e-3)
226240
})

tests/testthat/test-check_model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test_that("`check_outliers()` works if convergence issues", {
4040
test_that("`check_model()` for invalid models", {
4141
dd <- data.frame(y = as.difftime(0:5, units = "days"))
4242
m1 <- lm(y ~ 1, data = dd)
43-
expect_error(check_model(m1))
43+
expect_message(check_model(m1), regex = "Date variables are not")
4444
})
4545

4646
test_that("`check_model()` works for quantreg", {

0 commit comments

Comments
 (0)