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 (#782)
  • Loading branch information
strengejacke authored Dec 22, 2024
1 parent 14a121f commit 2dfeea2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ check_collinearity.zerocount <- function(x,


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

Check warning on line 416 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_collinearity.R,line=416,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
16 changes: 15 additions & 1 deletion tests/testthat/test-check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 2dfeea2

Please sign in to comment.