Last updated in March 2022

Goals for today

  • Learning how to produce point-range regression plots
  • Understanding marginal effects
  • Plotting marginal effects

Point-range plots

Point-range plots

  • Straightforward visualizations of the regression coefficients tables

Standardization

  • Visual display invites comparison, so better standardize

Marginal effect plots

Some models are easy to interpret…

  • Relationship between life expectancy and democratic index, assuming linear relationship
mod1 = lm(life_exp ~ dem_index, data = countries)
coef(mod1)
## (Intercept)   dem_index 
##   67.191591    1.621479
  • A country with additional point of democratic index has, on average, 1.6 years higher life expectancy

… others not so much

  • Relationship between life expectancy and democratic index, but the relationship can be parabolic and also can differ based on whether the country has a post soviet history or not.
m2 = lm(life_exp ~ poly(dem_index, 2) * postsoviet,
          data = countries[!is.na(countries$dem_index),])
coef(m2)
##                       (Intercept)               poly(dem_index, 2)1 
##                         80.981531                          8.327868 
##               poly(dem_index, 2)2                     postsovietyes 
##                         -3.296518                         -1.995878 
## poly(dem_index, 2)1:postsovietyes poly(dem_index, 2)2:postsovietyes 
##                          5.085355                         12.699062
  • Help, how can I interpret this?

Complex models are hard to interpret

  • Once variables are transformed, there are interactions, quadratic terms, splines, etc., interpreting relationships between them using coefficients tables becomes difficult
  • Solution: visual interpretation using marginal effects

Marginal effects are here to save the day

  • Marginal effect = expected value of the dependent variable for given values of selected independent variable while other independent variables are held constant (preferably at some reasonable value such as mean)
ggpredict(m2, terms = c("dem_index [4,6,8]", "postsoviet [yes]"))
## # Predicted values of life_exp
## 
## dem_index | Predicted |         95% CI
## --------------------------------------
##         4 |     79.87 | [75.00, 84.74]
##         6 |     76.25 | [75.34, 77.15]
##         8 |     78.62 | [77.55, 79.69]

Marginal effects vizualized

  • The plot contains the exact same information as the table of regression coefficients, but is actually interpretable

Marginal effects

  • We can also plot just one variable one, while holding the others constant
  • The following plot shows the difference in expected life expectancy for countries with average democratic index

  • Question: How is this plot different from displaying simply group means, i.e. mean life expectancy for the postsoviet vs. non-postsoviet?

ggeffects package

  • ggeffects package computes marginal effects and returns ggplot2 friendly data frames

  • The ggeffects offers three basic functions:

    • ggpredict - based on the base predict() function, works on almost any model
    • ggeffects - based on the effects package, similar to ggpredict, but handles categorical variables differently
    • ggemeans - based on the emeans package, mostly for contrasts

ggeffects package is broadly applicable

  • The package works for a variety of models not covered in this course
    • generalized linear models
    • (generalized) mixed models
    • bayesian models
    • survival models
    • and many more

And that is pretty cool!