Skip to content

Commit

Permalink
Collinearity not available for models of class 'hurdle'
Browse files Browse the repository at this point in the history
Fixes #606
  • Loading branch information
strengejacke committed Sep 10, 2023
1 parent 7b181e1 commit e5b2768
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
* `check_outliers()` for `"ICS"` method is now more stable and less likely to
fail.

## Bug fixes

* `check_collinearity()` did not work for hurdle- or zero-inflated models of
package *pscl* when model had no explicitly defined formula for the
zero-inflation model.

# performance 0.10.4

## Changes to functions
Expand Down
8 changes: 8 additions & 0 deletions R/check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,14 @@ check_collinearity.zerocount <- function(x,

f <- insight::find_formula(x)

# hurdle or zeroinfl model can have no zero-inflation formula, in which case
# we have the same formula as for conditional formula part
if (inherits(x, c("hurdle", "zeroinfl", "zerocount")) &&
component == "zero_inflated" &&
is.null(f[["zero_inflated"]])) {
f$zero_inflated <- f$conditional
}

if (inherits(x, "mixor")) {
terms <- labels(x$terms)
} else {
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,24 @@ test_that("check_collinearity, ci are NA", {
)
)
})

test_that("check_collinearity, hurdle/zi models w/o zi-formula", {
skip_if_not_installed("pscl")
data("bioChemists", package = "pscl")
m <- pscl::hurdle(
art ~ fem + mar,
data = bioChemists,
dist = "poisson",
zero.dist = "binomial",
link = "logit"
)
out <- check_collinearity(m)
expect_identical(
colnames(out),
c(
"Term", "VIF", "VIF_CI_low", "VIF_CI_high", "SE_factor", "Tolerance",
"Tolerance_CI_low", "Tolerance_CI_high", "Component"
)
)
expect_equal(out$VIF, c(1.05772, 1.05772, 1.06587, 1.06587), tolerance = 1e-4)
})

0 comments on commit e5b2768

Please sign in to comment.