| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("MASS") |
| 7 |
suppressPackageStartupMessages(library(MASS)) |
| 8 |
|
| 9 |
fit <- polr( |
| 10 |
Sat ~ Infl + Type + Cont, |
| 11 |
weights = Freq, |
| 12 |
data = housing, |
| 13 |
Hess = TRUE |
| 14 |
) |
| 15 |
|
| 16 |
fit2 <- polr(Sat ~ Freq, data = housing) |
| 17 |
|
| 18 |
test_that("MASS::polr tidier arguments", { |
| 19 |
check_arguments(tidy.polr) |
| 20 |
check_arguments(glance.polr) |
| 21 |
check_arguments(augment.polr) |
| 22 |
}) |
| 23 |
|
| 24 |
test_that("tidy.polr", { |
| 25 |
td <- tidy(fit) |
| 26 |
td2 <- tidy(fit, conf.int = TRUE, exponentiate = TRUE) |
| 27 |
td3 <- tidy(fit2, conf.int = TRUE, exponentiate = TRUE) |
| 28 |
|
| 29 |
check_tidy_output(td, strict = FALSE) |
| 30 |
check_tidy_output(td2, strict = FALSE) |
| 31 |
check_tidy_output(td3, strict = FALSE) |
| 32 |
|
| 33 |
check_dims(td, expected_cols = 5) |
| 34 |
check_dims(td2, expected_cols = 7) |
| 35 |
check_dims(td3, expected_cols = 7) |
| 36 |
}) |
| 37 |
|
| 38 |
test_that("glance.polr", { |
| 39 |
gl <- glance(fit) |
| 40 |
check_glance_outputs(gl) |
| 41 |
}) |
| 42 |
|
| 43 |
test_that("augment.polr", { |
| 44 |
check_augment_function( |
| 45 |
aug = augment.polr, |
| 46 |
model = fit, |
| 47 |
data = housing, |
| 48 |
newdata = housing, |
| 49 |
strict = FALSE |
| 50 |
) |
| 51 |
|
| 52 |
au <- augment(fit, type.predict = "class") |
| 53 |
expect_s3_class(au$.fitted, "factor") |
| 54 |
expect_equal(predict(fit, type = "class"), au$.fitted) |
| 55 |
}) |
| 56 |
|
| 57 |
test_that("suppress Waiting for profiling to be done... message", { |
| 58 |
expect_silent(tidy(fit, conf.int = TRUE)) |
| 59 |
}) |
| 60 |
|
| 61 |
test_that("tidy.polr messages informatively", { |
| 62 |
mtcars$cyl <- as.factor(mtcars$cyl) |
| 63 |
mtcars$gear <- as.factor(mtcars$gear) |
| 64 |
|
| 65 |
fit <- polr( |
| 66 |
gear ~ cyl, |
| 67 |
data = mtcars, |
| 68 |
Hess = TRUE |
| 69 |
) |
| 70 |
|
| 71 |
expect_snapshot(.res <- tidy(fit, p.values = TRUE)) |
| 72 |
}) |