Making yield predictions
The fun part of modeling is using the models to make predictions. You can do this using a call to predict()
, in the following form.
predict(model, cases_to_predict, type = "response")
mgcv
and dplyr
are loaded; GAMs of the corn and wheat datasets are available as corn_model
and wheat_model
. A character vector of census regions is stored as census_regions
.
This exercise is part of the course
Introduction to Writing Functions in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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 = ___)