resample: Resample data

View source: R/resample.R

resampleR Documentation

Resample data

Description

Create resamples of your data, e.g. for model building or validation. "KFold" creates stratified folds, , "StratSub" creates stratified subsamples, "Bootstrap" gives the standard bootstrap, i.e. random sampling with replacement, while "StratBoot" uses StratSub and then randomly duplicates some of the training cases to reach the original length of the input, or the length defined by target_length.

Usage

resample(x, config = setup_KFold(), verbosity = 1L)

Arguments

x

Vector or data.frame: Usually the outcome; NROW(x) defines the sample size. A config naming a column – stratify_var or id_strat – needs the data frame that column lives in, since a name cannot be looked up in a bare vector.

config

Resampler object created by one of the ⁠setup_*⁠ resampler functions, e.g. setup_KFold.

verbosity

Integer: Verbosity level.

Details

Note that option 'KFold' may result in resamples of slightly different length. Avoid all operations which rely on equal-length vectors. For example, you can't place resamples in a data.frame, but must use a list instead.

Value

Resampler object.

Author(s)

EDG

Examples

y <- rnorm(200)
# 10-fold (stratified)
y_10fold <- resample(y, setup_KFold(10L))
y_10fold
# 25 stratified subsamples
y_25strat <- resample(y, setup_StratSub(25L))
y_25strat
# 100 stratified bootstraps
y_100strat <- resample(y, setup_StratBoot(100L))
y_100strat
# LOOCV
y_loocv <- resample(y, setup_LOOCV())
y_loocv
# User-supplied resamples
y_custom <- resample(
  y,
  setup_Custom(resamples = list(1:150, 51:200))
)
y_custom

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.