From eff54e5f48ef9d2c9cb51dece6987f7246552dfb Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Dec 2024 21:18:31 +0100 Subject: [PATCH] parameters() fails on binomial mgcv::gam (#1052) * parameters() fails on binomial mgcv::gam Fixes #1051 * news. desc * fix * update snapshots * include performance remotes * styler --- DESCRIPTION | 4 ++-- NEWS.md | 9 +++++++++ R/dominance_analysis.R | 2 +- R/format.R | 7 ++++++- tests/testthat/_snaps/printing.md | 21 +++++++++++++++++++++ tests/testthat/test-printing.R | 10 ++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5d6fff562..176ab606a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.24.0.2 +Version: 0.24.0.3 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -224,4 +224,4 @@ Config/testthat/edition: 3 Config/testthat/parallel: true Config/Needs/website: easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true -Remotes: easystats/datawizard +Remotes: easystats/datawizard, easystats/performance diff --git a/NEWS.md b/NEWS.md index a831e8252..c80da9213 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# parameters 0.24.1 + +## Bug fixes + +* Fixed issue when printing `model_parameters()` with models from `mgcv::gam()`. + +* Fixed issues due to breaking changes in the latest release of the *datawizard* + package. + # parameters 0.24.0 ## Breaking Changes diff --git a/R/dominance_analysis.R b/R/dominance_analysis.R index be6542a50..8981c714b 100644 --- a/R/dominance_analysis.R +++ b/R/dominance_analysis.R @@ -571,7 +571,7 @@ dominance_analysis <- function(model, sets = NULL, all = NULL, } da_df_res <- datawizard::data_rename( - da_df_res, + da_df_res, replacement = c( "Parameter", "General_Dominance", "Percent", "Ranks", "Subset" diff --git a/R/format.R b/R/format.R index 1939fdd5e..94dd3f874 100644 --- a/R/format.R +++ b/R/format.R @@ -887,9 +887,14 @@ format.parameters_sem <- function(x, logit_model <- isTRUE(.additional_arguments(x, "logit_link", FALSE)) || isTRUE(attributes(x)$coefficient_name %in% c("Log-Odds", "Odds Ratio")) + # remove NA and infinite values from spurios coefficients + if (!is.null(spurious_coefficients)) { + spurious_coefficients <- spurious_coefficients[!is.na(spurious_coefficients) & !is.infinite(spurious_coefficients)] # nolint + } + # check for complete separation coefficients or possible issues with # too few data points - if (!is.null(spurious_coefficients) && logit_model) { + if (!is.null(spurious_coefficients) && length(spurious_coefficients) && logit_model) { if (any(spurious_coefficients > 50)) { msg <- c(msg, "Some coefficients are very large, which may indicate issues with complete separation.") # nolint } else if (any(spurious_coefficients > 15)) { diff --git a/tests/testthat/_snaps/printing.md b/tests/testthat/_snaps/printing.md index cf03e1e23..769e0e344 100644 --- a/tests/testthat/_snaps/printing.md +++ b/tests/testthat/_snaps/printing.md @@ -361,3 +361,24 @@ Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed using a Wald t-distribution approximation. +# no fail for mgcv-binomial + + Code + print(out) + Output + # Fixed Effects + + Parameter | Log-Odds | SE | 95% CI | z | df | p + --------------------------------------------------------------------- + (Intercept) | -0.20 | 0.50 | [-1.18, 0.79] | -0.39 | 29.98 | 0.695 + + # Smooth Terms + + Parameter | z | df | p + --------------------------------------- + Smooth term (mpg) | 7.24 | 1.02 | 0.007 + Message + + The model has a log- or logit-link. Consider using `exponentiate = + TRUE` to interpret coefficients as ratios. + diff --git a/tests/testthat/test-printing.R b/tests/testthat/test-printing.R index 542f517cf..763c6acbb 100644 --- a/tests/testthat/test-printing.R +++ b/tests/testthat/test-printing.R @@ -118,3 +118,13 @@ withr::with_options( 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)) + }) +)