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 3575e6a commit 13c696f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tests/testthat/test-check_overdispersion.R
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
)
})
27 changes: 27 additions & 0 deletions tests/testthat/test-check_zeroinflation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
})

0 comments on commit 13c696f

Please sign in to comment.