| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("multcomp") |
| 7 |
suppressPackageStartupMessages(library(multcomp)) |
| 8 |
|
| 9 |
amod <- aov(breaks ~ wool + tension, data = warpbreaks) |
| 10 |
wht <- glht(amod, linfct = mcp(tension = "Tukey")) |
| 11 |
|
| 12 |
test_that("multcomp tidier arguments", { |
| 13 |
check_arguments(tidy.glht) |
| 14 |
check_arguments(tidy.confint.glht) |
| 15 |
check_arguments(tidy.summary.glht) |
| 16 |
check_arguments(tidy.cld) |
| 17 |
}) |
| 18 |
|
| 19 |
test_that("tidy.glht", { |
| 20 |
td <- tidy(wht) |
| 21 |
check_tidy_output(td, strict = FALSE) |
| 22 |
check_dims(td, 3, 7) |
| 23 |
}) |
| 24 |
|
| 25 |
test_that("tidy.confint.glht", { |
| 26 |
td <- tidy(confint(wht)) |
| 27 |
check_tidy_output(td) |
| 28 |
check_dims(td, 3, 5) |
| 29 |
}) |
| 30 |
|
| 31 |
test_that("tidy.summary.glht works", { |
| 32 |
td <- tidy(summary(wht, test = adjusted("bonferroni"))) |
| 33 |
check_tidy_output(td, strict = FALSE) |
| 34 |
check_dims(td, 3, 7) |
| 35 |
|
| 36 |
expect_true("adj.p.value" %in% colnames(td)) |
| 37 |
expect_identical(td, tidy(wht, test = adjusted("bonferroni"))) |
| 38 |
|
| 39 |
td <- tidy(summary(wht, test = adjusted("none"))) |
| 40 |
expect_true("p.value" %in% colnames(td)) |
| 41 |
}) |
| 42 |
|
| 43 |
test_that("tidy.cld works", { |
| 44 |
td <- tidy(multcomp::cld(wht)) |
| 45 |
check_tidy_output(td, strict = FALSE) |
| 46 |
check_dims(td, 3, 2) |
| 47 |
}) |
| 48 |
|
| 49 |
test_that("tidy.glht consistency with tidy.TukeyHSD", { |
| 50 |
set.seed(13986) |
| 51 |
td_hsd <- tidy(TukeyHSD(amod, "tension")) |
| 52 |
td_glht <- tidy(wht, conf.int = TRUE) |> |
| 53 |
dplyr::select(-statistic) |> |
| 54 |
mutate(contrast = gsub(" ", "", contrast)) |
| 55 |
|
| 56 |
expect_equal( |
| 57 |
as.data.frame(td_hsd), |
| 58 |
as.data.frame(td_glht), |
| 59 |
ignore_attr = TRUE, |
| 60 |
tolerance = 0.001 |
| 61 |
) |
| 62 |
}) |