Research question: what social factors most strongly pattern political views?
Sometimes, want to compare effect sizes across predictors (IVs) within a model
Complicated by variables on different metric (e.g., age vs income), by variables of different types (e.g., binary vs continuous), and by nonlinearities of continuous IVs
For binary IVs, the 0 vs 1 effect already provides the full summary
For nominal IVs, can use an ME inequality
For continuous IVs, calculate marginal effects, even with nonlinearities
Can still provide an answer for the average effect
For comparing effect sizes across binary and continuous predictors, a +2 SD change is sometimes recommended (Gelman 2008) as comparable
More robust alternative is ME across trimmed range (5th to 95th percentile)
Logic: binary 0 vs 1 or ME inequality is entire range of variable’s effect; trimmed range similarly expresses entire range of continuous IV’s effect while protecting against outliers (Mize and Han 2025)
Comparing marginal effects within a model
In Stata, mecompare can simultaneously calculate multiple MEs, and then use metest for additional tests of equality
amount(trimrange) for 5th to 95th percentile change for continuous IVs
meinequality option for nominal IVs
In R, use avg_comparisons and specify each predictor of interest in a list( )
For a significance test of the difference in marginal effects, use the hypothesis option*
hypothesis = ~ pairwise will calculate all contrasts, but be careful with multiple exploratory hypothesis tests
To compare pure effect sizes and ignore direction, take the absolute value of the marginal effects before testing their equality
Source | SS df MS Number of obs = 3,608
-------------+---------------------------------- F(9, 3598) = 16.61
Model | 339.734948 9 37.7483275 Prob > F = 0.0000
Residual | 8175.67969 3,598 2.27228452 R-squared = 0.0399
-------------+---------------------------------- Adj R-squared = 0.0375
Total | 8515.41463 3,607 2.3608025 Root MSE = 1.5074
-------------------------------------------------------------------------------
conpolviews | Coefficient Std. err. t P>|t| [95% conf. interval]
--------------+----------------------------------------------------------------
age | 0.037 0.009 4.021 0.000 0.019 0.055
|
c.age#c.age | -0.000 0.000 -2.487 0.013 -0.000 -0.000
|
woman |
Women | -0.175 0.051 -3.438 0.001 -0.275 -0.075
|
race4 |
Black | -0.331 0.084 -3.945 0.000 -0.496 -0.167
Other | -0.129 0.111 -1.161 0.246 -0.348 0.089
Hispanic | 0.011 0.083 0.134 0.893 -0.152 0.174
|
class |
working cl.. | -0.021 0.096 -0.223 0.823 -0.209 0.166
middle class | -0.279 0.094 -2.952 0.003 -0.464 -0.094
upper class | -0.536 0.151 -3.556 0.000 -0.831 -0.240
|
_cons | 2.986 0.243 12.273 0.000 2.509 3.463
-------------------------------------------------------------------------------
eststore mod42bmecompare age woman race4 class, amount(trimrange) meinequality model(mod42b)
Predicting: Linear prediction
Marginal effects (N_mod42b=3608)
| ME # Estimate SE P>|z|
---------------------------------+---------------------------------------
age(5-95%) |
mod42b | 1 0.784 0.082 0.000
---------------------------------+---------------------------------------
woman |
Women - Men |
mod42b | 2 -0.175 0.051 0.001
---------------------------------+---------------------------------------
race4 |
ME Inequality | 3 0.172 0.053 0.001
Black - White |
mod42b | 4 -0.331 0.084 0.000
Other - White |
mod42b | 5 -0.129 0.111 0.246
Hispanic - White |
mod42b | 6 0.011 0.083 0.893
---------------------------------+---------------------------------------
class |
ME Inequality | 7 0.273 0.059 0.000
working cla - lower clas |
mod42b | 8 -0.021 0.096 0.823
middle clas - lower clas |
mod42b | 9 -0.279 0.094 0.003
upper class - lower clas |
mod42b | 10 -0.536 0.151 0.000
library(haven) # import Stata data and labelslibrary(dplyr) # data manipulationlibrary(marginaleffects) # predictions and marginal effectssource("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 |>filter(year ==2021)# Keep only model vars and drop any missing data on themgss <- gss[c("polviews", "age", "woman", "race4", "class")]gss <- gss[complete.cases(gss), ]# Treat binary/nominal variables as factors; drop categories with no casesgss <- gss |>mutate(conpolviews =as.numeric(polviews), woman =as_factor(woman),race4 =as_factor(race4), class =as_factor(class)) |>droplevels()mod42b <-lm(conpolviews ~poly(age, 2, raw =TRUE) + woman + race4 + class, data = gss)# Trimmed range of age: 5th to 95th percentilequantile(gss$age, c(.05, .95))