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.
Este ejercicio forma parte del curso
Inference for Linear Regression in R
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# Run this to see how the model looks
ggplot(hypdata_nonlinear, aes(x = explanatory, y = response)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE)
# Model response vs. explanatory
model <- ___
# Extract observation-level information
modeled_observations <- ___
# See the result
modeled_observations
# Using modeled_observations, plot residuals vs. fitted values
___ +
# Add a point layer
___ +
# Add horizontal line at y = 0
___