Debian Codegraph @

tests/testthat/test-ordinal.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("modeltests")
4 library(modeltests)
5
6 skip_if_not_installed("ordinal")
7 suppressPackageStartupMessages(library(ordinal))
8
9 fit <- clm(rating ~ temp * contact, data = wine)
10
11 fit_sc <- clm(rating ~ temp + contact, scale = ~ temp + contact, data = wine)
12
13 mfit <- clmm(rating ~ temp + contact + (1 | judge), data = wine)
14
15 test_that("ordinal tidier arguments", {
16 check_arguments(tidy.clm)
17 check_arguments(glance.clm)
18 check_arguments(augment.clm, strict = FALSE)
19
20 check_arguments(tidy.clmm)
21 check_arguments(glance.clmm)
22 })
23
24 test_that("tidy.clm", {
25 td <- tidy(fit)
26 td2 <- tidy(fit, conf.int = TRUE, exponentiate = TRUE)
27
28 check_tidy_output(td)
29 check_tidy_output(td2)
30
31 check_dims(td, 7, 6)
32 check_dims(td2, 7, 8)
33
34 expect_equal(
35 object = td$term,
36 expected = td2$term,
37 label = "'term' column in tidy output with `conf.int = FALSE`",
38 expected.label = "'term' column in tidy output with `conf.int = TRUE`",
39 info = "The terms (and their order) should be unaffected by whether `conf.int` = TRUE or `conf.int` = FALSE."
40 )
41 })
42
43 test_that("tidy.clm works with scale parameter", {
44 tt <- tidy(fit_sc)
45 expect_equal(
46 tt$coef.type,
47 rep(c("intercept", "location", "scale"), c(4, 2, 2))
48 )
49 })
50
51 test_that("glance.clm", {
52 gl <- glance(fit)
53 check_glance_outputs(gl)
54 check_dims(gl, 1, 6)
55 })
56
57 test_that("augment.clm", {
58 check_augment_function(
59 aug = augment.clm,
60 model = fit,
61 data = wine,
62 newdata = wine,
63 strict = FALSE
64 )
65
66 au_c <- augment(fit, type.predict = "class")
67 expect_equal(predict(fit, type = "class")$fit, au_c$.fitted)
68
69 au_p <- augment(fit, type.predict = "prob")
70 expect_equal(predict(fit, type = "prob")$fit, au_p$.fitted)
71 })
72
73
74 test_that("tidy.clmm", {
75 td <- tidy(mfit)
76 td2 <- tidy(mfit, conf.int = TRUE, exponentiate = TRUE)
77
78 check_tidy_output(td)
79 check_tidy_output(td2)
80
81 check_dims(td, 6, 6)
82 check_dims(td2, 6, 8)
83 })
84
85 test_that("glance.clmm", {
86 gl <- glance(mfit)
87 check_glance_outputs(gl)
88 check_dims(gl, 1, 5)
89 })