Let's use the function to create a linear model object, and then use par(), mfrow(), and plot() to examine the model diagnostics. Follow the steps given below:
- Build your own version of mtcars_lm, which looks at how the displacement and weight variables affect mpg using the following code:
mtcars_lm <- lm(mpg ~ disp + wt, data = mtcars)
- Run the following code to enable plotting a 2 × 2 grid of plots so that looking at model diagnostic plots is easier with the following method:
par(mfrow = c(2, 2))
- Plot the mtcars_lm variable to see the model diagnostic plots using plot(mtcars_lm).
Be sure to turn the 2 × 2 grid off. This will make the plot disappear, so be sure you're done looking at it before ...