開始使用免費開始

手動計算含互動項的預測值

為了更了解 predict() 的運作方式,現在再次手動計算預測值。對這個模型,你需要分別計算三條迴歸線;在每一條線上,預測值都等於截距加上斜率乘以數值型自變數。關鍵在於針對每一種情況,挑對截距與斜率。

mdl_price_vs_both_interexplanatory_data 已可使用;dplyrtidyr 也已載入可用。

本練習屬於課程

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 <- ___
編輯並執行程式碼