When doing the spatial_prediction() step the following larger steps happen:
Join spatial covariate information down to the training/mosquito data.
Training mosquito data (currently) has say 1000 rows.
The result is the mosquito data with 1000 rows plus 13 extra columns with spatial covariate information extracted down to match the long/lat of the mosquito data (with bilinear interpolation)
Convert the covariate raster to a data frame, so we can predict out to it from the training/mosquito data
But as part of this we need to ensure it has all the same column names as the training data
This is the part I'm not 100% sure on. The values we want to provide here for this raster are currently specified as start year, month, end year, end month, and also sets insecticide_id to be 1. The model later fits each insecticide separately, BUT this data is used again in fitting. I'm uncertain the below is right - and I'm not sure how we should tackle giving/specifying the columns or variables/values appropriately.
spatial_prediction <- function(covariate_rasters = raster_covariates,
training_data = ir_data_subset,
level_zero_models = model_list,
inla_mesh_setup = gp_inla_setup) {
ir_data_subset_spatial_covariates <- join_rasters_to_mosquito_data(
rasters = covariate_rasters,
mosquito_data = training_data
)
chosen_year <- max(as.integer(training_data$start_year))
rasters_as_data <- raster_to_df(covariate_rasters)
rasters_w_basic_info <- rasters_as_data %>%
mutate(
start_year = chosen_year,
start_month = 1,
end_month = 12,
end_year = chosen_year,
int = 1,
# dummy to be changed later?
insecticide_id = 1,
.before = everything()
)
# predict out for each raster in rasters_for_inner_loop
# full set of map data (environmental covariates and coords)
# in this final step we take a set of rasters, pull out coords and env
# covariates for each pixel, and use stacked generalisation to predict to
# all of them, then put predicted IR values back in a raster of predictions.
spatial_predictions <- inner_loop(
data = ir_data_subset_spatial_covariates,
new_data = rasters_w_basic_info,
level_zero_models = level_zero_models,
level_one_model_setup = inla_mesh_setup
)
spatial_predictions
}
When doing the
spatial_prediction()
step the following larger steps happen:Join spatial covariate information down to the training/mosquito data.
Convert the covariate raster to a data frame, so we can predict out to it from the training/mosquito data
This is the part I'm not 100% sure on. The values we want to provide here for this raster are currently specified as start year, month, end year, end month, and also sets insecticide_id to be 1. The model later fits each insecticide separately, BUT this data is used again in fitting. I'm uncertain the below is right - and I'm not sure how we should tackle giving/specifying the columns or variables/values appropriately.