- Learning how to produce point-range regression plots
- Understanding marginal effects
- Plotting marginal effects
Last updated in March 2022
mod1 = lm(life_exp ~ dem_index, data = countries) coef(mod1)
## (Intercept) dem_index ## 67.191591 1.621479
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
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]
ggeffects packageggeffects 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 modelggeffects - based on the effects package, similar to ggpredict, but handles categorical variables differentlyggemeans - based on the emeans package, mostly for contrastsggeffects package is broadly applicableAnd that is pretty cool!