Practice: Visual Model Checks

You should get used to checking model quality visually. Look for inconsistencies between the data cloud pattern and the fitted lines for patterns in residuals and outlying observations. These exercises give examples and suggest R functions you can use for these tasks. This exercise does not count toward your grade. It is just for practice!


  1. Instead of using lm() to fit a straight line, you can use loess() to fit a smooth curve. Repeat the process of model fitting, grid generation, predictions, and visualisation on sim1 using loess() instead of lm(). How does the result compare to geom_smooth()?

  2. add_predictions() is paired with gather_predictions() and spread_predictions(). How do these three functions differ?

  3. What does geom_ref_line() do? What package does it come from? Why is displaying a reference line in plots showing residuals useful and important?

  4. Why might you want to look at a frequency polygon of absolute residuals? What are the pros and cons compared to looking at the raw residuals?

Source: H. Wickham and G. Grolemund,
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 License.

Last modified: Thursday, December 15, 2022, 4:56 PM