| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("margins") |
| 7 |
suppressPackageStartupMessages(library(margins)) |
| 8 |
|
| 9 |
fit1 <- glm(am ~ cyl + hp + wt, data = mtcars, family = binomial) |
| 10 |
marg1 <- margins(fit1) |
| 11 |
|
| 12 |
fit2 <- lm(mpg ~ wt * cyl * disp, data = mtcars) |
| 13 |
marg2a <- margins(fit2) |
| 14 |
marg2b <- margins(fit2, variable = "wt") |
| 15 |
marg2c <- margins(fit2, at = list(cyl = c(4, 6, 8))) |
| 16 |
marg2d <- margins( |
| 17 |
fit2, |
| 18 |
variables = "wt", |
| 19 |
at = list(cyl = c(4, 6, 8), drat = c(3, 3.5, 4)) |
| 20 |
) |
| 21 |
|
| 22 |
test_that("margins tidier arguments", { |
| 23 |
check_arguments(tidy.margins) |
| 24 |
check_arguments(glance.margins) |
| 25 |
}) |
| 26 |
|
| 27 |
test_that("tidy.margins", { |
| 28 |
td1a <- tidy(marg1) |
| 29 |
td1b <- tidy(marg1, conf.int = TRUE) |
| 30 |
td2a <- tidy(marg2a) |
| 31 |
td2b <- tidy(marg2b) |
| 32 |
td2c <- tidy(marg2c) |
| 33 |
td2d <- tidy(marg2d) |
| 34 |
|
| 35 |
check_tidy_output(td1a) |
| 36 |
check_tidy_output(td1b) |
| 37 |
check_tidy_output(td2a) |
| 38 |
check_tidy_output(td2b) |
| 39 |
check_tidy_output(td2c) |
| 40 |
check_tidy_output(td2d) |
| 41 |
|
| 42 |
check_dims(td1a, 3, 5) |
| 43 |
}) |
| 44 |
|
| 45 |
test_that("glance.margins", { |
| 46 |
gl1 <- glance(fit1) |
| 47 |
gl2 <- glance(fit2) |
| 48 |
|
| 49 |
check_dims(gl1, expected_cols = 8) |
| 50 |
check_dims(gl2, expected_cols = 12) |
| 51 |
}) |