Learn R Programming

sjstats (version 0.3.0)

bootstrap: Generate bootstrap replications

Description

Generates n bootstrap samples of data and returns the bootstrapped data frames as list-variable.

Usage

bootstrap(data, n, size)

Arguments

data
A data frame.
n
Number of bootstraps to be generated
size
Optional, size of the bootstrap samples. May either be a number between 1 and nrow(data) or a value between 0 and 1 to sample a proportion of observations from data (see 'Examples').

Value

A data_frame with one column: a list-variable strap, which contains the bootstrapped samples from data.

Details

By default, each bootstrap sample has the same number of observations as data. To generate bootstrap samples without resampling same observations (i.e. sampling without replacement), use size to get bootstrapped data with a specific number of observations.

See Also

boot_ci to calculate confidence intervals from bootstrap samples.

Examples

Run this code
data(efc)
bs <- bootstrap(efc, 5)

# now run models for each bootstrapped sample
lapply(bs$strap, function(x) lm(neg_c_7 ~ e42dep + c161sex, data = x))

# generate bootstrap samples with 600 observations for each sample
bs <- bootstrap(efc, 5, 600)

# generate bootstrap samples with 70% observations of the original sample size
bs <- bootstrap(efc, 5, .7)


Run the code above in your browser using DataLab