Marginal Means with marginaleffects::marginal_means()
Source: R/marginal_tidiers.R
tidy_marginal_means.Rd
This function is deprecated. Use instead tidy_marginal_predictions()
with
the option newdata = "marginalmeans"
.
Arguments
- x
(a model object, e.g.
glm
)
A model to be tidied.- conf.int
(
logical
)
Whether or not to include a confidence interval in the tidied output.- conf.level
(
numeric
)
The confidence level to use for the confidence interval (between0
ans1
).- ...
Additional parameters passed to
marginaleffects::marginal_means()
.
Details
Use marginaleffects::marginal_means()
to estimate marginal means and
return a tibble tidied in a way that it could be used by broom.helpers
functions. See marginaleffects::marginal_means()()
for a list of supported
models.
marginaleffects::marginal_means()
estimate marginal means:
adjusted predictions, averaged across a grid of categorical predictors,
holding other numeric predictors at their means. Please refer to the
documentation page of marginaleffects::marginal_means()
. Marginal means
are defined only for categorical variables.
For more information, see vignette("marginal_tidiers", "broom.helpers")
.
See also
marginaleffects::marginal_means()
Other marginal_tieders:
tidy_all_effects()
,
tidy_avg_comparisons()
,
tidy_avg_slopes()
,
tidy_ggpredict()
,
tidy_marginal_contrasts()
,
tidy_marginal_predictions()
,
tidy_margins()
Examples
if (FALSE) { # interactive()
# Average Marginal Means
df <- Titanic |>
dplyr::as_tibble() |>
tidyr::uncount(n) |>
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
mod <- glm(
Survived ~ Class + Age + Sex,
data = df, family = binomial
)
tidy_marginal_means(mod)
tidy_plus_plus(mod, tidy_fun = tidy_marginal_means)
mod2 <- lm(Petal.Length ~ poly(Petal.Width, 2) + Species, data = iris)
tidy_marginal_means(mod2)
}