bootstrap: Generate bootstrap replicates

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

Description

Generate bootstrap replicates. In addition to the ordinary bootstrap, it supports weighted bootstrap (weights), Bayesian bootstrap (bayes), cluster bootstrap (if data is a grouped data frame and groups = TRUE), and stratified bootstrap (if data is grouped data frame and stratify = TRUE).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
bootstrap(data, ...)

## S3 method for class 'data.frame'
bootstrap(data, R = 1L, weights = NULL,
  bayes = FALSE, m = NULL, ...)

## S3 method for class 'grouped_df'
bootstrap(data, R = 1L, stratify = FALSE,
  groups = TRUE, weights = NULL, bayes = FALSE, weight_groups = TRUE,
  weight_within = TRUE, ...)

Arguments

data

A data frame

...

Passed to methods

R

Number of replicates to sample

weights

Observation level weights. This must be the name of a column in data.

bayes

If TRUE, a Bayesian bootstrap is used.

m

Number of observations in the replicates.

stratify

Resample within groups (stratified bootstrap)

groups

Resample groups (clustered bootstrap)

weight_groups

If TRUE and groups = TRUE, then sample groups using group-level weights. If weights is NULL, then weight groups by the number of observations in each. If weights, is not-NULL, then use the sum of the observation level weights in each group as the group-level weight.

weight_within

If TRUE and stratify = TRUE, then use observation level weights to sample observations within each group.

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. This function produces slightly different output and has more options than the modelr function bootstrap.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# example from modelr::bootstrap
library("purrr")
library("dplyr")
boot <- 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.