Menyesuaikan untuk hubungan nonlinier
Tiga contoh berikut menggunakan himpunan data dengan struktur yang melanggar ketentuan teknis regresi linear. Untuk setiap contoh, Anda akan menerapkan transformasi pada data agar plot residual terlihat menyebar acak.
Pada contoh pertama ini, tampaknya variabel-variabelnya tidak berhubungan secara linear.
Latihan ini adalah bagian dari kursus
Inferensi untuk Regresi Linear di R
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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
___