From 7aa6533c056859c2dd6efdc2d73533f3b71e095c Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 30 Apr 2024 13:50:50 +0200 Subject: [PATCH] Conflict between `include_reference` and `pretty_names` (#967) * Conflict between `include_reference` and `pretty_names` Fixes #961 * add test * update desc * insight remotes * Update DESCRIPTION --- DESCRIPTION | 4 +-- R/utils_model_parameters.R | 6 ++-- tests/testthat/test-model_parameters_df.R | 38 ++++++++++++----------- tests/testthat/test-pretty_namesR.R | 12 +++++++ 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1f4e2c5fb..0b8d8ccf0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", @@ -139,7 +139,6 @@ Suggests: haven, httr, Hmisc, - ivprobit, ivreg, knitr, lavaan, @@ -219,3 +218,4 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true +Remotes: easystats/insight diff --git a/R/utils_model_parameters.R b/R/utils_model_parameters.R index 6301f3e66..07037d0dc 100644 --- a/R/utils_model_parameters.R +++ b/R/utils_model_parameters.R @@ -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)) @@ -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 } diff --git a/tests/testthat/test-model_parameters_df.R b/tests/testthat/test-model_parameters_df.R index da8b44508..d347cd60d 100644 --- a/tests/testthat/test-model_parameters_df.R +++ b/tests/testthat/test-model_parameters_df.R @@ -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 --------------------------- diff --git a/tests/testthat/test-pretty_namesR.R b/tests/testthat/test-pretty_namesR.R index 3b650892c..b3ed219ab 100644 --- a/tests/testthat/test-pretty_namesR.R +++ b/tests/testthat/test-pretty_namesR.R @@ -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]" + ) + ) })