View source: R/graph_crossval.R
| cross_validation | R Documentation |
Mirrors rSPDE::cross_validation() for bru fits (output from inlabru::bru()).
For each fold, the held-out responses are set to NA with
inlabru::bru_set_missing() and the model is refit with inlabru::bru_rerun().
When true_CV = FALSE, the original fit's mode$theta is held fixed so only
the latent posterior is updated; when TRUE, theta is re-estimated. Posterior
response samples are then drawn at the held-out locations via inlabru::generate().
Works with the exact, non-FEM SPDE models in MetricGraph
(inla_metric_graph_spde) and FEM-based rSPDE models alike.
A fit containing an rSPDE component and no exact MetricGraph SPDE is
delegated to rSPDE::cross_validation(). Mixed exact/rSPDE model lists
use this implementation. Fits without a recognizable package-specific
component continue to use the function explicitly called.
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
)
models |
A fitted model from |
model_names |
Character vector of model names. Defaults to |
scores |
Subset of |
cv_type |
One of |
weight_thr |
Threshold for |
k |
Number of folds for |
percentage |
Train percentage (1-99) for |
number_folds |
Number of folds for |
n_samples |
Number of posterior samples for sample-based scoring. |
return_scores_folds |
If |
orientation_results |
One of |
include_best |
Add a |
train_test_indexes |
Optional pre-built fold list. If supplied,
|
return_train_test |
Return the train/test indices used. |
return_post_samples |
Return posterior response samples (forces
|
return_true_test_values |
Return the true response values at test points. |
parallelize_RP |
Parallelize CRPS/SCRPS pairwise integrals. |
n_cores_RP |
Number of cores for |
true_CV |
If |
save_settings |
If |
model_options_bru |
List of options passed to inlabru. |
print |
Print partial progress. |
fit_verbose |
Pass |
Either a data.frame (default), or a list with scores_df plus the
optional components requested by return_* / save_settings arguments.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.