Skip to content

Commit 13c696f

Browse files
committed
add tests
1 parent 3575e6a commit 13c696f

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

tests/testthat/test-check_overdispersion.R

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("check_overdispersion", {
1+
test_that("check_overdispersion, glmmTMB-poisson", {
22
skip_if_not_installed("glmmTMB")
33
skip_if_not(getRversion() >= "4.0.0")
44
data(Salamanders, package = "glmmTMB")
@@ -20,7 +20,7 @@ test_that("check_overdispersion", {
2020
)
2121
})
2222

23-
test_that("check_overdispersion", {
23+
test_that("check_overdispersion, glmmTMB-poisson mixed", {
2424
skip_if_not_installed("glmmTMB")
2525
skip_if_not(getRversion() >= "4.0.0")
2626
data(Salamanders, package = "glmmTMB")
@@ -109,3 +109,27 @@ test_that("check_overdispersion, zero-inflated and negbin", {
109109
ignore_attr = TRUE
110110
)
111111
})
112+
113+
114+
test_that("check_overdispersion, MASS::negbin", {
115+
skip_if_not_installed("MASS")
116+
skip_if_not_installed("DHARMa")
117+
set.seed(3)
118+
mu <- rpois(500, lambda = 3)
119+
x <- rnorm(500, mu, mu * 3)
120+
x <- ceiling(x)
121+
x <- pmax(x, 0)
122+
m <- MASS::glm.nb(x ~ mu)
123+
expect_equal(
124+
check_overdispersion(m),
125+
structure(
126+
list(
127+
dispersion_ratio = 2.44187535015136,
128+
p_value = 0
129+
),
130+
class = c("check_overdisp", "see_check_overdisp")
131+
),
132+
ignore_attr = TRUE,
133+
tolerance = 1e-4
134+
)
135+
})

tests/testthat/test-check_zeroinflation.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,30 @@ test_that("check_zeroinflation, glmmTMB nbinom", {
133133
tolerance = 1e-3
134134
)
135135
})
136+
137+
138+
test_that("check_zeroinflation, MASS::negbin", {
139+
skip_if_not_installed("MASS")
140+
skip_if_not_installed("DHARMa")
141+
set.seed(3)
142+
mu <- rpois(500, lambda = 3)
143+
x <- rnorm(500, mu, mu * 3)
144+
x <- ceiling(x)
145+
x <- pmax(x, 0)
146+
m <- MASS::glm.nb(x ~ mu)
147+
expect_equal(
148+
check_zeroinflation(m),
149+
structure(
150+
list(
151+
predicted.zeros = 178,
152+
observed.zeros = 202L,
153+
ratio = 0.879643564356436,
154+
tolerance = 0.1,
155+
p.value = 0.008
156+
),
157+
class = "check_zi"
158+
),
159+
ignore_attr = TRUE,
160+
tolerance = 1e-4
161+
)
162+
})

0 commit comments

Comments
 (0)