Skip to content

Commit

Permalink
parameters() fails on binomial mgcv::gam
Browse files Browse the repository at this point in the history
Fixes #1051
  • Loading branch information
strengejacke committed Dec 3, 2024
1 parent 13b6b07 commit 4f98ab9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/_snaps/printing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@
Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a Wald z-distribution approximation.

---

Code
print(model_parameters(m))
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.

# adding model summaries

Code
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-printing.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ withr::with_options(
expect_snapshot(print(out))
})
)

test_that("print model with multiple components", {
skip_if_not_installed("mgcv")
m <- mgcv::gam(vs ~ s(mpg), data = mtcars, family = "binomial")
expect_snapshot(print(model_parameters(m)))
})

0 comments on commit 4f98ab9

Please sign in to comment.