Skip to content

Commit 594cb97

Browse files
authored
Inconsistency in the use of parenthesis between parameters() and compare_parameters() (#1029)
* Inconsistency in the use of parenthesis between `parameters()` and `compare_parameters()` Fixes #1028 * fix * fix * update snapshots * update test * fix printing issue * submit to PR
1 parent 33f8987 commit 594cb97

26 files changed

+335
-251
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.22.2.18
4+
Version: 0.22.2.19
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
* Improved printing for `simulate_parameters()` for models from packages *mclogit*.
3636

37+
* `print()` for `compare_parameters()` now also puts factor levels into square
38+
brackets, like the `print()` method for `model_parameters()`.
39+
3740
## Bug fixes
3841

3942
* Arguments like `digits` etc. were ignored in `model_parameters() for objects

R/1_model_parameters.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#' [`print_md()`][print_md.parameters_model]. \cr \cr **For developers**, if
6262
#' speed performance is an issue, you can use the (undocumented) `pretty_names`
6363
#' argument, e.g. `model_parameters(..., pretty_names = FALSE)`. This will
64-
#' skip the formatting of the coefficient names and make `model_parameters()`
64+
#' skip the formatting of the coefficient names and makes `model_parameters()`
6565
#' faster.
6666
#'
6767
#' @section Standardization of model coefficients:

R/compare_parameters.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#' @name compare_parameters
33
#'
44
#' @description Compute and extract model parameters of multiple regression
5-
#' models. See [model_parameters()] for further details.
5+
#' models. See [`model_parameters()`] for further details.
66
#'
77
#' @param ... One or more regression model objects, or objects returned by
88
#' `model_parameters()`. Regression models may be of different model
99
#' types. Model objects may be passed comma separated, or as a list.
1010
#' If model objects are passed with names or the list has named elements,
1111
#' these names will be used as column names.
1212
#' @param component Model component for which parameters should be shown. See
13-
#' documentation for related model class in [model_parameters()].
13+
#' documentation for related model class in [`model_parameters()`].
1414
#' @param column_names Character vector with strings that should be used as
1515
#' column headers. Must be of same length as number of models in `...`.
1616
#' @param ci_method Method for computing degrees of freedom for p-values
@@ -303,11 +303,6 @@ compare_models <- compare_parameters
303303
}
304304
}
305305
}
306-
307-
if (!is.null(x$Parameter)) {
308-
x$Parameter <- gsub("]", ")", gsub("[", "(", x$Parameter, fixed = TRUE), fixed = TRUE)
309-
}
310-
311306
x
312307
}
313308

R/print.compare_parameters.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ print.compare_parameters <- function(x,
4242
zap_small = FALSE,
4343
groups = NULL,
4444
column_width = NULL,
45-
ci_brackets = c("(", ")"),
45+
ci_brackets = c("[", "]"),
4646
select = NULL,
4747
...) {
4848
# save original input

R/print.parameters_model.R

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,33 @@
1212
#' printed. There are three options for this argument:
1313
#'
1414
#' 1. Selecting columns by name or index
15-
#' \cr
15+
#'
1616
#' `select` can be a character vector (or numeric index) of column names that
17-
#' should be printed. There are two pre-defined options for selecting columns:
18-
#' `select = "minimal"` prints coefficients, confidence intervals and p-values,
19-
#' while `select = "short"` prints coefficients, standard errors and p-values.
17+
#' should be printed, where columns are extracted from the data frame returned
18+
#' by `model_parameters()` and related functions.
19+
#'
20+
#' There are two pre-defined options for selecting columns:
21+
#' `select = "minimal"` prints coefficients, confidence intervals and
22+
#' p-values, while `select = "short"` prints coefficients, standard errors and
23+
#' p-values.
2024
#'
2125
#' 2. A string expression with layout pattern
22-
#' \cr
23-
#' `select` is a string with "tokens" enclosed in braces. These tokens will
24-
#' be replaced by their associated columns, where the selected columns will
25-
#' be collapsed into one column. However, it is possible to create multiple
26-
#' columns as well. Following tokens are replaced by the related coefficients
27-
#' or statistics: `{estimate}`, `{se}`, `{ci}` (or `{ci_low}` and `{ci_high}`),
28-
#' `{p}` and `{stars}`. The token `{ci}` will be replaced by `{ci_low}, {ci_high}`.
29-
#' Furthermore, a `|` separates values into new cells/columns. If
30-
#' `format = "html"`, a `<br>` inserts a line break inside a cell. See
26+
#'
27+
#' `select` is a string with "tokens" enclosed in braces. These tokens will be
28+
#' replaced by their associated columns, where the selected columns will be
29+
#' collapsed into one column. Following tokens are replaced by the related
30+
#' coefficients or statistics: `{estimate}`, `{se}`, `{ci}` (or `{ci_low}` and
31+
#' `{ci_high}`), `{p}` and `{stars}`. The token `{ci}` will be replaced by
32+
#' `{ci_low}, {ci_high}`. Example: `select = "{estimate}{stars} ({ci})"`
33+
#'
34+
#' It is possible to create multiple columns as well. A `|` separates values
35+
#' into new cells/columns. Example: `select = "{estimate} ({ci})|{p}"`.
36+
#'
37+
#' If `format = "html"`, a `<br>` inserts a line break inside a cell. See
3138
#' 'Examples'.
3239
#'
3340
#' 3. A string indicating a pre-defined layout
34-
#' \cr
41+
#'
3542
#' `select` can be one of the following string values, to create one of the
3643
#' following pre-defined column layouts:
3744
#'

R/print_html.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ print_html.compare_parameters <- function(x,
214214
groups = groups
215215
)
216216

217+
# replace brackets by parenthesis
218+
if (!is.null(ci_brackets) && "Parameter" %in% colnames(formatted_table)) {
219+
formatted_table$Parameter <- gsub("[", ci_brackets[1], formatted_table$Parameter, fixed = TRUE)
220+
formatted_table$Parameter <- gsub("]", ci_brackets[2], formatted_table$Parameter, fixed = TRUE)
221+
}
222+
217223
out <- insight::export_table(
218224
formatted_table,
219225
format = "html",

R/print_md.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ print_md.compare_parameters <- function(x,
176176
engine = engine
177177
)
178178

179+
# replace brackets by parenthesis
180+
if (!is.null(ci_brackets) && "Parameter" %in% colnames(formatted_table)) {
181+
formatted_table$Parameter <- gsub("[", ci_brackets[1], formatted_table$Parameter, fixed = TRUE)
182+
formatted_table$Parameter <- gsub("]", ci_brackets[2], formatted_table$Parameter, fixed = TRUE)
183+
}
184+
179185
if (identical(engine, "tt")) {
180186
# retrieve output format - print_md() may be called from print_html()
181187
dots <- list(...)
@@ -285,7 +291,11 @@ print_md.parameters_pca <- print_md.parameters_efa
285291
# Equivalence test ----------------------------
286292

287293
#' @export
288-
print_md.equivalence_test_lm <- function(x, digits = 2, ci_brackets = c("(", ")"), zap_small = FALSE, ...) {
294+
print_md.equivalence_test_lm <- function(x,
295+
digits = 2,
296+
ci_brackets = c("(", ")"),
297+
zap_small = FALSE,
298+
...) {
289299
rule <- attributes(x)$rule
290300
rope <- attributes(x)$rope
291301

R/utils_format.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,19 @@
440440
}
441441
# create a pretty level for the reference category
442442
pretty_level <- paste0(fn_clean, " [", sub(fn, "", reference_level, fixed = TRUE), "]")
443+
pretty_level <- gsub("_", " ", pretty_level, fixed = TRUE)
444+
# special handling for "cut()"
445+
pattern_cut_right <- "(.*)\\((.*),(.*)\\]\\]$"
446+
pattern_cut_left <- "(.*)\\[(.*),(.*)\\)\\]$"
447+
if (all(grepl(pattern_cut_right, pretty_level))) {
448+
lower_bounds <- gsub(pattern_cut_right, "\\2", pretty_level)
449+
upper_bounds <- gsub(pattern_cut_right, "\\3", pretty_level)
450+
pretty_level <- gsub(pattern_cut_right, paste0("\\1>", as.numeric(lower_bounds), "-", upper_bounds, "]"), pretty_level)
451+
} else if (all(grepl(pattern_cut_left, pretty_level))) {
452+
lower_bounds <- gsub(pattern_cut_left, "\\2", pretty_level)
453+
upper_bounds <- gsub(pattern_cut_left, "\\3", pretty_level)
454+
pretty_level <- gsub(pattern_cut_left, paste0("\\1", as.numeric(lower_bounds), "-<", upper_bounds, "]"), pretty_level)
455+
}
443456
# insert new pretty level at the correct position in "pretty_names"
444457
pretty_names <- .insert_element_at(
445458
pretty_names,

man/bootstrap_parameters.Rd

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)