Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_model() and other functions not working with only post-"hurdle" glmmTMB model #782

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@



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

Check warning on line 407 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_collinearity.R,line=407,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 44 to at most 40.

Check warning on line 407 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_collinearity.R,line=407,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 @@ -216,5 +216,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
Loading