手動計算含互動項的預測值
為了更了解 predict() 的運作方式,現在再次手動計算預測值。對這個模型,你需要分別計算三條迴歸線;在每一條線上,預測值都等於截距加上斜率乘以數值型自變數。關鍵在於針對每一種情況,挑對截距與斜率。
mdl_price_vs_both_inter 與 explanatory_data 已可使用;dplyr 與 tidyr 也已載入可用。
本練習屬於課程
R 的迴歸分析中級
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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 <- ___