Total ME inequalities for nominal independent variables

Example 5.3 of Mize and Han (2025), in R

With a nominal outcome and nominal independent variables there are two layers of summary. On each outcome category, the effect of a nominal predictor is its ME inequality – the average absolute difference in that category’s probability across the predictor’s groups. The Total ME inequality then sums those across the outcome categories and halves the sum. Here race-ethnicity and degree, both nominal, predict self-rated health. The same example in Stata is on the totalme page.

Load and prepare the data

library(haven)           # Read Stata data
library(marginaleffects) # Marginal effects and hypotheses
library(nnet)            # Multinomial logit

source("https://raw.githubusercontent.com/tdmize/Rfunctions/main/ME_helper_functions.R")

gss <- read_dta("https://tdmize.github.io/data/data/cda_gss.dta")
gss <- gss[gss$year >= 2000 & gss$year <= 2021, ]

vars <- c("healthR", "race4", "age", "woman", "parent", "married", "faminc", "degree")
gss <- gss[complete.cases(gss[vars]), vars]

fvars <- c("healthR", "race4", "woman", "parent", "married", "degree")
gss[fvars] <- lapply(gss[fvars], as_factor)
nrow(gss)
[1] 19292

Fit the multinomial logit model

healthmod <- multinom(healthR ~ race4 + age + woman + parent +
  married + faminc + degree, data = gss, trace = FALSE)

Total ME inequalities

List the predictors in variables; totalme() returns the Total ME inequality of each:

avg_comparisons(healthmod,
  variables = list(race4 = "pairwise", degree = "pairwise"),
  hypothesis = totalme(healthmod))
   Term Estimate Std. Error     z Pr(>|z|)     S  2.5 % 97.5 %
 degree   0.1157    0.00554 20.89   <0.001 319.6 0.1049 0.1266
 race4    0.0471    0.00679  6.94   <0.001  37.9 0.0338 0.0604

Type: probs

Degree moves much more probability across the health categories than race-ethnicity does. The weights count each pairwise comparison in proportion to the share of the sample in the two groups compared. For the unweighted version, which gives every comparison the same weight, use totalme(healthmod, weighted = FALSE).

Back to top