Generate cell draws and summary rasters from INLA model
Source:R/generate_cell_draws_and_summarize.R
generate_cell_draws_and_summarize.Rd
Use INLA posteriors to predict out across a grid
Usage
generate_cell_draws_and_summarize(
inla_model,
inla_mesh,
n_samples,
id_raster,
covariates,
inverse_link_function,
nugget_in_predict = TRUE,
admin_boundaries = NULL,
ui_width = 0.95,
verbose = TRUE
)
Arguments
- inla_model
Output from
fit_inla_model()
- inla_mesh
An SPDE mesh used to define the spatial integration points of the INLA geostatistical model. Typically created using
INLA::inla.mesh.2d()
or a similar function.- n_samples
(numeric) Number of posterior predictive samples to draw.
- id_raster
(terra::SpatRaster) raster showing all cell locations where predictions should be taken.
- covariates
(list) Named list of all covariate effects included in the model, typically generated by
load_covariates()
.- inverse_link_function
(character) If a link function was used in the INLA model, name of the R function to transform the predictive draws from link space to natural space. For example, in a logit-linked binomial model, pass 'plogis' (as a string is fine) to invert-logit the predictive draws.
- nugget_in_predict
(
logical(1)
, default TRUE) Should the nugget term be used as an IID noise term applied to each pixel-draw?- admin_boundaries
(sf object, default NULL) The same admin boundaries used to create the admin-level effect, if one was defined in the model. Only used if an admin-level effect was defined in the model.
- ui_width
(numeric, default 0.95) Size of the uncertainty interval width when calculating the upper and lower summary rasters
- verbose
(
logical(1)
, default TRUE) Log progress for draw generation?
Value
Named list containing at least the following items:
"parameter_draws": posterior samples generated from
INLA::inla.posterior.sample()
"cell_draws": A matrix of grid cell draws. Each row represents a non-NA pixel in the
id_raster
, in the same order that would be pulled byterra::values()
, and each column represents a different posterior draw."cell_pred_mean": Mean predictive estimate by grid cell, formatted as a terra SpatRaster
"cell_pred_lower": Lower bound of (X%) uncertainty interval, formatted as a terra SpatRaster
"cell_pred_upper": Upper bound of (X%) uncertainty interval, formatted as a terra SpatRaster