From e47f5433c4fec65dce1f860268be81bf82c598df Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 30 Jun 2023 20:45:50 +0200 Subject: [PATCH] add tests --- tests/testthat/_snaps/print.md | 68 ++++++++++++++++++++++++++++++++++ tests/testthat/test-print.R | 10 +++++ 2 files changed, 78 insertions(+) create mode 100644 tests/testthat/_snaps/print.md create mode 100644 tests/testthat/test-print.R diff --git a/tests/testthat/_snaps/print.md b/tests/testthat/_snaps/print.md new file mode 100644 index 000000000..b88e10940 --- /dev/null +++ b/tests/testthat/_snaps/print.md @@ -0,0 +1,68 @@ +# print.describe_posterior + + Code + describe_posterior(m) + Warning + Could not estimate a good default ROPE range. Using 'c(-0.1, 0.1)'. + Output + Summary of Posterior Distribution + + Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS + ------------------------------------------------------------------------------------------- + (Intercept) | 0.96 | [-0.81, 2.51] | 90.00% | [-0.10, 0.10] | 2.54% | 1.011 | 110.00 + child | -1.16 | [-1.36, -0.94] | 100% | [-0.10, 0.10] | 0% | 0.996 | 278.00 + camper | 0.73 | [ 0.54, 0.91] | 100% | [-0.10, 0.10] | 0% | 0.996 | 271.00 + +--- + + Code + describe_posterior(m, effects = "all", component = "all") + Warning + Could not estimate a good default ROPE range. Using 'c(-0.1, 0.1)'. + Output + Summary of Posterior Distribution + + Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS + ------------------------------------------------------------------------------------------- + (Intercept) | 0.96 | [-0.81, 2.51] | 90.00% | [-0.10, 0.10] | 2.54% | 1.011 | 110.00 + child | -1.16 | [-1.36, -0.94] | 100% | [-0.10, 0.10] | 0% | 0.996 | 278.00 + camper | 0.73 | [ 0.54, 0.91] | 100% | [-0.10, 0.10] | 0% | 0.996 | 271.00 + + # Fixed effects (zero-inflated) + + Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS + ------------------------------------------------------------------------------------------- + (Intercept) | -0.48 | [-2.03, 0.89] | 78.00% | [-0.10, 0.10] | 10.59% | 0.997 | 138.00 + child | 1.85 | [ 1.19, 2.54] | 100% | [-0.10, 0.10] | 0% | 0.996 | 303.00 + camper | -0.88 | [-1.61, -0.07] | 98.40% | [-0.10, 0.10] | 0.85% | 0.996 | 292.00 + + # Random effects (conditional) Intercept: persons + + Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS + -------------------------------------------------------------------------------------------- + persons.1 | -0.99 | [-2.68, 0.80] | 92.00% | [-0.10, 0.10] | 2.12% | 1.007 | 106.00 + persons.2 | -4.65e-03 | [-1.63, 1.66] | 50.00% | [-0.10, 0.10] | 13.98% | 1.013 | 109.00 + persons.3 | 0.69 | [-0.95, 2.34] | 79.60% | [-0.10, 0.10] | 5.08% | 1.010 | 114.00 + persons.4 | 1.57 | [-0.05, 3.29] | 96.80% | [-0.10, 0.10] | 1.27% | 1.009 | 114.00 + + # Random effects (zero-inflated) Intercept: persons + + Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS + ----------------------------------------------------------------------------------------- + persons.1 | 1.10 | [-0.23, 2.72] | 94.80% | [-0.10, 0.10] | 3.39% | 0.997 | 166.00 + persons.2 | 0.18 | [-0.94, 1.58] | 63.20% | [-0.10, 0.10] | 14.83% | 0.996 | 154.00 + persons.3 | -0.30 | [-1.79, 1.02] | 64.00% | [-0.10, 0.10] | 12.29% | 0.997 | 154.00 + persons.4 | -1.45 | [-2.90, -0.10] | 98.00% | [-0.10, 0.10] | 0% | 1.000 | 189.00 + + # Random effects (conditional) SD/Cor: persons + + Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS + ----------------------------------------------------------------------------------------- + (Intercept) | 1.42 | [ 0.71, 3.58] | 100% | [-0.10, 0.10] | 0% | 1.010 | 126.00 + + # Random effects (zero-inflated) SD/Cor: persons + + Parameter | Median | 95% CI | pd | ROPE | % in ROPE | Rhat | ESS + ----------------------------------------------------------------------------------------- + (Intercept) | 1.30 | [ 0.63, 3.41] | 100% | [-0.10, 0.10] | 0% | 0.996 | 129.00 + diff --git a/tests/testthat/test-print.R b/tests/testthat/test-print.R new file mode 100644 index 000000000..9a87796e6 --- /dev/null +++ b/tests/testthat/test-print.R @@ -0,0 +1,10 @@ +test_that("print.describe_posterior", { + skip_on_cran() + skip_if_offline() + skip_if_not_or_load_if_installed("brms") + skip_if_not_or_load_if_installed("httr") + + m <- insight::download_model("brms_zi_3") + expect_snapshot(describe_posterior(m)) + expect_snapshot(describe_posterior(m, effects = "all", component = "all")) +})