Mirrors rSPDE::cross_validation() for bru fits (output from inlabru::bru()),
with built-in support for the exact, non-FEM SPDE models in
MetricGraph (objects of class inla_metric_graph_spde). For models
fit with such a component, the function rebuilds the SPDE on a graph clone
with held-out responses set to NA, refits when true_CV = TRUE, and draws
posterior samples via the inlabru::generate path used by
predict.inla_metric_graph_spde. For models without a metric-graph SPDE
component (e.g. FEM-based rSPDE models), it uses the standard
inlabru::bru_set_missing() + bru_rerun() + inlabru::generate() path
shared with rSPDE::cross_validation().
cross_validation(
models,
model_names = NULL,
scores = c("mae", "mse", "crps", "scrps", "dss"),
cv_type = c("k-fold", "loo", "lpo"),
weight_thr = NULL,
k = 5,
percentage = 20,
number_folds = 10,
n_samples = 1000,
return_scores_folds = FALSE,
orientation_results = c("negative", "positive"),
include_best = TRUE,
train_test_indexes = NULL,
return_train_test = FALSE,
return_post_samples = FALSE,
return_true_test_values = FALSE,
parallelize_RP = FALSE,
n_cores_RP = parallel::detectCores() - 1,
true_CV = TRUE,
save_settings = FALSE,
model_options_bru = list(),
print = TRUE,
fit_verbose = FALSE
)Either a data.frame (default), or a list with scores_df plus the
optional components requested by return_* / save_settings arguments.
A fitted model from inlabru::bru() or a list of such models.
All models must have the same number of likelihoods and be fitted to
identical datasets.
Character vector of model names. Defaults to names(models)
or Model 1, Model 2, ... if absent.
Subset of c("mae", "mse", "crps", "scrps", "dss", "wcrps", "swcrps").
One of "k-fold", "loo", "lpo".
Threshold for wcrps / swcrps. Required if either is requested.
Number of folds for k-fold.
Train percentage (1-99) for lpo.
Number of folds for lpo.
Number of posterior samples for sample-based scoring.
If TRUE, return per-fold score matrices.
One of "negative" (lower is better) or
"positive" (higher is better).
Add a Best row indicating the best model per score.
Optional pre-built fold list. If supplied,
cv_type, k, percentage, number_folds are ignored.
Return the train/test indices used.
Return posterior response samples (forces
return_scores_folds = TRUE).
Return the true response values at test points.
Parallelize CRPS/SCRPS pairwise integrals.
Number of cores for parallelize_RP.
If TRUE, refit the model on each training fold; if FALSE,
sample directly from the supplied fit without refitting.
If TRUE, return the CV settings used.
List of options passed to inlabru.
Print partial progress.
Pass verbose through to INLA when refitting.