| bin_layer | R Documentation |
Overlays within-bin estimates of the conditional effect of var1 on an
interplot output, following the binning estimator of Hainmueller,
Mummolo, and Xu (2019). It provides a visual check of the linear-interaction-
effect (LIE) assumption: if the moderating relationship is truly linear, the
binned point estimates fall on the interplot line; systematic departures
signal a nonlinear conditional effect.
bin_layer(
m,
var1,
var2,
ci = 0.95,
bins = 3,
point_color = "#BD472A",
point_shape = 18
)
m |
A model object of class |
var1 |
The name (as a string) of the variable whose conditional effect is plotted. |
var2 |
The name (as a string) of the moderating variable. |
ci |
A numeric value defining the confidence level. The default is 0.95. |
bins |
The number of moderator bins (quantile groups). The default is 3 (low / medium / high terciles). |
point_color |
Color of the binned points and whiskers. Default |
point_shape |
Plotting shape of the binned points. Default |
For each quantile bin of var2, the model is refitted on the
observations in that bin with var2 centered at the bin median. The
coefficient on var1 is then its marginal effect evaluated at the bin
median, estimated from only that bin's data; this is algebraically the
Hainmueller-Mummolo-Xu L-estimator. Each estimate is drawn as a
dot-and-whisker at the bin median.
Bins with singular or failed fits are dropped with a warning.
A list of ggplot2 layers, to be added to an interplot
plot with +.
Hainmueller, Jens, Jonathan Mummolo, and Yiqing Xu. 2019. "How Much Should We Trust Estimates from Multiplicative Interaction Models? Simple Tools to Improve Empirical Practice." Political Analysis 27(2): 163–192.
m <- lm(mpg ~ wt * cyl, data = mtcars)
interplot(m, "cyl", "wt") + bin_layer(m, "cyl", "wt")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.