resample_boot: Generate data resamples using bootstrap

View source: R/resample_boot.R

resample_bootR Documentation

Generate data resamples using bootstrap

Description

Generate data resamples using bootstrap

Usage

resample_boot(data, n = 10, ...)

Arguments

data

data.frame, the data to resample.

n

integer, number of bootstraps.

...

unquoted names of columns of .data to stratify by. Usually they are discrete variables.

Value

A tibble with columns

  • train : an object of class modelr::resample. The boostrapped data.

  • val : an object of class modelr::resample. The out-of-bag data (i.e. the rows of .data not selected in the current bootstrap).

  • boot : integer, the bootstrap number.

Examples

resample_boot(mtcars, n=2)
rs <- resample_boot(mtcars, n=2)
data.frame(rs$train[1])
# = some rows are repeated
data.frame(rs$val[1])
# = all these rows are not above

# stratified bootstrap
rs  <- resample_boot(mtcars, n=10)
rss <- resample_boot(mtcars, n=10, gear)
sapply(rs$train, function(x) {sum(data.frame(x)$gear==4)})
# = variable number of occurrence of gear==4 in the training set
sapply(rss$train, function(x) {sum(data.frame(x)$gear==4)})
# = reliable number of gear==4 in the training set

jiho/joml documentation built on Dec. 6, 2023, 5:50 a.m.