Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with parameters() on marginaleffects objects #901

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.21.1.5
Version: 0.21.1.6
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# parameters 0.21.2

## Changes

* The `ci_digits` argument of the `print()` method for `model_parameters()` now
defaults to the same value of `digits`.

* `model_parameters()` for objects from package *marginaleffects* now also
accepts the `exponentiate` argument.

## Bug fixes

* Fixed issue with wrong calculation of test-statistic and p-values in
Expand Down
6 changes: 3 additions & 3 deletions R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ display.parameters_model <- function(object,
footer = NULL,
align = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
footer_digits = 3,
ci_brackets = c("(", ")"),
Expand Down Expand Up @@ -132,7 +132,7 @@ display.parameters_brms_meta <- display.parameters_model
display.compare_parameters <- function(object,
format = "markdown",
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
select = NULL,
column_labels = NULL,
Expand Down Expand Up @@ -165,7 +165,7 @@ display.compare_parameters <- function(object,
display.parameters_sem <- function(object,
format = "markdown",
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_brackets = c("(", ")"),
...) {
Expand Down
6 changes: 3 additions & 3 deletions R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ equivalence_test.ggeffects <- function(x,
#' @export
format.equivalence_test_lm <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = NULL,
ci_brackets = NULL,
Expand Down Expand Up @@ -736,7 +736,7 @@ format.equivalence_test_lm <- function(x,
#' @export
print.equivalence_test_lm <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_brackets = NULL,
zap_small = FALSE,
Expand Down Expand Up @@ -794,7 +794,7 @@ plot.equivalence_test_lm <- function(x, ...) {
#' #' @export
#' print_md.equivalence_test_lm <- function(x,
#' digits = 2,
#' ci_digits = 2,
#' ci_digits = digits,
#' p_digits = 3,
#' ci_brackets = NULL,
#' zap_small = FALSE,
Expand Down
19 changes: 13 additions & 6 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ format.parameters_model <- function(x,
split_components = TRUE,
select = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = NULL,
ci_brackets = NULL,
Expand Down Expand Up @@ -259,7 +259,7 @@ format.compare_parameters <- function(x,
split_components = TRUE,
select = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = NULL,
ci_brackets = NULL,
Expand Down Expand Up @@ -468,16 +468,23 @@ format.compare_parameters <- function(x,
#' @export
format.parameters_sem <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
format = NULL,
ci_width = NULL,
ci_brackets = TRUE,
pretty_names = TRUE,
...) {
if (missing(digits)) digits <- .additional_arguments(x, "digits", 2)
if (missing(ci_digits)) ci_digits <- .additional_arguments(x, "ci_digits", 2)
if (missing(p_digits)) p_digits <- .additional_arguments(x, "p_digits", 3)
if (missing(digits)) {
digits <- .additional_arguments(x, "digits", 2)
}
if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}
if (missing(p_digits)) {
p_digits <- .additional_arguments(x, "p_digits", 3)
}

.format_columns_multiple_components(
x,
pretty_names = TRUE,
Expand Down
4 changes: 2 additions & 2 deletions R/methods_htest.R
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ model_parameters.svytable <- function(model, verbose = TRUE, ...) {
if ("ci_digits" %in% names(dot.arguments)) {
attr(params, "ci_digits") <- eval(dot.arguments[["ci_digits"]])
} else {
attr(params, "ci_digits") <- 2
attr(params, "ci_digits") <- NULL
}

if ("p_digits" %in% names(dot.arguments)) {
Expand Down Expand Up @@ -747,7 +747,7 @@ model_parameters.svytable <- function(model, verbose = TRUE, ...) {
if ("ci_digits" %in% names(dot.arguments)) {
attr(params, "ci_digits") <- eval(dot.arguments[["ci_digits"]])
} else {
attr(params, "ci_digits") <- 2
attr(params, "ci_digits") <- NULL
}

if ("p_digits" %in% names(dot.arguments)) {
Expand Down
14 changes: 10 additions & 4 deletions R/methods_lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,17 @@ p_value.blavaan <- p_value.BFBayesFactor
# print ---------------------------

#' @export
print.parameters_sem <- function(x, digits = 2, ci_digits = 2, p_digits = 3, ...) {
print.parameters_sem <- function(x, digits = 2, ci_digits = digits, p_digits = 3, ...) {
# check if user supplied digits attributes
if (missing(digits)) digits <- .additional_arguments(x, "digits", 2)
if (missing(ci_digits)) ci_digits <- .additional_arguments(x, "ci_digits", 2)
if (missing(p_digits)) p_digits <- .additional_arguments(x, "p_digits", 3)
if (missing(digits)) {
digits <- .additional_arguments(x, "digits", 2)
}
if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}
if (missing(p_digits)) {
p_digits <- .additional_arguments(x, "p_digits", 3)
}

verbose <- .additional_arguments(x, "verbose", TRUE)

Expand Down
14 changes: 9 additions & 5 deletions R/methods_marginaleffects.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @export
model_parameters.marginaleffects <- function(model,
ci = 0.95,
exponentiate = FALSE,
...) {
insight::check_if_installed("marginaleffects")
out <- insight::standardize_names(
Expand All @@ -18,10 +19,7 @@ model_parameters.marginaleffects <- function(model,
colnames(out)[colnames(out) == "contrast"] <- "Comparison"
colnames(out) <- gsub("^contrast_", "Comparison: ", colnames(out))

out <- tryCatch(
.add_model_parameters_attributes(out, model, ci, ...),
error = function(e) out
)
out <- .safe(.add_model_parameters_attributes(out, model, ci, exponentiate = exponentiate, ...), out)

attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))

Expand All @@ -41,6 +39,8 @@ model_parameters.marginaleffects <- function(model,
attr(out, "coefficient_name") <- "Estimate"
}

# exponentiate coefficients and SE/CI, if requested
out <- .exponentiate_parameters(out, model = NULL, exponentiate)

class(out) <- c("parameters_model", "see_parameters_model", class(out))
out
Expand Down Expand Up @@ -70,6 +70,7 @@ model_parameters.slopes <- model_parameters.marginaleffects
#' @export
model_parameters.predictions <- function(model,
ci = 0.95,
exponentiate = TRUE,
...) {
insight::check_if_installed("marginaleffects")

Expand All @@ -89,12 +90,15 @@ model_parameters.predictions <- function(model,
out[[resp]] <- NULL
}

out <- .safe(.add_model_parameters_attributes(out, model, ci, ...), out)
out <- .safe(.add_model_parameters_attributes(out, model, ci, exponentiate = exponentiate, ...), out)

attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
attr(out, "coefficient_name") <- "Predicted"
attr(out, "no_caption") <- TRUE

# exponentiate coefficients and SE/CI, if requested
out <- .exponentiate_parameters(out, model = NULL, exponentiate)

class(out) <- c("parameters_model", "see_parameters_model", class(out))
out
}
4 changes: 2 additions & 2 deletions R/print.compare_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ print.compare_parameters <- function(x,
subtitle = NULL,
footer = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
zap_small = FALSE,
groups = NULL,
Expand All @@ -21,7 +21,7 @@ print.compare_parameters <- function(x,
digits <- .additional_arguments(x, "digits", digits)
}
if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", ci_digits)
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}
if (missing(p_digits)) {
p_digits <- .additional_arguments(x, "p_digits", p_digits)
Expand Down
6 changes: 3 additions & 3 deletions R/print.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ print.parameters_model <- function(x,
caption = NULL,
footer = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
footer_digits = 3,
show_sigma = FALSE,
Expand Down Expand Up @@ -256,7 +256,7 @@ print.parameters_model <- function(x,
digits <- .additional_arguments(x, "digits", digits)
}
if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", ci_digits)
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}
if (missing(p_digits)) {
p_digits <- .additional_arguments(x, "p_digits", p_digits)
Expand Down Expand Up @@ -371,7 +371,7 @@ print.parameters_random <- function(x, digits = 2, ...) {
split_components = TRUE,
select = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
zap_small = FALSE,
ci_width = "auto",
Expand Down
8 changes: 4 additions & 4 deletions R/print_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ print_html.parameters_model <- function(x,
footer = NULL,
align = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
footer_digits = 3,
ci_brackets = c("(", ")"),
Expand All @@ -30,7 +30,7 @@ print_html.parameters_model <- function(x,
}

if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", ci_digits)
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}

if (missing(p_digits)) {
Expand Down Expand Up @@ -139,7 +139,7 @@ print_html.compare_parameters <- function(x,
subtitle = NULL,
footer = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
zap_small = FALSE,
groups = NULL,
Expand All @@ -155,7 +155,7 @@ print_html.compare_parameters <- function(x,
}

if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", ci_digits)
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}

if (missing(p_digits)) {
Expand Down
12 changes: 6 additions & 6 deletions R/print_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ print_md.parameters_model <- function(x,
footer = NULL,
align = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
footer_digits = 3,
ci_brackets = c("(", ")"),
Expand All @@ -26,7 +26,7 @@ print_md.parameters_model <- function(x,
digits <- .additional_arguments(x, "digits", digits)
}
if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", ci_digits)
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}
if (missing(p_digits)) {
p_digits <- .additional_arguments(x, "p_digits", p_digits)
Expand Down Expand Up @@ -124,7 +124,7 @@ print_md.parameters_simulate <- print_md.parameters_model
#' @export
print_md.compare_parameters <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
caption = NULL,
subtitle = NULL,
Expand All @@ -137,7 +137,7 @@ print_md.compare_parameters <- function(x,
digits <- .additional_arguments(x, "digits", digits)
}
if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", ci_digits)
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}
if (missing(p_digits)) {
p_digits <- .additional_arguments(x, "p_digits", p_digits)
Expand Down Expand Up @@ -178,7 +178,7 @@ print_md.compare_parameters <- function(x,
#' @export
print_md.parameters_sem <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_brackets = c("(", ")"),
...) {
Expand All @@ -188,7 +188,7 @@ print_md.parameters_sem <- function(x,
digits <- .additional_arguments(x, "digits", digits)
}
if (missing(ci_digits)) {
ci_digits <- .additional_arguments(x, "ci_digits", ci_digits)
ci_digits <- .additional_arguments(x, "ci_digits", digits)
}
if (missing(p_digits)) {
p_digits <- .additional_arguments(x, "p_digits", p_digits)
Expand Down
4 changes: 2 additions & 2 deletions R/utils_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
.format_columns_single_component <- function(x,
pretty_names,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = "auto",
ci_brackets = TRUE,
Expand Down Expand Up @@ -758,7 +758,7 @@
pretty_names,
split_column = "Component",
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
coef_column = NULL,
format = NULL,
Expand Down
Loading