Skip to content
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.18.2.4
Version: 0.18.2.5
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Bug fixes

* `check_collinearity()` now labels terms correctly for *brms* models that use
the `0 + Intercept` formula syntax. Before, each VIF was shown under the name
of the previous term and the last term was missing (#417).

* `check_model()` now correctly returns the random-effects normality panel for
mixed models that specify random slopes using split terms such as
`(1 | group) + (0 + slope | group)` (including `||` expansions, #845).
Expand Down
6 changes: 6 additions & 0 deletions R/check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
}


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

Check warning on line 450 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=450,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 50 to at most 40. Consider replacing high-complexity sections like loops and branches with helper functions.

Check warning on line 450 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_collinearity.R,line=450,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 50 to at most 40. Consider replacing high-complexity sections like loops and branches with helper functions.
v <- .safe(insight::get_varcov(x, component = component, verbose = FALSE))

# fix class for fixest, which returns a "fixest_vcov" here
Expand Down Expand Up @@ -537,7 +537,7 @@
"Model matrix is rank deficient. VIFs may not be sensible.",
paste0(
"The following coefficients have VIF = Inf / tolerance = 0: ",
paste0(na_cols, collapse = ", ")

Check warning on line 540 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=540,col=13,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

Check warning on line 540 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=540,col=13,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists

Check warning on line 540 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_collinearity.R,line=540,col=13,[paste_linter] Use paste(), not paste0(), to collapse a character vector when sep= is not used.

Check warning on line 540 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_collinearity.R,line=540,col=13,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
)
)
} else {
Expand Down Expand Up @@ -574,6 +574,12 @@
model_terms <- labels(stats::terms(f[[component]]))
}

# brms formulas like `y ~ 0 + Intercept + x` list "Intercept" as a term, but
# it is the model's intercept, which is not part of the term assignment
if (inherits(x, "brmsfit")) {
model_terms <- setdiff(model_terms, "Intercept")
}

if ("instruments" %in% names(f)) {
model_terms <- unique(c(model_terms, labels(stats::terms(f[["instruments"]]))))
}
Expand All @@ -592,7 +598,7 @@
return(NULL)
}

R <- stats::cov2cor(v)

Check warning on line 601 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=601,col=3,[object_overwrite_linter] 'R' is an exported object from package 'tools'. Avoid re-using such symbols.

Check warning on line 601 in R/check_collinearity.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_collinearity.R,line=601,col=3,[object_overwrite_linter] 'R' is an exported object from package 'tools'. Avoid re-using such symbols.
detR <- det(R)

result <- vector("numeric")
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
.package = "insight"
)
testthat::local_mocked_bindings(
model.matrix = function(...) stop("rebuild failed"),

Check warning on line 81 in tests/testthat/test-check_collinearity.R

View workflow job for this annotation

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

file=tests/testthat/test-check_collinearity.R,line=81,col=34,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message.
.package = "stats"
)
expect_null(
Expand Down Expand Up @@ -216,9 +216,9 @@
expect_warning(expect_message(ccoW <- check_collinearity(aW))) # nolint
expect_message(ccoB <- check_collinearity(aB), regexp = NA) # nolint

expect_identical(nrow(ccoM), 15L)

Check warning on line 219 in tests/testthat/test-check_collinearity.R

View workflow job for this annotation

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

file=tests/testthat/test-check_collinearity.R,line=219,col=3,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)
expect_identical(nrow(ccoW), 3L)

Check warning on line 220 in tests/testthat/test-check_collinearity.R

View workflow job for this annotation

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

file=tests/testthat/test-check_collinearity.R,line=220,col=3,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)
expect_identical(nrow(ccoB), 3L)

Check warning on line 221 in tests/testthat/test-check_collinearity.R

View workflow job for this annotation

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

file=tests/testthat/test-check_collinearity.R,line=221,col=3,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)

suppressWarnings(suppressMessages({
aM <- afex::aov_car(
Expand All @@ -244,8 +244,8 @@
expect_warning(expect_message(ccoW <- check_collinearity(aW))) # nolint
expect_message(ccoB <- check_collinearity(aB), regexp = NA) # nolint

expect_identical(nrow(ccoM), 15L)

Check warning on line 247 in tests/testthat/test-check_collinearity.R

View workflow job for this annotation

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

file=tests/testthat/test-check_collinearity.R,line=247,col=3,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)
expect_identical(nrow(ccoW), 3L)

Check warning on line 248 in tests/testthat/test-check_collinearity.R

View workflow job for this annotation

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

file=tests/testthat/test-check_collinearity.R,line=248,col=3,[expect_shape_linter] expect_shape(x, nrow = n) is better than expect_identical(nrow(x), n)
expect_identical(nrow(ccoB), 3L)
})

Expand Down Expand Up @@ -487,3 +487,26 @@
})
expect_identical(out1$VIF, out2$VIF)
})


test_that("check_collinearity, brms with 0 + Intercept syntax", {
skip_on_cran()
skip_if_not_installed("brms")
m <- suppressMessages(suppressWarnings(brms::brm(
mpg ~ 0 + Intercept + cyl + disp + hp,
data = mtcars,
chains = 1,
iter = 500,
refresh = 0,
seed = 123,
silent = 2
)))
expect_silent({
out <- check_collinearity(m, ci = NULL)
})
expect_identical(out$Term, c("cyl", "disp", "hp"))
# VIFs for slopes, computed from the posterior correlation matrix
v <- insight::get_varcov(m)
R <- stats::cov2cor(v[-1, -1])
expect_equal(out$VIF, unname(diag(solve(R))), tolerance = 1e-6)
})
Loading