Skip to content

Commit 63e1801

Browse files
marginaleffects 0.29.0
1 parent 48bee4c commit 63e1801

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

R/methods_marginaleffects.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ model_parameters.marginaleffects <- function(model,
1212
insight::check_if_installed("marginaleffects")
1313

1414
# Bayesian models have posterior draws as attribute
15-
is_bayesian <- !is.null(suppressWarnings(marginaleffects::get_draws(model, "PxD")))
15+
is_bayesian <- suppressWarnings(!is.null(marginaleffects::get_draws(model, "PxD")))
1616

1717
if (is_bayesian) {
1818
# Bayesian
@@ -48,9 +48,7 @@ model_parameters.marginaleffects <- function(model,
4848
# do not print or report these columns
4949
out <- out[, !colnames(out) %in% c("predicted_lo", "predicted_hi"), drop = FALSE]
5050

51-
if (inherits(model, "marginalmeans")) {
52-
attr(out, "coefficient_name") <- "Marginal Means"
53-
} else if (inherits(model, "comparisons")) {
51+
if (inherits(model, "comparisons")) {
5452
attr(out, "coefficient_name") <- "Estimate"
5553
attr(out, "title") <- "Contrasts between Adjusted Predictions"
5654
if ("Type" %in% colnames(out)) {
@@ -137,10 +135,11 @@ model_parameters.predictions <- function(model,
137135
out$rowid <- out$Type <- out$rowid_dedup <- NULL
138136

139137
# find at-variables
140-
at_variables <- attributes(model)$newdata_at
141-
if (is.null(at_variables)) {
142-
at_variables <- attributes(model)$by
143-
}
138+
at_variables <- c(
139+
marginaleffects::components(model, "variable_names_datagrid"),
140+
marginaleffects::components(model, "variable_names_by"),
141+
marginaleffects::components(model, "variable_names_by_hypothesis")
142+
)
144143

145144
# find cofficient name - differs for Bayesian models
146145
coef_name <- intersect(c("Predicted", "Coefficient"), colnames(out))[1]
@@ -153,7 +152,7 @@ model_parameters.predictions <- function(model,
153152
}
154153

155154
# extract response, remove from data frame
156-
reg_model <- attributes(model)$model
155+
reg_model <- marginaleffects::components(model, "model")
157156
if (!is.null(reg_model) && insight::is_model(reg_model)) {
158157
resp <- insight::find_response(reg_model)
159158
# check if response could be extracted

tests/testthat/test-marginaleffects.R

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,10 @@ test_that("predictions, using bayestestR #1063", {
180180
skip_if(is.null(m))
181181

182182
d <- insight::get_datagrid(m, by = "Days", include_random = TRUE)
183-
x <- marginaleffects::avg_predictions(m, newdata = d, by = "Days")
183+
x <- marginaleffects::predictions(m, newdata = d, allow_new_levels = TRUE)
184184
out <- model_parameters(x)
185-
expect_named(
186-
out,
187-
c(
188-
"Median", "CI", "CI_low", "CI_high", "pd", "ROPE_CI", "ROPE_low",
189-
"ROPE_high", "ROPE_Percentage", "Days", "subgrp", "grp", "Subject"
190-
)
191-
)
185+
cols <- c(
186+
"Median", "CI", "CI_low", "CI_high", "pd", "ROPE_CI", "ROPE_low",
187+
"ROPE_high", "ROPE_Percentage", "Days", "subgrp", "grp", "Subject")
188+
expect_named(out, cols)
192189
})

0 commit comments

Comments
 (0)