Creates a continuous spatial map of prediction variance across
cross-validation folds. Unlike borg_stability() which
returns summary statistics, this function produces per-location
stability scores showing where predictions are consistent versus
volatile across different train/test partitions.
Usage
borg_stability_map(
model,
data,
new = NULL,
target,
coords,
formula = NULL,
fit_fun = NULL,
folds = NULL,
v = 10,
seed = 42
)Arguments
- model
A fitted model with a
predict()method, or a model-fitting function.- data
Data frame with predictors, target, and coordinates.
- new
Data frame of prediction locations. If
NULL, usesdata.- target
Character. Target variable name.
- coords
Character vector of length 2. Coordinate column names.
- formula
Model formula. Required if
modelis a function.- fit_fun
Function. Model fitting function. If
NULL, attempts to refit from model's call.- folds
A
borg_cvorborg_disc_cvobject, or a fold list. IfNULL, generates spatial CV folds automatically.- v
Integer. Number of folds if generating automatically. Default: 10.
- seed
Integer. Random seed. Default: 42.
Value
A data frame with class "borg_stability_map" containing:
- pred_mean
Mean prediction across folds
- pred_sd
Standard deviation of predictions across folds
- pred_cv
Coefficient of variation (|sd/mean|)
- pred_range
Range of predictions (max - min)
- n_folds_predicted
Number of folds where this point was in the test set (or could be predicted)
- x, y
Coordinates
Has print() and autoplot() methods.
Details
How it works
For each CV fold:
Refit the model on the training set.
Predict on all locations (not just test set).
Store per-location predictions.
Then compute per-location statistics across folds. Locations with
high pred_sd are unstable — the prediction changes substantially
depending on which data is included in training.