Skip to contents

Draws times nonparametric bootstrap resamples of the rows of data with base R's sample.int (no rsample dependency). Each resample's analysis set is \(n\) rows drawn with replacement; its assessment set is the out-of-bag rows (those never drawn, about \(e^{-1} \approx 36.8\%\) of them). This is the same design as rsample::bootstraps; the resampled indices are not the same as rsample's under a given seed.

Usage

morie_rsample_bootstraps(data, times = 25L, ...)

Arguments

data

A data.frame (or matrix / vector; rows are resampled).

times

Number of bootstrap resamples (default 25).

...

Optional strata (a column name of data, or a vector of length nrow(data); rows are resampled within strata, a numeric stratifier being cut at its quartiles as in rsample), breaks (number of quantile bins for a numeric stratifier, default 4) and apparent (logical; if TRUE an extra "Apparent" resample uses every row for both analysis and assessment).

Value

A data.frame of class c("morie_bootstraps", "data.frame") with one row per resample and columns id ("Bootstrap01", ...) and splits (a list column). Each split is a list with integer row indices analysis (length \(n\), with replacement) and assessment (the out-of-bag rows). The original data are kept in attr(x, "data"); the analysis set of split \(b\) is data[x$splits[[b]]$analysis, , drop = FALSE]. Attributes times, strata and apparent record the call.

Examples

set.seed(1)
rs <- morie_rsample_bootstraps(data.frame(x = rnorm(30)), times = 5L)
rs$id
#> [1] "Bootstrap1" "Bootstrap2" "Bootstrap3" "Bootstrap4" "Bootstrap5"
sp <- rs$splits[[1]]
length(sp$analysis)                 # n rows, drawn with replacement
#> [1] 30
setdiff(seq_len(30), sp$analysis)   # equals sp$assessment (out-of-bag)
#>  [1]  3  5  9 15 20 21 26 27 28 29 30