balanced_bootstrap: Generate balanced bootstrap replicates

Description Usage Arguments Value Methods (by class) References See Also Examples

Description

A balanced bootstrap generates R replicates in which each element appears R times.

Usage

1
2
3
4
5
6
7
balanced_bootstrap(data, ...)

## S3 method for class 'data.frame'
balanced_bootstrap(data, R = 1L, ...)

## S3 method for class 'grouped_df'
balanced_bootstrap(data, R = 1L, stratify = FALSE, ...)

Arguments

data

A data frame

...

Arguments passed to methods

R

Number of replicates

stratify

If TRUE, resample within groups, otherwise, resample by groups instead of rows.

Value

A data frame with R rows and the following columns:

train

A list of resample objects. Training sets.

test

A list of resample objects. Test sets.

.id

An integer vector of identifiers

Methods (by class)

References

See Also

The boot function boot which is the canonical R bootstrap implementation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# example from modelr::bootstrap
library("purrr")
library("dplyr")
boot <- balanced_bootstrap(mtcars, 100)

models <- map(boot$sample, ~ lm(mpg ~ wt, data = .))
tidied <- map_df(models, broom::tidy, .id = "id")

hist(subset(tidied, term == "wt")$estimate)
hist(subset(tidied, term == "(Intercept)")$estimate)

jrnold/resamplr documentation built on May 20, 2019, 1:05 a.m.