We’ll use the mtcars dataset to demonstrate the coefficient visualization functions.
# Prepare data
data(mtcars)
mtcars$am <- as.factor(mtcars$am)
# Create multiple models predicting mpg
m1 <- lm(mpg ~ wt, data = mtcars)
m2 <- lm(mpg ~ wt + am, data = mtcars)
m3 <- lm(mpg ~ wt + am + hp, data = mtcars)
# Create a named list of models
models <- list(
"Model A" = m1,
"Model B" = m2,
"Model C" = m3
)
Let’s examine the effect of weight (wt) across our models:
model_name | cov_name | coef | conf1 | conf2 |
---|---|---|---|---|
Model A | wt | -5.34447157272268 | -6.48630823741826 | -4.20263490802709 |
Model B | wt | -5.3528114467999 | -6.96495096730801 | -3.7406719262918 |
Model C | wt | -2.87857541380719 | -4.73232352702331 | -1.02482730059107 |
Now let’s visualize these coefficients and their confidence intervals:
The plot shows how the effect of weight (wt) on mpg changes across different model specifications:
The black dots represent the coefficient estimates, and the horizontal lines show the 95% confidence intervals. The vertical dashed line at zero helps identify significant effects (intervals that don’t cross zero).