| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("mlogit") |
| 7 |
skip_if_not_installed("AER") |
| 8 |
suppressPackageStartupMessages(library(mlogit)) |
| 9 |
suppressPackageStartupMessages(library(AER)) |
| 10 |
library(dplyr) |
| 11 |
|
| 12 |
data("Fishing", package = "mlogit") |
| 13 |
Fish <- dfidx(Fishing, varying = 2:9, shape = "wide", choice = "mode") |
| 14 |
fit1 <- mlogit(mode ~ price + catch, data = Fish) |
| 15 |
|
| 16 |
data("TravelMode", package = "AER") |
| 17 |
fit2 <- mlogit(choice ~ wait + travel + vcost, TravelMode, heterosc = TRUE) |
| 18 |
|
| 19 |
test_that("mlogit tidier arguments", { |
| 20 |
check_arguments(tidy.mlogit) |
| 21 |
check_arguments(glance.mlogit) |
| 22 |
check_arguments(augment.mlogit, strict = FALSE) |
| 23 |
}) |
| 24 |
|
| 25 |
test_that("tidy.mlogit", { |
| 26 |
td1 <- tidy(fit1) |
| 27 |
td2 <- tidy(fit1, conf.int = TRUE) |
| 28 |
td3 <- tidy(fit2) |
| 29 |
td4 <- tidy(fit2, conf.int = TRUE) |
| 30 |
|
| 31 |
check_tidy_output(td1) |
| 32 |
check_tidy_output(td2) |
| 33 |
check_tidy_output(td3) |
| 34 |
check_tidy_output(td4) |
| 35 |
}) |
| 36 |
|
| 37 |
test_that("glance.mlogit", { |
| 38 |
gl1 <- glance(fit1) |
| 39 |
gl2 <- glance(fit2) |
| 40 |
|
| 41 |
check_glance_outputs(gl1) |
| 42 |
check_glance_outputs(gl2) |
| 43 |
}) |
| 44 |
|
| 45 |
test_that("augment.mlogit", { |
| 46 |
check_augment_function( |
| 47 |
aug = augment.mlogit, |
| 48 |
model = fit1, |
| 49 |
data = Fish, |
| 50 |
newdata = Fish, |
| 51 |
strict = FALSE |
| 52 |
) |
| 53 |
|
| 54 |
au1 <- augment(fit1) |
| 55 |
au2 <- augment(fit2) |
| 56 |
|
| 57 |
expect_true(all( |
| 58 |
c("id", "alternative", "chosen", ".resid", ".fitted") %in% names(au1) |
| 59 |
)) |
| 60 |
expect_true(all( |
| 61 |
c("id", "alternative", "chosen", ".resid", ".fitted") %in% names(au2) |
| 62 |
)) |
| 63 |
}) |