Exercise

Adjusting for non-linear relationship

The next three examples work with datasets where the underlying data structure violates the linear regression technical conditions. For each example, you will apply a transformation to the data in order to create residual plots that look scattered.

In this first example, it appears as though the variables are not linearly related.

Instructions 1/2

undefined XP
  • 1
    • Run a linear regression of response versus explanatory on hypdata_nonlinear.
    • Get the observation-level information from the model.
    • Using modeled_observations, plot the residuals versus the fitted values.
      • Add a point layer.
      • Add a horizontal line at y = 0 using geom_hline() and setting yintercept to 0.
  • 2
    • Update the model add a quadratic term, I(explanatory^2), to the right-hand side of the formula.
    • Rerun the code and look at how the plots change.