Total marginal effects in R
Holistic effect size measures for nominal and ordinal outcome models
In a model with several outcome categories – a multinomial or ordered logit or probit, for example – a predictor has one marginal effect per category, and no single one of them says how much the predictor matters. The Total marginal effect (Total ME) from Mize and Han (2025) summarizes them in a single number: the sum of the absolute values of the marginal effects across all outcome categories, divided by two. That is the total amount of probability the predictor moves between the categories.
In R, you can calculate it with the marginaleffects package, which handles the marginal effects and the standard errors. For nominal or ordinal predictors, the meineq_weights() helper calculates the weights for the weighted Total ME inequality. The same measures are available in Stata with the totalme command.
Setup
meineq_weights() is in my Rfunctions repository on GitHub. Load it with source():
library(marginaleffects) # Marginal effects and hypotheses
source("https://raw.githubusercontent.com/tdmize/Rfunctions/main/ME_helper_functions.R")Continuous and binary predictors
Total MEs for several predictors can be calculated in one call:
avg_comparisons(mod,
variables = list(age = "sd",
binaryvar = "reference"),
hypothesis = ~ I(sum(abs(x)) / 2) | term)avg_comparisons() calculates each predictor’s marginal effect on every outcome category. hypothesis then adds up the absolute values and divides by two, separately for each predictor (| term).
Nominal or ordinal predictors
For a nominal predictor, first calculate a Total ME for every pairwise contrast between its categories (| contrast), then average those using the ME inequality weights:
avg_comparisons(mod,
variables = list(nominalvar = "pairwise"),
hypothesis = ~ I(sum(abs(x)) / 2) | contrast) |>
hypotheses(hypothesis = meineq_weights(mod, nominalvar))The result is the weighted Total ME inequality.
Examples
The examples reproduce the Total ME examples from Mize and Han (2025):
- Total MEs for a single model (Example 5.2.c): continuous and binary predictors of self-rated health.
- Comparing Total MEs across models (Example 5.2.e): testing mediation, with models combined by
suest. - Total ME inequalities for nominal independent variables (Example 5.3): race-ethnicity and degree.
Citation
If you use these measures, please cite:
Mize, Trenton D. and Bing Han. 2025. “Inequality and Total Effect Summary Measures for Nominal and Ordinal Variables.” Sociological Science 12:115–157.