[Experimental] Use margins::margins() to estimate average marginal effects (AME) and return a tibble tidied in a way that it could be used by broom.helpers functions. See margins::margins() for a list of supported models.

tidy_margins(x, conf.int = TRUE, conf.level = 0.95, ...)

Arguments

x

a model

conf.int

logical indicating whether or not to include a confidence interval in the tidied output

conf.level

the confidence level to use for the confidence interval

...

additional parameters passed to margins::margins()

Details

By default, margins::margins() estimate average marginal effects (AME): an effect is computed for each observed value in the original dataset before being averaged.

For more information, see vignette("marginal_tidiers", "broom.helpers").

Note

When applying margins::margins(), custom contrasts are ignored. Treatment contrasts (stats::contr.treatment()) are applied to all categorical variables. Interactions are also ignored.

Examples

if (FALSE) { # interactive()
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_margins(mod)
tidy_plus_plus(mod, tidy_fun = tidy_margins)
}