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