Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 16, 2024
1 parent 3382ecb commit 62d2bfe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/testthat/test-check_overdispersion.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,29 @@ test_that("check_overdispersion, MASS::negbin", {
tolerance = 1e-4
)
})


test_that("check_overdispersion, genpois", {
skip_if_not_installed("glmmTMB")
skip_if_not_installed("DHARMa")
skip_if_not(getRversion() >= "4.0.0")
data(Salamanders, package = "glmmTMB")

model <- glmmTMB::glmmTMB(
count ~ mined + spp + (1 | site),
family = glmmTMB::genpois(),
data = Salamanders
)
expect_equal(
check_overdispersion(model),
structure(
list(
dispersion_ratio = 1.02883236131678,
p_value = 0.88
),
class = c("check_overdisp", "see_check_overdisp")
),
tolerance = 1e-4,
ignore_attr = TRUE
)
})
29 changes: 29 additions & 0 deletions tests/testthat/test-check_zeroinflation.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,32 @@ test_that("check_zeroinflation, MASS::negbin", {
tolerance = 1e-4
)
})


test_that("check_zeroinflation, genpois", {
skip_if_not_installed("glmmTMB")
skip_if_not_installed("DHARMa")
skip_if_not(getRversion() >= "4.0.0")
data(Salamanders, package = "glmmTMB")

model <- glmmTMB::glmmTMB(
count ~ mined + spp + (1 | site),
family = glmmTMB::genpois(),
data = Salamanders
)
expect_equal(
check_zeroinflation(model),
structure(
list(
predicted.zeros = 386,
observed.zeros = 387L,
ratio = 0.997860465116279,
tolerance = 0.1,
p.value = 1
),
class = "check_zi"
),
tolerance = 1e-4,
ignore_attr = TRUE
)
})

0 comments on commit 62d2bfe

Please sign in to comment.