1. 学习
  2. /
  3. 课程
  4. /
  5. Inference for Linear Regression in R

Connected

练习

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.

说明 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.