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