進行產量預測
建模最有趣的部分,就是用模型來做預測。你可以用 predict() 來完成,格式如下:
predict(model, cases_to_predict, type = "response")
已載入 mgcv 與 dplyr;玉米與小麥資料集的 GAM 已分別存在 corn_model 與 wheat_model。人口普查分區的字元向量已儲存在 census_regions。
本練習屬於課程
R 函式撰寫入門
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Make predictions in 2050
predict_this <- data.frame(
year = ___,
census_region = census_regions
)
# Predict the yield
pred_yield_kg_per_ha <- ___(___, ___, type = "response")
predict_this %>%
# Add the prediction as a column of predict_this
___(pred_yield_kg_per_ha = ___)