get_averages: Average Estimates (aka "Margins")

get_averagesR Documentation

Average Estimates (aka "Margins")

Description

Calculate average estimates by taking the (group-wise) mean of all the unit-level estimates computed by the predictions(), comparisons(), or slopes() functions.

Warning: It is generally faster and safer to use the by argument of one of the three functions listed above. Alternatively, one can call it in one step:

avg_slopes(model)

slopes(model, by = TRUE)

Proceeding in two steps by assigning the unit-level estimates is typically slower, because all estimates must be computed twice.

Note that the tidy() and summary() methods are slower wrappers around ⁠avg_*()⁠ functions.

Usage

get_averages(x, by = TRUE, ...)

Arguments

x

Object produced by the predictions(), comparisons(), or slopes() functions.

by

Character vector of variable names over which to compute group-wise average estimates. When by=NULL, the global average (per term) is reported.

...

All additional arguments are passed to the original fitting function to override the original call options: conf_level, transform, etc. See ?predictions, ?comparisons, ?slopes.

Details

Standard errors are estimated using the delta method. See the marginaleffects website for details.

In Bayesian models (e.g., brms), estimates are aggregated applying the median (or mean) function twice. First, we apply it to all marginal effects for each posterior draw, thereby estimating one Average (or Median) Marginal Effect per iteration of the MCMC chain. Second, we calculate the mean and the quantile function to the results of Step 1 to obtain the Average Marginal Effect and its associated interval.

Value

A data.frame of estimates and uncertainty estimates

Examples

## Not run: 
mod <- lm(mpg ~ factor(gear), data = mtcars)
contr <- comparisons(mod, variables = list(gear = "sequential"))
tidy(contr)

## End(Not run)

marginaleffects documentation built on Oct. 20, 2023, 1:07 a.m.