| 1 |
skip_if_not_installed("modeltests") |
| 2 |
library(modeltests) |
| 3 |
|
| 4 |
skip_if_not_installed("MASS") |
| 5 |
suppressPackageStartupMessages(library(MASS)) |
| 6 |
|
| 7 |
fit <- glm.nb(Days ~ Sex / (Age + Eth * Lrn), data = MASS::quine) |
| 8 |
|
| 9 |
test_that("MASS::glm.nb tidier arguments", { |
| 10 |
check_arguments(tidy.negbin) |
| 11 |
check_arguments(glance.negbin) |
| 12 |
}) |
| 13 |
|
| 14 |
test_that("tidy.negbin", { |
| 15 |
td1 <- tidy(fit) |
| 16 |
td2 <- tidy(fit, conf.int = TRUE) |
| 17 |
td3 <- tidy(fit, exponentiate = TRUE, conf.int = TRUE) |
| 18 |
|
| 19 |
check_tidy_output(td2) |
| 20 |
check_tidy_output(td1) |
| 21 |
|
| 22 |
expect_false(NA %in% td2$conf.low) |
| 23 |
expect_false(NA %in% td2$conf.high) |
| 24 |
|
| 25 |
# exponentiate arg check |
| 26 |
expect_equal( |
| 27 |
as.matrix(td3[, c("estimate", "conf.low", "conf.high")]), |
| 28 |
exp(as.matrix(td2[, c("estimate", "conf.low", "conf.high")])) |
| 29 |
) |
| 30 |
}) |
| 31 |
|
| 32 |
test_that("glance.negbin", { |
| 33 |
gl <- glance(fit) |
| 34 |
check_glance_outputs(gl) |
| 35 |
check_dims(gl, 1, 8) |
| 36 |
}) |