Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 11, 2023
1 parent c9a4eca commit 2b1dc4c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
10 changes: 10 additions & 0 deletions R/utils_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@
# copy object, so we save original data
out <- params

# if we use "keep" or "drop", we have less parameters in our data frame,
# so we need to make sure we only have those pretty_names, which names match
# the parameters in the data frame
pretty_names <- pretty_names[names(pretty_names) %in% params$Parameter]

# iterate all factors in the data and check if any factor was used in the model
for (fn in names(factors)) {
f <- factors[[fn]]
Expand Down Expand Up @@ -1040,6 +1045,11 @@
tables[[type]][[1]] <- insight::format_value(tables[[type]][[1]], digits = digits, protect_integers = TRUE)
}

# add the coefficient for the base-(reference)-level of factors?
if (add_reference) {
tables[[type]] <- .add_reference_level(tables[[type]])
}

formatted_table <- insight::format_table(
tables[[type]],
digits = digits, ci_digits = ci_digits,
Expand Down
44 changes: 44 additions & 0 deletions tests/testthat/test-printing_reference_level.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# skip_if(getRversion() < "4.0.0")

# test_that("simple reference level", {
# data(PlantGrowth)
# d <<- PlantGrowth
# m <- lm(weight ~ group, data = d)
# mp <- model_parameters(m)
# expect_snapshot(print(mp, add_reference = TRUE))

# data(mtcars)
# d <<- mtcars
# d$cyl <- as.factor(d$cyl)
# d$am <- as.factor(d$am)
# m <- lm(mpg ~ hp + cyl + gear + am, data = d)
# mp <- model_parameters(m)
# expect_snapshot(print(mp, add_reference = TRUE))

# data(iris)
# d <<- iris
# m <- lm(Sepal.Length ~ Sepal.Width * Species, data = d)
# mp <- model_parameters(m)
# expect_snapshot(print(mp, add_reference = TRUE))

# data(mtcars)
# d <<- mtcars
# d$gear <- as.factor(d$gear)
# m <- glm(vs ~ wt + gear, data = d, family = "binomial")
# expect_snapshot(print(model_parameters(m, exponentiate = TRUE, drop = "(Intercept)"), add_reference = TRUE))
# })

# test_that("reference for models with multiple components", {
# skip_on_cran()
# skip_if_not_installed("glmmTMB")
# data("fish")

# m1 <- glmmTMB::glmmTMB(
# count ~ child + camper + zg + (1 | ID),
# ziformula = ~ child + camper + (1 | persons),
# data = fish,
# family = glmmTMB::truncated_poisson()
# )

# print(model_parameters(m1), add_reference = TRUE)
# })

0 comments on commit 2b1dc4c

Please sign in to comment.