Skip to content

Commit

Permalink
Merge branch 'main' into predictions_term
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 24, 2024
2 parents 0108a08 + 0b1d3c3 commit e07e0e1
Show file tree
Hide file tree
Showing 45 changed files with 2,101 additions and 2,062 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: marginaleffects
Title: Predictions, Comparisons, Slopes, Marginal Means, and Hypothesis Tests
Version: 0.23.0.6
Version: 0.23.0.7
Authors@R:
c(person(given = "Vincent",
family = "Arel-Bundock",
Expand Down Expand Up @@ -174,7 +174,7 @@ Suggests:
tidyr,
tidyverse,
tinysnapshot,
tinytable (>= 0.4.0),
tinytable (>= 0.6.1),
tinytest,
titanic,
truncreg,
Expand Down Expand Up @@ -209,6 +209,7 @@ Collate:
'get_contrast_data_logical.R'
'get_contrast_data_numeric.R'
'get_contrasts.R'
'get_draws.R'
'get_group_names.R'
'get_hypothesis.R'
'get_jacobian.R'
Expand Down Expand Up @@ -284,7 +285,6 @@ Collate:
'plot_comparisons.R'
'plot_predictions.R'
'plot_slopes.R'
'posterior_draws.R'
'predictions.R'
'print.R'
'recall.R'
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export(expect_margins)
export(expect_predictions)
export(expect_slopes)
export(get_coef)
export(get_draws)
export(get_group_names)
export(get_model_matrix)
export(get_predict)
Expand All @@ -213,7 +214,6 @@ export(plot_comparisons)
export(plot_predictions)
export(plot_slopes)
export(posterior_draws)
export(posteriordraws)
export(predictions)
export(set_coef)
export(slopes)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Breaking change:

Bugs:

* Intercept only model now works with `avg_predictions()`. Thanks to @vbrazao for report #1230.
* `systemfit` models returned no standard errors when the same variables entered in different parts of the model. Thanks to @mronkko for report #1233.

New features:
Expand All @@ -22,6 +23,8 @@ Misc:
* Be less strict about combining columns of different types. This allows us to handle types like `haven_labelled`. Thanks to @mwindzio for report #1238.
* In `lme4` and `glmmTMB` models, warnings are now silenced when the user specifically passes `re.form=NULL`. Thanks to @mattansb for the feature request.
* New startup message appears once per 24hr period and can be suppressed using `options(marginaleffects_startup_message = FALSE)`.
* `posterior_draws()` is renamed `get_draws()` because it also applies to bootstrap and simulation-based inference draws.
* `get_coef()` and `get_vcov()` are now documented on the main website, as they are useful helper functions.

## 0.23.0

Expand Down
81 changes: 34 additions & 47 deletions R/broom.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,86 +9,72 @@ generics::glance


#' tidy helper
#'
#'
#' @noRd
#' @export
tidy.comparisons <- function(x, ...) {
insight::check_if_installed("tibble")
out <- tibble::as_tibble(x)
if (!"term" %in% names(out)) {
lab <- seq_len(nrow(out))
if ("group" %in% colnames(out) || is.character(attr(x, "by"))) {
tmp <- c("group", attr(x, "by"))
tmp <- Filter(function(j) j %in% colnames(x), tmp)
if (length(tmp) > 0) {
tmp <- do.call(paste, out[, tmp])
if (anyDuplicated(tmp)) {
tmp <- paste(seq_len(nrow(out)), tmp)
}
lab <- tmp
}
}
out[["term"]] <- lab
}
return(out)
insight::check_if_installed("tibble")
out <- tibble::as_tibble(x)
return(out)
}


#' tidy helper
#'
#'
#' @noRd
#' @export
tidy.slopes <- tidy.comparisons


#' tidy helper
#'
#'
#' @noRd
#' @export
tidy.predictions <- tidy.comparisons


#' tidy helper
#'
#'
#' @noRd
#' @export
tidy.hypotheses <- tidy.comparisons


#' tidy helper
#'
#'
#' @noRd
#' @export
tidy.marginalmeans <- function(x, ...) {
insight::check_if_installed("tibble")
tibble::as_tibble(x)
insight::check_if_installed("tibble")
tibble::as_tibble(x)
}


#' @noRd
#' @export
glance.slopes <- function(x, ...) {
insight::check_if_installed("insight")
insight::check_if_installed("modelsummary")
model <- tryCatch(attr(x, "model"), error = function(e) NULL)
if (is.null(model) || isTRUE(checkmate::check_string(model))) {
model <- tryCatch(attr(x, "call")[["model"]], error = function(e) NULL)
}
gl <- suppressMessages(suppressWarnings(try(
modelsummary::get_gof(model, ...), silent = TRUE)))
if (inherits(gl, "data.frame")) {
out <- data.frame(gl)
} else {
out <- NULL
}
vcov.type <- attr(x, "vcov.type")
if (is.null(out) && !is.null(vcov.type)) {
out <- data.frame("vcov.type" = vcov.type)
} else if (!is.null(out)) {
out[["vcov.type"]] <- vcov.type
}
out <- tibble::as_tibble(out)
return(out)
insight::check_if_installed("insight")
insight::check_if_installed("modelsummary")
model <- tryCatch(attr(x, "model"), error = function(e) NULL)
if (is.null(model) || isTRUE(checkmate::check_string(model))) {
model <- tryCatch(attr(x, "call")[["model"]], error = function(e) NULL)
}
gl <- suppressMessages(suppressWarnings(try(
modelsummary::get_gof(model, ...),
silent = TRUE)))
if (inherits(gl, "data.frame")) {
out <- data.frame(gl)
} else {
out <- NULL
}
vcov.type <- attr(x, "vcov.type")
if (is.null(out) && !is.null(vcov.type)) {
out <- data.frame("vcov.type" = vcov.type)
} else if (!is.null(out)) {
out[["vcov.type"]] <- vcov.type
}
out <- tibble::as_tibble(out)
return(out)
}


Expand All @@ -109,4 +95,5 @@ glance.hypotheses <- glance.slopes

#' @noRd
#' @export
glance.marginalmeans <- glance.slopes
glance.marginalmeans <- glance.slopes

Loading

0 comments on commit e07e0e1

Please sign in to comment.