| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("nnet") |
| 7 |
suppressPackageStartupMessages(library(nnet)) |
| 8 |
|
| 9 |
fit <- multinom(gear ~ mpg + factor(am), data = mtcars, trace = FALSE) |
| 10 |
|
| 11 |
response <- t(rmultinom(100, 1, c(0.1, 0.2, 0.3, 0.4))) |
| 12 |
fit_matrix_response <- multinom(response ~ 1, trace = FALSE) |
| 13 |
|
| 14 |
test_that("nnet tidier arguments", { |
| 15 |
check_arguments(tidy.multinom) |
| 16 |
check_arguments(glance.multinom) |
| 17 |
}) |
| 18 |
|
| 19 |
test_that("tidy.multinom when y has only 2 levels", { |
| 20 |
dfr <- data.frame(a = rnorm(100)) |
| 21 |
dfr$y <- dfr$a + rnorm(100) |
| 22 |
twolevels <- nnet::multinom(I(y > 0) ~ a, dfr, trace = FALSE) |
| 23 |
td1 <- tidy(twolevels, conf.int = TRUE) |
| 24 |
check_tidy_output(td1) |
| 25 |
check_dims(td1, 2, 8) |
| 26 |
}) |
| 27 |
|
| 28 |
test_that("tidy.multinom", { |
| 29 |
td1 <- tidy(fit, conf.int = TRUE) |
| 30 |
td2 <- tidy(fit_matrix_response, conf.int = TRUE) |
| 31 |
check_tidy_output(td1) |
| 32 |
check_tidy_output(td2) |
| 33 |
check_dims(td1, 6, 8) |
| 34 |
check_dims(td2, 3, 8) |
| 35 |
}) |
| 36 |
|
| 37 |
test_that("glance.multinom", { |
| 38 |
gl <- glance(fit) |
| 39 |
check_glance_outputs(gl) |
| 40 |
check_dims(gl, expected_cols = 4) |
| 41 |
}) |