1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
skip_on_cran()
skip_if_not_installed("withr")
skip_if(getRversion() < "4.0.0")
withr::with_options(
list(parameters_interaction = "*", easystats_table_width = Inf),
{
# Splitting model components ----
test_that("print model with multiple components", {
skip_if_not_installed("glmmTMB")
data("Salamanders", package = "glmmTMB")
model <- glmmTMB::glmmTMB(count ~ spp + mined + (1 | site),
ziformula = ~ spp + mined,
family = glmmTMB::nbinom2(),
data = Salamanders
)
out <- model_parameters(model, exponentiate = TRUE)
expect_snapshot(print(out))
expect_snapshot(print(out, split_component = FALSE))
})
# Adding model summaries -----
test_that("adding model summaries", {
# summary doesn't show the R2 if performance is not installed so the
# snapshot breaks between R CMD check "classic" and "strict"
skip_if_not_installed("performance")
model <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
out <- model_parameters(model, include_info = TRUE)
expect_snapshot(print(out))
})
# Group parameters ------
test_that("grouped parameters", {
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$gear <- as.factor(mtcars$gear)
model <- lm(mpg ~ hp + gear * vs + cyl + drat, data = mtcars)
# don't select "Intercept" parameter
out <- model_parameters(model, drop = "^\\(Intercept")
expect_snapshot(
print(out, groups = list(
Engine = c("cyl6", "cyl8", "vs", "hp"),
Interactions = c("gear4:vs", "gear5:vs"),
Controls = c(2, 3, 7)
))
)
expect_snapshot(
print(out,
sep = " ",
groups = list(
Engine = c("cyl6", "cyl8", "vs", "hp"),
Interactions = c("gear4:vs", "gear5:vs"),
Controls = c(2, 3, 7)
)
)
)
})
# Digits ------
test_that("digits and ci_digits", {
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$gear <- as.factor(mtcars$gear)
model <- lm(mpg ~ hp + gear + vs + cyl + drat, data = mtcars)
expect_snapshot(model_parameters(model, digits = 4))
expect_snapshot(model_parameters(model, digits = 4, ci_digits = 1))
out <- model_parameters(model)
expect_snapshot(print(out, digits = 4))
expect_snapshot(print(out, digits = 4, ci_digits = 1))
})
# Table templates ------
test_that("select pattern", {
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$gear <- as.factor(mtcars$gear)
model <- lm(mpg ~ hp + gear * vs + cyl + drat, data = mtcars)
# don't select "Intercept" parameter
out <- model_parameters(model, drop = "^\\(Intercept")
expect_snapshot(
print(out, groups = list(
Engine = c("cyl6", "cyl8", "vs", "hp"),
Interactions = c("gear4:vs", "gear5:vs"),
Controls = c(2, 3, 7)
))
)
expect_snapshot(print(out, select = "{coef} ({se})"))
expect_snapshot(print(out, select = "{coef}{stars}|[{ci}]"))
expect_snapshot(
print(out, groups = list(
Engine = c("cyl6", "cyl8", "vs", "hp"),
Interactions = c("gear4:vs", "gear5:vs"),
Controls = c(2, 3, 7)
), select = "{coef}{stars}|[{ci}]")
)
expect_snapshot(
print(out,
sep = " ",
groups = list(
Engine = c("cyl6", "cyl8", "vs", "hp"),
Interactions = c("gear4:vs", "gear5:vs"),
Controls = c(2, 3, 7)
),
select = "{coef}{stars}|[{ci}]"
)
)
})
}
)
withr::with_options(
list(parameters_warning_exponentiate = TRUE),
test_that("no more message about interpretation of log-resoponse", {
data(mtcars)
m <- lm(log(mpg) ~ gear, data = mtcars)
out <- model_parameters(m, exponentiate = TRUE)
expect_snapshot(print(out))
})
)
withr::with_options(
list(parameters_warning_exponentiate = TRUE),
test_that("no fail for mgcv-binomial", {
skip_if_not_installed("mgcv")
m <- mgcv::gam(vs ~ s(mpg), data = mtcars, family = "binomial")
out <- model_parameters(m)
expect_snapshot(print(out))
})
)
|