Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(visreg)
- data("mtcars")
- # Convert transmission to factor with "automatic" as reference level
- mtcars$am <- factor(mtcars$am, levels = c(0, 1), labels = c("automatic", "manual"))
- mod1 <- lm(mpg~disp + hp + wt + am, data = mtcars)
- coef(mod1)
- (Intercept) disp hp wt ammanual
- 34.209443370 0.002489354 -0.039323213 -3.046747000 2.159270737
- visreg(mod1, "am", xlab = "Transmission")
- # Now relevel the transmission variable so that "manual" is the reference level
- mtcars$am <- relevel(mtcars$am, ref = "manual")
- mod2 <- lm(mpg~disp + hp + wt + am, data = mtcars)
- coef(mod2)
- (Intercept) disp hp wt amautomatic
- 36.368714107 0.002489354 -0.039323213 -3.046747000 -2.159270737
- visreg(mod2, "am", xlab = "Transmission")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement