Skip to content

Commit 4f98ab9

Browse files
committed
parameters() fails on binomial mgcv::gam
Fixes #1051
1 parent 13b6b07 commit 4f98ab9

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

R/format.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,14 @@ format.parameters_sem <- function(x,
887887
logit_model <- isTRUE(.additional_arguments(x, "logit_link", FALSE)) ||
888888
isTRUE(attributes(x)$coefficient_name %in% c("Log-Odds", "Odds Ratio"))
889889

890+
# remove NA and infinite values from spurios coefficients
891+
if (!is.null(spurious_coefficients)) {
892+
spurious_coefficients <- spurious_coefficients[!is.na(spurious_coefficients) & !is.infinite(spurious_coefficients)] # nolint
893+
}
894+
890895
# check for complete separation coefficients or possible issues with
891896
# too few data points
892-
if (!is.null(spurious_coefficients) && logit_model) {
897+
if (!is.null(spurious_coefficients) && length(spurious_coefficients) && logit_model) {
893898
if (any(spurious_coefficients > 50)) {
894899
msg <- c(msg, "Some coefficients are very large, which may indicate issues with complete separation.") # nolint
895900
} else if (any(spurious_coefficients > 15)) {

tests/testthat/_snaps/printing.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@
7777
Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
7878
using a Wald z-distribution approximation.
7979

80+
---
81+
82+
Code
83+
print(model_parameters(m))
84+
Output
85+
# Fixed Effects
86+
87+
Parameter | Log-Odds | SE | 95% CI | z | df | p
88+
---------------------------------------------------------------------
89+
(Intercept) | -0.20 | 0.50 | [-1.18, 0.79] | -0.39 | 29.98 | 0.695
90+
91+
# Smooth Terms
92+
93+
Parameter | z | df | p
94+
---------------------------------------
95+
Smooth term (mpg) | 7.24 | 1.02 | 0.007
96+
Message
97+
98+
The model has a log- or logit-link. Consider using `exponentiate =
99+
TRUE` to interpret coefficients as ratios.
100+
80101
# adding model summaries
81102

82103
Code

tests/testthat/test-printing.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,9 @@ withr::with_options(
118118
expect_snapshot(print(out))
119119
})
120120
)
121+
122+
test_that("print model with multiple components", {
123+
skip_if_not_installed("mgcv")
124+
m <- mgcv::gam(vs ~ s(mpg), data = mtcars, family = "binomial")
125+
expect_snapshot(print(model_parameters(m)))
126+
})

0 commit comments

Comments
 (0)