From b08dcc99d30eac9a00431043e333a433c67691ea Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Dec 2024 08:34:17 +0100 Subject: [PATCH] Fix, add snapshot --- DESCRIPTION | 2 +- R/plot.check_collinearity.R | 7 +- .../plot-check-collinearity.svg | 80 +++++++++++++++++++ tests/testthat/test-plot.check_collinearity.R | 7 +- tests/testthat/test-plot.check_dag.R | 1 + 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 tests/testthat/_snaps/plot.check_collinearity/plot-check-collinearity.svg diff --git a/DESCRIPTION b/DESCRIPTION index 646f5c623..ad6cffb06 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.9.0.10 +Version: 0.9.0.11 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/R/plot.check_collinearity.R b/R/plot.check_collinearity.R index 4884a65c8..4ba0f36bc 100644 --- a/R/plot.check_collinearity.R +++ b/R/plot.check_collinearity.R @@ -38,14 +38,11 @@ plot.see_check_collinearity <- function(x, dat$group[dat$VIF >= 5 & dat$VIF < 10] <- "moderate" dat$group[dat$VIF >= 10] <- "high" - dat <- datawizard::data_rename( + dat <- datawizard::data_select( dat, - select = c("Term", "VIF", "SE_factor", "Component"), - replacement = c("x", "y", "se", "facet") + select = c(x = "Term", y = "VIF", facet = "Component", group = "group") ) - dat <- datawizard::data_select(dat, select = c("x", "y", "facet", "group")) - if (insight::n_unique(dat$facet) <= 1) { dat$facet <- NULL } diff --git a/tests/testthat/_snaps/plot.check_collinearity/plot-check-collinearity.svg b/tests/testthat/_snaps/plot.check_collinearity/plot-check-collinearity.svg new file mode 100644 index 000000000..59080a3ae --- /dev/null +++ b/tests/testthat/_snaps/plot.check_collinearity/plot-check-collinearity.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +2 +3 +5 +10 + +cyl +disp +gear +wt +Variance Inflation Factor (VIF, log-scaled) + + + + + +Low (< 5) +Moderate (< 10) +High collinearity (VIF) may inflate parameter uncertainty +Collinearity + + diff --git a/tests/testthat/test-plot.check_collinearity.R b/tests/testthat/test-plot.check_collinearity.R index 4981bc5a2..bfd8903e4 100644 --- a/tests/testthat/test-plot.check_collinearity.R +++ b/tests/testthat/test-plot.check_collinearity.R @@ -1,6 +1,11 @@ test_that("`plot.see_check_collinearity()` works", { m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars) result <- performance::check_collinearity(m) - expect_s3_class(plot(result), "gg") + + skip_if_not_installed("vdiffr") + vdiffr::expect_doppelganger( + title = "plot.check_collinearity", + fig = plot(result) + ) }) diff --git a/tests/testthat/test-plot.check_dag.R b/tests/testthat/test-plot.check_dag.R index ec39f88b9..5c8658113 100644 --- a/tests/testthat/test-plot.check_dag.R +++ b/tests/testthat/test-plot.check_dag.R @@ -1,5 +1,6 @@ skip_if_not_installed("ggdag") skip_if_not_installed("dagitty") +skip_if_not_installed("vdiffr") test_that("`plot()` for check_dag", { set.seed(1234)