調整非線性關係
接下來的三個範例會使用到底層資料結構違反線性迴歸技術條件的資料集。對於每個範例,你會對資料做轉換,讓殘差圖呈現隨機分散的樣子。
在第一個範例中,看起來變數之間不是線性關係。
本練習屬於課程
R 中的線性迴歸推論
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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
___