From 76e2aba127e2169b3095459ad89f910b6670d137 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 10 Feb 2025 22:01:12 +0100 Subject: [PATCH] add tests --- DESCRIPTION | 1 + tests/testthat/_snaps/betareg.md | 50 ++++++++++++++++++++++++++++++++ tests/testthat/test-betareg.R | 19 ++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 tests/testthat/_snaps/betareg.md create mode 100644 tests/testthat/test-betareg.R diff --git a/DESCRIPTION b/DESCRIPTION index 678f6cfe..53689e0c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,6 +44,7 @@ Imports: utils Suggests: BH, + betareg, brms, coda, collapse, diff --git a/tests/testthat/_snaps/betareg.md b/tests/testthat/_snaps/betareg.md new file mode 100644 index 00000000..f5414f88 --- /dev/null +++ b/tests/testthat/_snaps/betareg.md @@ -0,0 +1,50 @@ +# estimate_means for betareg + + Code + print(out, zap_small = TRUE) + Output + Estimated Marginal Means + + batch | Proportion | SE | 95% CI | z + ------------------------------------------------ + 1 | 0.31 | 0.01 | [0.29, 0.34] | 26.00 + 2 | 0.23 | 0.01 | [0.21, 0.26] | 16.76 + 3 | 0.28 | 0.01 | [0.25, 0.31] | 18.78 + 4 | 0.19 | 0.01 | [0.17, 0.21] | 19.96 + 5 | 0.20 | 0.01 | [0.18, 0.22] | 19.16 + 6 | 0.19 | 0.01 | [0.17, 0.21] | 17.83 + 7 | 0.12 | 0.01 | [0.11, 0.14] | 15.57 + 8 | 0.12 | 0.01 | [0.10, 0.13] | 14.56 + 9 | 0.11 | 0.01 | [0.09, 0.12] | 12.25 + 10 | 0.07 | 0.01 | [0.06, 0.09] | 12.78 + + Variable predicted: yield + Predictors modulated: batch + Predictors averaged: temp (3.3e+02) + Predictions are on the response-scale. + +# estimate_relation for betareg + + Code + print(out, zap_small = TRUE) + Output + Model-based Predictions + + batch | Predicted | 95% CI + -------------------------------- + 1 | 0.31 | [0.28, 0.35] + 2 | 0.23 | [0.21, 0.25] + 3 | 0.28 | [0.25, 0.31] + 4 | 0.19 | [0.17, 0.21] + 5 | 0.20 | [0.18, 0.22] + 6 | 0.19 | [0.17, 0.21] + 7 | 0.12 | [0.11, 0.14] + 8 | 0.12 | [0.10, 0.13] + 9 | 0.11 | [0.09, 0.12] + 10 | 0.07 | [0.06, 0.09] + + Variable predicted: yield + Predictors modulated: batch + Predictors controlled: temp (3.3e+02) + Predictions are on the response-scale. + diff --git a/tests/testthat/test-betareg.R b/tests/testthat/test-betareg.R new file mode 100644 index 00000000..7c64891c --- /dev/null +++ b/tests/testthat/test-betareg.R @@ -0,0 +1,19 @@ +skip_on_cran() +skip_if_offline() +skip_if_not_installed("marginaleffects") +skip_if_not_installed("betareg") + +test_that("estimate_means for betareg", { + data("GasolineYield", package = "betareg") + m1 <- betareg::betareg(yield ~ batch + temp, data = GasolineYield) + out <- estimate_means(m1, "batch") + expect_snapshot(print(out, zap_small = TRUE)) +}) + + +test_that("estimate_relation for betareg", { + data("GasolineYield", package = "betareg") + m1 <- betareg::betareg(yield ~ batch + temp, data = GasolineYield) + out <- estimate_relation(m1, by = "batch", verbose = FALSE) + expect_snapshot(print(out, zap_small = TRUE)) +})