diff --git a/tests/testthat/test-check_overdispersion.R b/tests/testthat/test-check_overdispersion.R index ee3426299..9f38cc5ab 100644 --- a/tests/testthat/test-check_overdispersion.R +++ b/tests/testthat/test-check_overdispersion.R @@ -1,4 +1,4 @@ -test_that("check_overdispersion", { +test_that("check_overdispersion, glmmTMB-poisson", { skip_if_not_installed("glmmTMB") skip_if_not(getRversion() >= "4.0.0") data(Salamanders, package = "glmmTMB") @@ -20,7 +20,7 @@ test_that("check_overdispersion", { ) }) -test_that("check_overdispersion", { +test_that("check_overdispersion, glmmTMB-poisson mixed", { skip_if_not_installed("glmmTMB") skip_if_not(getRversion() >= "4.0.0") data(Salamanders, package = "glmmTMB") @@ -109,3 +109,27 @@ test_that("check_overdispersion, zero-inflated and negbin", { ignore_attr = TRUE ) }) + + +test_that("check_overdispersion, MASS::negbin", { + skip_if_not_installed("MASS") + skip_if_not_installed("DHARMa") + set.seed(3) + mu <- rpois(500, lambda = 3) + x <- rnorm(500, mu, mu * 3) + x <- ceiling(x) + x <- pmax(x, 0) + m <- MASS::glm.nb(x ~ mu) + expect_equal( + check_overdispersion(m), + structure( + list( + dispersion_ratio = 2.44187535015136, + p_value = 0 + ), + class = c("check_overdisp", "see_check_overdisp") + ), + ignore_attr = TRUE, + tolerance = 1e-4 + ) +}) diff --git a/tests/testthat/test-check_zeroinflation.R b/tests/testthat/test-check_zeroinflation.R index 5fd6a71fc..ef8ee3e44 100644 --- a/tests/testthat/test-check_zeroinflation.R +++ b/tests/testthat/test-check_zeroinflation.R @@ -133,3 +133,30 @@ test_that("check_zeroinflation, glmmTMB nbinom", { tolerance = 1e-3 ) }) + + +test_that("check_zeroinflation, MASS::negbin", { + skip_if_not_installed("MASS") + skip_if_not_installed("DHARMa") + set.seed(3) + mu <- rpois(500, lambda = 3) + x <- rnorm(500, mu, mu * 3) + x <- ceiling(x) + x <- pmax(x, 0) + m <- MASS::glm.nb(x ~ mu) + expect_equal( + check_zeroinflation(m), + structure( + list( + predicted.zeros = 178, + observed.zeros = 202L, + ratio = 0.879643564356436, + tolerance = 0.1, + p.value = 0.008 + ), + class = "check_zi" + ), + ignore_attr = TRUE, + tolerance = 1e-4 + ) +})