Inequality in categorical models

Example 4.2.b of Mize and Han (2025), in R

Because the statistic is built from predictions, it works the same way after a binary logit, where the predictions are probabilities. This example summarizes several nominal and binary predictors of conservative identification at once: gender, race-ethnicity, and subjective class. The same example in Stata is on the meinequality page.

Load and prepare the data

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

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 == 2021, ]

vars <- c("conserv", "race4", "woman", "class", "age")
gss <- gss[complete.cases(gss[vars]), vars]
fvars <- c("conserv", "race4", "woman", "class")
gss[fvars] <- lapply(gss[fvars], as_factor)
gss <- droplevels(gss)
nrow(gss)
[1] 3608

Fit the model

conmod <- glm(conserv ~ woman + race4 + class,
  family = binomial("logit"), data = gss)

ME inequality for each predictor

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

avg_comparisons(conmod,
  variables = list(woman = "pairwise", race4 = "pairwise", class = "pairwise"),
  hypothesis = meineq(conmod))
  Term Estimate Std. Error     z Pr(>|z|)    S   2.5 % 97.5 %
 class   0.0122     0.0174 0.701    0.484  1.0 -0.0219 0.0464
 race4   0.1078     0.0135 7.991   <0.001 49.4  0.0814 0.1342
 woman   0.0695     0.0156 4.466   <0.001 16.9  0.0390 0.1001

Type: response

Class has no overall effect on conservative identification. Racial-ethnic groups differ by about 11 percentage points on average. For a binary variable such as woman the ME inequality is simply the absolute value of its marginal effect, which puts binary and multi-category predictors on the same footing for comparison.

Back to top