Skip to content

Commit

Permalink
Conflict between include_reference and pretty_names (#967)
Browse files Browse the repository at this point in the history
* Conflict between `include_reference` and `pretty_names`
Fixes #961

* add test

* update desc

* insight remotes

* Update DESCRIPTION
  • Loading branch information
strengejacke authored Apr 30, 2024
1 parent f4af408 commit 7aa6533
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.21.6.4
Version: 0.21.6.6
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -139,7 +139,6 @@ Suggests:
haven,
httr,
Hmisc,
ivprobit,
ivreg,
knitr,
lavaan,
Expand Down Expand Up @@ -219,3 +218,4 @@ Config/Needs/website:
r-lib/pkgdown,
easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight
6 changes: 3 additions & 3 deletions R/utils_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
attr(params, "log_link") <- isTRUE(grepl("log", info$link_function, fixed = TRUE))
attr(params, "logit_link") <- isTRUE(identical(info$link_function, "logit"))

# add parameters with value and variable
attr(params, "pretty_labels") <- .format_value_labels(params, model)

# save model call
attr(params, "model_call") <- .safe(insight::get_call(model))

Expand Down Expand Up @@ -208,6 +205,9 @@
attributes(params) <- utils::modifyList(a, attributes(params))
}

# add parameters with value and variable
attr(params, "pretty_labels") <- .format_value_labels(params, model)

row.names(params) <- NULL
params
}
Expand Down
38 changes: 20 additions & 18 deletions tests/testthat/test-model_parameters_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,30 @@ test_that("model_parameters.multinom", {
})


## TODO: archieved on CRAN - add test back once ivprobit is back on CRAN.

# ivprobit ---------------------------
test_that("model_parameters.ivprobit", {
skip_if_not_installed("ivprobit")
set.seed(123)
data(eco, package = "ivprobit")
# test_that("model_parameters.ivprobit", {
# skip_if_not_installed("ivprobit")
# set.seed(123)
# data(eco, package = "ivprobit")

# model
model <- ivprobit::ivprobit(
formula = d2 ~ ltass + roe + div | eqrat + bonus | ltass + roe + div + gap + cfa,
data = eco
)
# # model
# model <- ivprobit::ivprobit(
# formula = d2 ~ ltass + roe + div | eqrat + bonus | ltass + roe + div + gap + cfa,
# data = eco
# )

params <- suppressWarnings(model_parameters(model))
expect_equal(params$df_error, c(789L, 789L, 789L, 789L, 789L, 789L), tolerance = 1e-3)
expect_equal(params$CI_low, c(-35.96484, -0.27082, -0.15557, -1e-05, -15.95755, -1e-05), tolerance = 1e-3)
expect_equal(params$p, c(0.08355, 0.12724, 0.55684, 0.63368, 0.46593, 0.61493), tolerance = 1e-3)
# params <- suppressWarnings(model_parameters(model))
# expect_equal(params$df_error, c(789L, 789L, 789L, 789L, 789L, 789L), tolerance = 1e-3)
# expect_equal(params$CI_low, c(-35.96484, -0.27082, -0.15557, -1e-05, -15.95755, -1e-05), tolerance = 1e-3)
# expect_equal(params$p, c(0.08355, 0.12724, 0.55684, 0.63368, 0.46593, 0.61493), tolerance = 1e-3)

params <- suppressWarnings(model_parameters(model, ci_method = "normal"))
expect_equal(params$df_error, c(Inf, Inf, Inf, Inf, Inf, Inf), tolerance = 1e-3)
expect_equal(params$CI_low, c(-35.93553, -0.26895, -0.15522, -1e-05, -15.91859, -1e-05), tolerance = 1e-3)
expect_equal(params$p, c(0.08316, 0.12684, 0.55668, 0.63355, 0.46571, 0.61479), tolerance = 1e-3)
})
# params <- suppressWarnings(model_parameters(model, ci_method = "normal"))
# expect_equal(params$df_error, c(Inf, Inf, Inf, Inf, Inf, Inf), tolerance = 1e-3)
# expect_equal(params$CI_low, c(-35.93553, -0.26895, -0.15522, -1e-05, -15.91859, -1e-05), tolerance = 1e-3)
# expect_equal(params$p, c(0.08316, 0.12684, 0.55668, 0.63355, 0.46571, 0.61479), tolerance = 1e-3)
# })


# biglm ---------------------------
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-pretty_namesR.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ test_that("pretty_names", {
`factor(cyl)8` = "cyl [8]"
)
)

mtcars2 <- transform(mtcars, cyl = as.factor(cyl))
attr(mtcars2$cyl, "label") <- "Cylinders"
model <- lm(mpg ~ wt + cyl, data = mtcars2)
p <- model_parameters(model, pretty_names = "labels", include_reference = TRUE)
expect_identical(
attr(p, "pretty_labels"),
c(
`(Intercept)` = "(Intercept)", wt = "wt", cyl4 = "Cylinders [4]",
cyl6 = "Cylinders [6]", cyl8 = "Cylinders [8]"
)
)
})

0 comments on commit 7aa6533

Please sign in to comment.