Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 2 additions & 2 deletions 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.28.0.4
Version: 0.28.0.6
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -231,4 +231,4 @@ Config/testthat/parallel: true
Config/Needs/website: easystats/easystatstemplate
Config/Needs/check: stan-dev/cmdstanr
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight
Remotes: easystats/insight, easystats/bayestestR, vincentarelbundock/marginaleffects
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ S3method(model_parameters,lqm)
S3method(model_parameters,lqmm)
S3method(model_parameters,maov)
S3method(model_parameters,marginaleffects)
S3method(model_parameters,marginalmeans)
S3method(model_parameters,margins)
S3method(model_parameters,maxLik)
S3method(model_parameters,maxim)
Expand Down
23 changes: 9 additions & 14 deletions R/methods_marginaleffects.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ model_parameters.marginaleffects <- function(model,
# do not print or report these columns
out <- out[, !colnames(out) %in% c("predicted_lo", "predicted_hi"), drop = FALSE]

if (inherits(model, "marginalmeans")) {
attr(out, "coefficient_name") <- "Marginal Means"
} else if (inherits(model, "comparisons")) {
if (inherits(model, "comparisons")) {
attr(out, "coefficient_name") <- "Estimate"
attr(out, "title") <- "Contrasts between Adjusted Predictions"
if ("Type" %in% colnames(out)) {
Expand Down Expand Up @@ -88,10 +86,6 @@ model_parameters.marginaleffects <- function(model,
model_parameters.comparisons <- model_parameters.marginaleffects


#' @export
model_parameters.marginalmeans <- model_parameters.marginaleffects


#' @export
model_parameters.hypotheses <- model_parameters.marginaleffects

Expand All @@ -109,9 +103,9 @@ model_parameters.predictions <- function(model,
insight::check_if_installed("marginaleffects")

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

if (is_bayes) {
if (is_bayesian) {
# Bayesian
out <- suppressWarnings(bayestestR::describe_posterior(
model,
Expand All @@ -137,10 +131,11 @@ model_parameters.predictions <- function(model,
out$rowid <- out$Type <- out$rowid_dedup <- NULL

# find at-variables
at_variables <- attributes(model)$newdata_at
if (is.null(at_variables)) {
at_variables <- attributes(model)$by
}
at_variables <- c(
marginaleffects::components(model, "variable_names_datagrid"),
marginaleffects::components(model, "variable_names_by"),
marginaleffects::components(model, "variable_names_by_hypothesis")
)

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

# extract response, remove from data frame
reg_model <- attributes(model)$model
reg_model <- marginaleffects::components(model, "model")
if (!is.null(reg_model) && insight::is_model(reg_model)) {
resp <- insight::find_response(reg_model)
# check if response could be extracted
Expand Down
28 changes: 14 additions & 14 deletions tests/testthat/_snaps/brms.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Output
# Fixed Effects

Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------------------
(Intercept) | -0.25 | [-1.28, 0.75] | 68.62% | 0.999 | 3459.00
var_binom1 | -0.64 | [-2.09, 0.64] | 83.20% | 1.000 | 2820.00
groupsb | -0.22 | [-1.35, 0.87] | 64.75% | 1.000 | 3332.00
var_cont | -0.06 | [-0.14, 0.00] | 96.65% | 1.000 | 3528.00
var_binom1:groupsb | 0.53 | [-1.70, 2.69] | 69.25% | 1.000 | 2699.00
Parameter | Median | 95% CI | pd | Rhat | ESS
-------------------------------------------------------------------
(Intercept) | -0.25 | [-1.28, 0.75] | 68.62% | 0.999 | 3459
var_binom1 | -0.64 | [-2.09, 0.64] | 83.20% | 1.000 | 2820
groupsb | -0.22 | [-1.35, 0.87] | 64.75% | 1.000 | 3332
var_cont | -0.06 | [-0.14, 0.00] | 96.65% | 1.000 | 3528
var_binom1:groupsb | 0.53 | [-1.70, 2.69] | 69.25% | 1.000 | 2699
Message

Uncertainty intervals (equal-tailed) computed using a MCMC distribution
Expand All @@ -27,13 +27,13 @@
Output
# Fixed Effects

Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------------------
(Intercept) | 0.78 | [0.28, 2.11] | 68.62% | 0.999 | 3459.00
var_binom1 | 0.53 | [0.12, 1.90] | 83.20% | 1.000 | 2820.00
groupsb | 0.80 | [0.26, 2.38] | 64.75% | 1.000 | 3332.00
var_cont | 0.94 | [0.87, 1.00] | 96.65% | 1.000 | 3528.00
var_binom1:groupsb | 1.69 | [0.18, 14.80] | 69.25% | 1.000 | 2699.00
Parameter | Median | 95% CI | pd | Rhat | ESS
-------------------------------------------------------------------
(Intercept) | 0.78 | [0.28, 2.11] | 68.62% | 0.999 | 3459
var_binom1 | 0.53 | [0.12, 1.90] | 83.20% | 1.000 | 2820
groupsb | 0.80 | [0.26, 2.38] | 64.75% | 1.000 | 3332
var_cont | 0.94 | [0.87, 1.00] | 96.65% | 1.000 | 3528
var_binom1:groupsb | 1.69 | [0.18, 14.80] | 69.25% | 1.000 | 2699
Message

Uncertainty intervals (equal-tailed) computed using a MCMC distribution
Expand Down
Loading
Loading