Skip to content

Commit 340b90c

Browse files
committed
pretty_labels attribute includes NAs with interactions
Fixes #1032
1 parent 333c2a4 commit 340b90c

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: parameters
33
Title: Processing of Model Parameters
4-
Version: 0.23.0.2
4+
Version: 0.23.0.3
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* The `robust` argument, which was deprecated for a long time, is now no longer
66
supported. Please use `vcov` and `vcov_args` instead.
77

8+
## Bug fixes
9+
10+
* Fixed bug when extracting 'pretty labels' for model parameters, which could
11+
fail when predictors were character vectors.
12+
813
# parameters 0.23.0
914

1015
## Breaking Changes

R/format_parameters.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ format_parameters.parameters_model <- function(model, ...) {
412412

413413
# coefficient names (not labels)
414414
preds <- lapply(colnames(mf), function(i) {
415+
if (is.character(mf[[i]])) {
416+
mf[[i]] <- as.factor(mf[[i]])
417+
}
415418
if (is.factor(mf[[i]])) {
416419
i <- paste0(i, levels(mf[[i]]))
417420
}

R/utils_model_parameters.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
attr(params, "bootstrap") <- bootstrap
5252
attr(params, "iterations") <- iterations
5353
attr(params, "p_adjust") <- p_adjust
54-
attr(params, "robust_vcov") <- isTRUE(list(...)$robust) || "vcov" %in% names(list(...))
54+
attr(params, "robust_vcov") <- "vcov" %in% names(list(...))
5555
attr(params, "ignore_group") <- isFALSE(group_level)
5656
attr(params, "ran_pars") <- isFALSE(group_level)
5757
attr(params, "show_summary") <- isTRUE(include_info)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# pretty_labels
2+
3+
Code
4+
print(p)
5+
Output
6+
Parameter | Log-Odds | SE | 95% CI | z | p
7+
------------------------------------------------------------
8+
(Intercept) | 0.44 | 0.07 | [0.30, 0.58] | 6.07 | < .001
9+
X | 0.26 | 0.10 | [0.06, 0.46] | 2.52 | 0.012
10+
M [b] | 0.57 | 0.11 | [0.36, 0.78] | 5.29 | < .001
11+
M [c] | 0.97 | 0.11 | [0.75, 1.19] | 8.75 | < .001
12+
X × M [b] | 0.89 | 0.17 | [0.56, 1.24] | 5.17 | < .001
13+
X × M [c] | 1.41 | 0.21 | [1.00, 1.84] | 6.58 | < .001
14+
Message
15+
16+
Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
17+
computed using a Wald z-distribution approximation.
18+

tests/testthat/test-pretty_namesR.R renamed to tests/testthat/test-pretty_names.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,30 @@ test_that("pretty_names", {
3333
)
3434
)
3535
})
36+
37+
38+
test_that("pretty_labels", {
39+
set.seed(1024)
40+
N <- 5000
41+
X <- rbinom(N, 1, .5)
42+
M <- sample(c("a", "b", "c"), N, replace = TRUE)
43+
b <- runif(8, -1, 1)
44+
Y <- rbinom(N, 1, prob = plogis(
45+
b[1] + b[2] * X +
46+
b[3] * (M == "b") + b[4] * (M == "b") + b[5] * (M == "c") +
47+
b[6] * X * (M == "a") + b[7] * X + (M == "b") +
48+
b[8] * X * (M == "c")
49+
))
50+
dat <- data.frame(Y, X, M, stringsAsFactors = FALSE)
51+
mod <- glm(Y ~ X * M, data = dat, family = binomial)
52+
53+
p <- parameters(mod)
54+
expect_identical(
55+
attr(p, "pretty_labels"),
56+
c(
57+
`(Intercept)` = "(Intercept)", X = "X", Mb = "M [b]", Mc = "M [c]",
58+
`X:Mb` = "X × M [b]", `X:Mc` = "X × M [c]"
59+
)
60+
)
61+
expect_snapshot(print(p))
62+
})

0 commit comments

Comments
 (0)