From 1d3e32ea7f626dc84e66fc3bb8ac3ae3c514d622 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Sep 2024 16:32:24 +0200 Subject: [PATCH] add tests --- .../plot-model-parameters-1.svg | 93 ++++++ .../plot-model-parameters-random-0.svg | 93 ++++++ .../plot-model-parameters-random-1.svg | 256 ++++++++++++++++ .../plot-model-parameters-random-2.svg | 290 ++++++++++++++++++ .../plot-model-parameters-random-3.svg | 290 ++++++++++++++++++ .../plot-model-parameters-random-4.svg | 290 ++++++++++++++++++ .../plot-model-parameters-random-5.svg | 281 +++++++++++++++++ .../plot-model-parameters-random-6.svg | 162 ++++++++++ tests/testthat/test-plot.parameters_model.R | 58 +++- 9 files changed, 1812 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg create mode 100644 tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg new file mode 100644 index 000000000..ba2c1abe1 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-1.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Random Effects + + + + + + + + + +Fixed Effects + + + +0 +10 +20 +30 + +0 +5 +10 + +Days + +SD (Observations) +SD (Days) +Coefficient +plot.model_parameters_1 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg new file mode 100644 index 000000000..c9efd6bd8 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-0.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Random Effects + + + + + + + + + +Fixed Effects + + + +0 +10 +20 +30 + +0 +5 +10 + +Days + +SD (Observations) +SD (Days) +Coefficient +plot.model_parameters_random_0 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg new file mode 100644 index 000000000..aad093030 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-1.svg @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-60 +-30 +0 +30 +60 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 +Coefficient +Level +plot.model_parameters_random_1 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg new file mode 100644 index 000000000..7b60e0279 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-2.svg @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-50 +0 +50 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 +Coefficient +Level +plot.model_parameters_random_2 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg new file mode 100644 index 000000000..1cccf6187 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-3.svg @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-50 +0 +50 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 + +372 +371 +370 +369 +352 +351 +350 +349 +337 +335 +334 +333 +332 +331 +330 +310 +309 +308 +Coefficient +Level +plot.model_parameters_random_3 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg new file mode 100644 index 000000000..87fa94a0e --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-4.svg @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + + + + + + + +Subject: (Intercept) + + + +-50 +0 +50 + +337 +330 +331 +352 +333 +372 +332 +351 +369 +308 +371 +335 +334 +350 +349 +370 +310 +309 + +337 +330 +331 +352 +333 +372 +332 +351 +369 +308 +371 +335 +334 +350 +349 +370 +310 +309 +Coefficient +Level +plot.model_parameters_random_4 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg new file mode 100644 index 000000000..e69c31930 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-5.svg @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.26 [-21.40, 25.92] +-40.40 [-64.06, -16.74] +-38.96 [-62.62, -15.30] +23.69 [0.03, 47.35] +22.26 [-1.40, 45.92] +9.04 [-14.62, 32.70] +16.84 [-6.82, 40.50] +-7.23 [-30.89, 16.43] +-0.33 [-23.99, 23.32] +34.89 [11.23, 58.55] +-25.21 [-48.87, -1.55] +-13.07 [-36.73, 10.59] +4.58 [-19.08, 28.24] +20.86 [-2.79, 44.52] +3.28 [-20.38, 26.93] +-25.61 [-49.27, -1.95] +0.81 [-22.85, 24.47] +12.31 [-11.34, 35.97] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: (Intercept) + + + + + + + + + +Subject: Days + + + +-100 +-50 +0 +50 +100 +150 + +-100 +-50 +0 +50 +100 +150 + +337 +330 +331 +352 +333 +372 +332 +351 +369 +308 +371 +335 +334 +350 +349 +370 +310 +309 +Coefficient +Level +plot.model_parameters_random_5 + + diff --git a/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg new file mode 100644 index 000000000..be78806e0 --- /dev/null +++ b/tests/testthat/_snaps/plot.parameters_model/plot-model-parameters-random-6.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9.20 [4.68, 13.72] +-8.62 [-13.14, -4.10] +-5.45 [-9.97, -0.93] +-4.81 [-9.33, -0.30] +-3.07 [-7.59, 1.45] +-0.27 [-4.79, 4.25] +-0.22 [-4.74, 4.29] +1.07 [-3.44, 5.59] +-10.75 [-15.27, -6.23] +8.63 [4.11, 13.15] +1.17 [-3.34, 5.69] +6.61 [2.10, 11.13] +-3.02 [-7.53, 1.50] +3.54 [-0.98, 8.05] +0.87 [-3.65, 5.39] +4.82 [0.31, 9.34] +-0.99 [-5.51, 3.53] +1.28 [-3.23, 5.80] + + + + + + + + + +Subject: Days + + + +-20 +-10 +0 +10 +20 + +308 +337 +350 +370 +352 +372 +349 +334 +369 +333 +332 +371 +351 +331 +330 +310 +309 +335 +Coefficient +Level +plot.model_parameters_random_6 + + diff --git a/tests/testthat/test-plot.parameters_model.R b/tests/testthat/test-plot.parameters_model.R index 7a52d8b6f..56a7aceee 100644 --- a/tests/testthat/test-plot.parameters_model.R +++ b/tests/testthat/test-plot.parameters_model.R @@ -1,6 +1,62 @@ test_that("`plot.see_parameters_model()` works", { m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars) result <- parameters::model_parameters(m) - expect_s3_class(plot(result), "gg") + + skip_if_not_installed("vdiffr") + vdiffr::expect_doppelganger( + title = "plot.model_parameters_1", + fig = plot(out) + ) +}) + +test_that("`plot.see_parameters_model()` random parameters works", { + skip_if_not_installed("vdiffr") + skip_if_not_installed("lme4") + skip_if_not_installed("parameters") + + data(sleepstudy, package = "lme4") + s_mod <- lme4::lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) + + out <- parameters::model_parameters(s_mod) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_0", + fig = plot(out) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_1", + fig = plot(out) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_2", + fig = plot(out, show_labels = TRUE) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_3", + fig = plot(out, show_labels = TRUE, size_text = 5) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_4", + fig = plot(out, sort = "ascending", show_labels = TRUE) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_5", + fig = plot(out, sort = "ascending", show_labels = TRUE, n_columns = 2) + ) + + out <- parameters::model_parameters(s_mod, group_level = TRUE) + vdiffr::expect_doppelganger( + title = "plot.model_parameters_random_6", + fig = plot(out, sort = "ascending", show_labels = TRUE, show_intercept = FALSE) + ) })