Marginal Slopes / Effects with marginaleffects::avg_slopes()
Source: R/marginal_tidiers.R
tidy_avg_slopes.Rd
Use marginaleffects::avg_slopes()
to estimate marginal slopes / effects and
return a tibble tidied in a way that it could be used by broom.helpers
functions. See marginaleffects::avg_slopes()
for a list of supported
models.
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::avg_slopes()
.
Details
By default, marginaleffects::avg_slopes()
estimate average marginal
effects (AME): an effect is computed for each observed value in the original
dataset before being averaged. Marginal Effects at the Mean (MEM) could be
computed by specifying newdata = "mean"
. Other types of marginal effects
could be computed. Please refer to the documentation page of
marginaleffects::avg_slopes()
.
For more information, see vignette("marginal_tidiers", "broom.helpers")
.
See also
Other marginal_tieders:
tidy_all_effects()
,
tidy_avg_comparisons()
,
tidy_ggpredict()
,
tidy_marginal_contrasts()
,
tidy_marginal_means()
,
tidy_marginal_predictions()
,
tidy_margins()
Examples
if (FALSE) { # interactive()
# Average Marginal Effects (AME)
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_avg_slopes(mod)
tidy_plus_plus(mod, tidy_fun = tidy_avg_slopes)
mod2 <- lm(Petal.Length ~ poly(Petal.Width, 2) + Species, data = iris)
tidy_avg_slopes(mod2)
# Marginal Effects at the Mean (MEM)
tidy_avg_slopes(mod, newdata = "mean")
tidy_plus_plus(mod, tidy_fun = tidy_avg_slopes, newdata = "mean")
}