Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. library(visreg)
  2.  
  3. data("mtcars")
  4.  
  5. # Convert transmission to factor with "automatic" as reference level
  6.  
  7. mtcars$am <- factor(mtcars$am, levels = c(0, 1), labels = c("automatic", "manual"))
  8.  
  9. mod1 <- lm(mpg~disp + hp + wt + am, data = mtcars)
  10.  
  11. coef(mod1)
  12.  
  13. (Intercept) disp hp wt ammanual
  14. 34.209443370 0.002489354 -0.039323213 -3.046747000 2.159270737
  15.  
  16. visreg(mod1, "am", xlab = "Transmission")
  17.  
  18. # Now relevel the transmission variable so that "manual" is the reference level
  19.  
  20. mtcars$am <- relevel(mtcars$am, ref = "manual")
  21.  
  22. mod2 <- lm(mpg~disp + hp + wt + am, data = mtcars)
  23.  
  24. coef(mod2)
  25.  
  26. (Intercept) disp hp wt amautomatic
  27. 36.368714107 0.002489354 -0.039323213 -3.046747000 -2.159270737
  28.  
  29. visreg(mod2, "am", xlab = "Transmission")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement