|
7 | 7 | #' |
8 | 8 | #' @inheritParams get_emmeans |
9 | 9 | #' @inheritParams parameters::model_parameters.default |
10 | | -#' @param backend Whether to use 'emmeans' or 'marginaleffects' as a backend. |
11 | | -#' The latter is experimental and some features might not work. |
| 10 | +#' @param backend Whether to use `"emmeans"` or `"marginaleffects"` as a backend. |
| 11 | +#' Results are usually very similar. The major difference will be found for mixed |
| 12 | +#' models, where `backend = "marginaleffects"` will also average across random |
| 13 | +#' effects levels, producing "marginal predictions" (instead of "conditional |
| 14 | +#' predictions", see Heiss 2022). |
12 | 15 | #' @inherit estimate_slopes details |
13 | 16 | #' |
14 | | -#' @examplesIf require("emmeans", quietly = TRUE) |
| 17 | +#' @return A data frame of estimated marginal means. |
| 18 | +#' |
| 19 | +#' @references |
| 20 | +#' Heiss, A. (2022). Marginal and conditional effects for GLMMs with |
| 21 | +#' {marginaleffects}. Andrew Heiss. \doi{10.59350/xwnfm-x1827} |
| 22 | +#' |
| 23 | +#' @examplesIf all(insight::check_if_installed(c("emmeans", "see", "lme4"), quietly = TRUE)) |
15 | 24 | #' library(modelbased) |
16 | 25 | #' |
17 | 26 | #' # Frequentist models |
|
29 | 38 | #' # Methods that can be applied to it: |
30 | 39 | #' means <- estimate_means(model, by = c("Species", "Sepal.Width=0")) |
31 | 40 | #' |
32 | | -#' @examplesIf require("see") && require("emmeans", quietly = TRUE) |
33 | 41 | #' plot(means) # which runs visualisation_recipe() |
34 | | -#' |
35 | 42 | #' standardize(means) |
36 | 43 | #' |
37 | | -#' @examplesIf require("lme4") && require("emmeans", quietly = TRUE) |
38 | 44 | #' \donttest{ |
39 | 45 | #' data <- iris |
40 | 46 | #' data$Petal.Length_factor <- ifelse(data$Petal.Length < 4.2, "A", "B") |
41 | 47 | #' |
42 | | -#' model <- lmer(Petal.Length ~ Sepal.Width + Species + (1 | Petal.Length_factor), data = data) |
| 48 | +#' model <- lme4::lmer( |
| 49 | +#' Petal.Length ~ Sepal.Width + Species + (1 | Petal.Length_factor), |
| 50 | +#' data = data |
| 51 | +#' ) |
43 | 52 | #' estimate_means(model) |
44 | 53 | #' estimate_means(model, by = "Sepal.Width", length = 3) |
45 | 54 | #' } |
46 | | -#' @return A data frame of estimated marginal means. |
47 | 55 | #' @export |
48 | 56 | estimate_means <- function(model, |
49 | 57 | by = "auto", |
|
0 commit comments