Menghitung prediksi secara manual dengan interaksi
Untuk memahami cara kerja predict(), saatnya kembali menghitung prediksi secara manual. Untuk model ini, ada tiga garis terpisah yang perlu dihitung, dan pada masing-masing garis, prediksi adalah intercept ditambah slope dikalikan nilai peubah penjelas numerik. Bagian yang menantang adalah mendapatkan intercept dan slope yang tepat untuk setiap kasus.
mdl_price_vs_both_inter dan explanatory_data tersedia; dplyr dan tidyr tersedia.
Latihan ini adalah bagian dari kursus
Regresi Tingkat Menengah di R
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Get the coefficients from mdl_price_vs_both_inter
coeffs <- ___
# Get the intercept for 0 to 15 year age group
intercept_0_15 <- ___
# Get the intercept for 15 to 30 year age group
intercept_15_30 <- ___
# Get the intercept for 30 to 45 year age group
intercept_30_45 <- ___
# Get the slope for 0 to 15 year age group
slope_0_15 <- ___
# Get the slope for 15 to 30 year age group
slope_15_30 <- ___
# Get the slope for 30 to 45 year age group
slope_30_45 <- ___