Estimates confidence intervals for cross-validation performance metrics
using spatial block bootstrap. Standard bootstrap assumes independent
observations; block bootstrap preserves the dependency structure
detected by borg_diagnose().
Usage
borg_bootstrap(
model,
data,
target,
coords = NULL,
formula = NULL,
fit_fun = NULL,
folds = NULL,
metric = c("rmse", "mae", "rsq"),
n_boot = 200,
n_blocks = 10,
conf_level = 0.95,
seed = 42
)Arguments
- model
A fitted model with a
predict()method, or a model-fitting function (seefit_fun).- data
Data frame with predictors and target.
- target
Character. Target variable name.
- coords
Character vector of length 2. Coordinate column names. If provided, uses spatial blocking. Otherwise, uses random blocks.
- 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_cvobject or fold list. If provided, bootstrap resamples within the fold structure.- metric
Character. Performance metric:
"rmse"(default),"mae","rsq".- n_boot
Integer. Number of bootstrap replicates. Default: 200.
- n_blocks
Integer. Number of spatial blocks for resampling. Default: 10.
- conf_level
Numeric. Confidence level. Default: 0.95.
- seed
Integer. Random seed. Default: 42.
Value
A list with class "borg_bootstrap" containing:
- estimate
Point estimate of the metric
- ci_lower
Lower confidence bound
- ci_upper
Upper confidence bound
- conf_level
Confidence level
- boot_distribution
Numeric vector of bootstrap estimates
- se
Bootstrap standard error
- bias
Bootstrap bias estimate
- metric
Metric name
- n_boot
Number of bootstrap replicates
- method
"spatial_block" or "random_block"
Has print() and autoplot() methods.
Details
Spatial block bootstrap
Data is partitioned into spatial blocks using k-means clustering on coordinates. Each bootstrap replicate resamples blocks (with replacement), then includes all observations from selected blocks. This preserves within-block spatial correlation while generating valid resamples.