hib_cv_model: Cross-validate a fitted hibiiscus mixed-effects model
Source:R/hib_cv_model.R
hib_cv_model.RdThis function re-fits models on different subsets of the data, and estimates a range of error metrics allowing for evaluation of model predictive performance.
Usage
hib_cv_model(
mod_obj,
db_obj,
fold_type,
custom_col = NULL,
random_seed = NULL,
re_form = list(NA),
backtransform = NULL,
use_original_mesh = NULL
)Arguments
- mod_obj
One of;
HibModelLME4,HibModelINLAorHibModelBRMS.- db_obj
A
HibDatabaseobject, or, if the above model used multiple data sources, alistofHibDatabaseobjects.- fold_type
A
characterindicating the type of cross-validation; one of: "Random-2", "Random-3", "Random-5", "Random-10", "Source_ID", "SS", "Country", "UN_subregion", "UN_region", "Biome", "Realm", "Custom".- custom_col
A
characterindicating the column in the model data (sitesdata.frame) to use to define cross-validation folds, whenfold_type == "Custom".- random_seed
A
numericindicating the random seed used to define random cross-validation folds - only used if 'Random-X' infold_type.- re_form
A
listindicating the random effects variables to be included in the cross-validation/insample predicitons - if multiple items supplied, each option will be used in a separate cross-validated prediction. Values can be eitherNA(no random effects),NULL(all random effects), or a rhsformulaspecifying particular random effects to include.
Note: only test set data points with random-effect values present in the training data will have predictions ifre_formis notNA.- backtransform
A function to convert the model prediction back to the original scale of interest. The inverse of any transformation used in model fitting.
- use_original_mesh
A
logicalvalue indicating whether cross-validation of spatialINLAmodels should use the original mesh for all CV folds. Computationally this is slightly more efficient, but will impact CV performance metrics as 'withheld' sites will still exist in the mesh.
Details
This function allows for model evaluation using multiple cross-validation strategies, and multiple random effects structures. It returns a HibCV object, which includes the original model, insample and CV performance for multiple evaluation metrics, model coefficients estimated per cross-validation fold.