-
-
Notifications
You must be signed in to change notification settings - Fork 40
marginaleffects 0.29.0 #1154
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
marginaleffects 0.29.0 #1154
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ model_parameters.marginaleffects <- function(model, | |
| insight::check_if_installed("marginaleffects") | ||
|
|
||
| # Bayesian models have posterior draws as attribute | ||
| is_bayesian <- !is.null(suppressWarnings(marginaleffects::get_draws(model, "PxD"))) | ||
| is_bayesian <- suppressWarnings(!is.null(marginaleffects::get_draws(model, "PxD"))) | ||
|
|
||
| if (is_bayesian) { | ||
| # Bayesian | ||
|
|
@@ -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")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vincentarelbundock Why did you remove this code?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The package has not produced objecta of this class for over a year "marginalmeans"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, ok! |
||
| if (inherits(model, "comparisons")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if (inherits(model, "marginalmeans")) {
attr(out, "coefficient_name") <- "Marginal Means"
} else if (inherits(model, "comparisons")) { |
||
| attr(out, "coefficient_name") <- "Estimate" | ||
| attr(out, "title") <- "Contrasts between Adjusted Predictions" | ||
| if ("Type" %in% colnames(out)) { | ||
|
|
@@ -137,10 +135,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] | ||
|
|
@@ -153,7 +152,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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,13 +180,10 @@ test_that("predictions, using bayestestR #1063", { | |
| skip_if(is.null(m)) | ||
|
|
||
| d <- insight::get_datagrid(m, by = "Days", include_random = TRUE) | ||
| x <- marginaleffects::avg_predictions(m, newdata = d, by = "Days") | ||
| x <- marginaleffects::predictions(m, newdata = d, allow_new_levels = TRUE) | ||
| out <- model_parameters(x) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vincentarelbundock Why did you change the function call?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, TBH. I think I had a problem that maybe wasn't a problem after all...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then I wasn't actually sure what the intended output was, so... |
||
| expect_named( | ||
| out, | ||
| c( | ||
| "Median", "CI", "CI_low", "CI_high", "pd", "ROPE_CI", "ROPE_low", | ||
| "ROPE_high", "ROPE_Percentage", "Days", "subgrp", "grp", "Subject" | ||
| ) | ||
| ) | ||
| cols <- c( | ||
| "Median", "CI", "CI_low", "CI_high", "pd", "ROPE_CI", "ROPE_low", | ||
| "ROPE_high", "ROPE_Percentage", "Days", "subgrp", "grp", "Subject") | ||
| expect_named(out, cols) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.