diff --git a/DESCRIPTION b/DESCRIPTION index 3a90eb87..dc2009c6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -68,7 +68,7 @@ VignetteBuilder: knitr Encoding: UTF-8 Language: en-US -RoxygenNote: 7.2.3.9000 +RoxygenNote: 7.3.0 Config/testthat/edition: 3 Config/testthat/parallel: true Roxygen: list(markdown = TRUE) diff --git a/R/estimate_means.R b/R/estimate_means.R index 7f2d27b1..222fa8a6 100644 --- a/R/estimate_means.R +++ b/R/estimate_means.R @@ -7,8 +7,6 @@ #' #' @inheritParams get_emmeans #' @inheritParams parameters::model_parameters.default -#' @param backend Whether to use 'emmeans' or 'marginaleffects' as a backend. -#' The latter is experimental and some features might not work. #' @inherit estimate_slopes details #' #' @examplesIf require("emmeans", quietly = TRUE) @@ -51,10 +49,10 @@ estimate_means <- function(model, fixed = NULL, transform = "response", ci = 0.95, - backend = "emmeans", + # backend = "emmeans", ...) { # Compute means - if (backend == "emmeans") { + # if (backend == "emmeans") { estimated <- get_emmeans(model, at, fixed, transform = transform, ...) # Summarize and clean @@ -72,11 +70,7 @@ estimate_means <- function(model, means <- means[names(means) != "1"] info <- attributes(estimated) - } else { - means <- .get_marginalmeans(model, at, fixed, transform = transform, ...) - - info <- attributes(means) - } + # } # Restore factor levels means <- datawizard::data_restoretype(means, insight::get_data(model)) diff --git a/R/get_marginalcontrasts.R b/R/get_marginalcontrasts.R deleted file mode 100644 index d2d9edc8..00000000 --- a/R/get_marginalcontrasts.R +++ /dev/null @@ -1,65 +0,0 @@ -# Wrapper around marginaleffects to get marginal means -# -# library(modelbased) -# if (require("marginaleffects")) { -# -# # Frequentist models -# # ------------------- -# model <- lm(Petal.Length ~ Sepal.Width * Species, data = iris) -# -# estimate_means(model) -# estimate_means(model, fixed = "Sepal.Width") -# estimate_means(model, at = c("Species", "Sepal.Width"), length = 2) -# estimate_means(model, at = "Species=c('versicolor', 'setosa')") -# estimate_means(model, at = "Sepal.Width=c(2, 4)") -# estimate_means(model, at = c("Species", "Sepal.Width=0")) -# estimate_means(model, at = "Sepal.Width", length = 5) -# estimate_means(model, at = "Sepal.Width=c(2, 4)") -# -# # Methods that can be applied to it: -# means <- estimate_means(model, fixed = "Sepal.Width") -# if (require("see")) { -# plot(means) # which runs visualisation_recipe() -# } -# standardize(means) -# -# if (require("lme4")) { -# data <- iris -# data$Petal.Length_factor <- ifelse(data$Petal.Length < 4.2, "A", "B") -# -# model <- lmer(Petal.Length ~ Sepal.Width + Species + (1 | Petal.Length_factor), data = data) -# estimate_means(model) -# estimate_means(model, at = "Sepal.Width", length = 3) -# } -# } -# } -# #' @keywords internal -# .get_marginalmeans <- function(model, -# at = "auto", -# fixed = NULL, -# transform = "response", -# ci = 0.95, -# ...) { -# -# # check if available -# insight::check_if_installed("marginaleffects") -# -# # Guess arguments -# args <- modelbased:::.guess_emmeans_arguments(model, at, fixed, ...) -# -# # Run emmeans -# means <- marginaleffects::marginalmeans(model, args$at, conf_level = ci) -# -# # Format names -# names(means)[names(means) %in% c("conf.low")] <- "CI_low" -# names(means)[names(means) %in% c("conf.high")] <- "CI_high" -# names(means)[names(means) %in% c("std.error")] <- "SE" -# names(means)[names(means) %in% c("marginalmean")] <- "Mean" -# names(means)[names(means) %in% c("p.value")] <- "p" -# names(means)[names(means) %in% c("statistic")] <- "p" -# -# ifelse(insight::find_statistic(model) == "t-statistic", "t", "statistic") -# -# out -# -# } diff --git a/R/get_marginalmeans.R b/R/get_marginalmeans.R deleted file mode 100644 index bd62f426..00000000 --- a/R/get_marginalmeans.R +++ /dev/null @@ -1,42 +0,0 @@ -#' @keywords internal -.get_marginalmeans <- function(model, - at = "auto", - fixed = NULL, - transform = "response", - ci = 0.95, - ...) { - # check if available - insight::check_if_installed("marginaleffects") - - # Guess arguments - args <- .guess_emmeans_arguments(model, at, fixed, ...) - - # Run emmeans - means <- marginaleffects::marginalmeans(model, variables = args$at, conf_level = ci) - - # TODO: this should be replaced by parameters::parameters(means) - # Format names - names(means)[names(means) %in% "conf.low"] <- "CI_low" - names(means)[names(means) %in% "conf.high"] <- "CI_high" - names(means)[names(means) %in% "std.error"] <- "SE" - names(means)[names(means) %in% "marginalmean"] <- "Mean" - names(means)[names(means) %in% "p.value"] <- "p" - names(means)[names(means) %in% "statistic"] <- ifelse(insight::find_statistic(model) == "t-statistic", "t", "statistic") - - # Format terms - term <- unique(means$term) # Get name of variable - if (length(term) > 1L) { - insight::format_error("marignalmeans backend can currently only deal with one 'at' variable.") - } - names(means)[names(means) %in% c("value")] <- term # Replace 'value' col by var name - means$term <- NULL - - # Drop stats - means$p <- NULL - means$t <- NULL - - # Store attributes - attr(means, "at") <- args$at - - means -} diff --git a/man/estimate_means.Rd b/man/estimate_means.Rd index 840663cb..e21f33ef 100644 --- a/man/estimate_means.Rd +++ b/man/estimate_means.Rd @@ -10,7 +10,6 @@ estimate_means( fixed = NULL, transform = "response", ci = 0.95, - backend = "emmeans", ... ) } @@ -38,9 +37,6 @@ probabilities.} \item{ci}{Confidence Interval (CI) level. Default to \code{0.95} (\verb{95\%}).} -\item{backend}{Whether to use 'emmeans' or 'marginaleffects' as a backend. -The latter is experimental and some features might not work.} - \item{...}{Other arguments passed for instance to \code{\link[insight:get_datagrid]{insight::get_datagrid()}}.} } \value{ diff --git a/man/modelbased-package.Rd b/man/modelbased-package.Rd index 6ad16b23..d2e92fe2 100644 --- a/man/modelbased-package.Rd +++ b/man/modelbased-package.Rd @@ -3,7 +3,6 @@ \docType{package} \name{modelbased-package} \alias{modelbased-package} -\alias{_PACKAGE} \alias{modelbased} \title{modelbased: Estimation of Model-Based Predictions, Contrasts and Means} \description{ diff --git a/tests/testthat/test-get_marginalmeans.R b/tests/testthat/test-get_marginalmeans.R deleted file mode 100644 index dda20c9a..00000000 --- a/tests/testthat/test-get_marginalmeans.R +++ /dev/null @@ -1,12 +0,0 @@ -test_that("get_marginaleffects", { - skip_if_not_installed("marginaleffects") - skip_if_not_installed("lme4") - model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris) - - estimated <- suppressMessages(estimate_means(model, backend = "marginaleffects")) - - expect_equal(nrow(estimated), 3) - expect_true(ncol(estimated) >= 5) - - # get_marginaleffects(model, trend = "Petal.Length", at = "Species", length = 10) -})