Generates B number of nonparametric bootstrap samples from the original sample data. data is referred to as the empirical distribution \( \hat{ F } %(\#eq:boot-ecdf) \).

nb(
  data,
  B = 2000L,
  par = FALSE,
  ncores = NULL,
  mc = TRUE,
  lb = FALSE,
  cl_eval = FALSE,
  cl_export = FALSE,
  cl_expr,
  cl_vars
)

Arguments

data

Vector, matrix or data frame. Sample data to bootstrap. The empirical distribution \( \hat{ F } %(\#eq:boot-ecdf) \).

B

Integer. Number of bootstrap samples.

par

Logical. If TRUE, use multiple cores. If FALSE, use lapply().

ncores

Integer. Number of cores to use if par = TRUE. If unspecified, defaults to detectCores() - 1.

mc

Logical. If TRUE, use parallel::mclapply(). If FALSE, use parallel::parLapply() or parallel::parLapplyLB(). Ignored if par = FALSE.

lb

Logical. If TRUE use parallel::parLapplyLB(). If FALSE, use parallel::parLapply(). Ignored if par = FALSE and mc = TRUE.

cl_eval

Logical. Execute parallel::clusterEvalQ() using cl_expr. Ignored if mc = TRUE.

cl_export

Logical. Execute parallel::clusterExport() using cl_vars. Ignored if mc = TRUE.

cl_expr

Expression. Expression passed to parallel::clusterEvalQ() Ignored if mc = TRUE.

cl_vars

Character vector. Names of objects to pass to parallel::clusterExport() Ignored if mc = TRUE.

Value

Returns a list of length B of nonparametric bootstrap samples.

Details

For more details and examples see the following vignettes:

Notes: Intro to NB

Notes: Intro to PB

References

Efron, B., & Tibshirani, R. J. (1993). An introduction to the bootstrap. New York, N.Y: Chapman & Hall.

Wikipedia: Bootstrapping (statistics)

See also

Other bootstrap functions: pbmvn(), pbuniv()

Examples

B <- 5L n <- 5 # vector---------------------------------------------------------------------- x <- rnorm(n = n) xstar <- nb( data = x, B = B ) str(xstar)
#> List of 5 #> $ : num [1:5] -0.105 -1.569 0.709 0.709 -3.002 #> $ : num [1:5] -3.002 -1.569 -0.902 -3.002 0.709 #> $ : num [1:5] -0.105 -0.105 -1.569 -1.569 0.709 #> $ : num [1:5] -1.569 -3.002 -0.902 -0.902 -0.105 #> $ : num [1:5] -1.569 0.709 -3.002 0.709 -0.105
# matrix---------------------------------------------------------------------- x1 <- rnorm(n = n) x2 <- rnorm(n = n) x3 <- rnorm(n = n) X <- cbind(x1, x2, x3) Xstar <- nb( data = X, B = B ) str(Xstar)
#> List of 5 #> $ : num [1:5, 1:3] -0.33 0.938 0.698 0.362 -0.33 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : chr [1:5] "1" "2" "3" "4" ... #> .. ..$ : chr [1:3] "x1" "x2" "x3" #> $ : num [1:5, 1:3] -1.371 -0.33 0.698 0.938 0.362 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : chr [1:5] "1" "2" "3" "4" ... #> .. ..$ : chr [1:3] "x1" "x2" "x3" #> $ : num [1:5, 1:3] -0.33 0.938 -0.33 0.362 0.362 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : chr [1:5] "1" "2" "3" "4" ... #> .. ..$ : chr [1:3] "x1" "x2" "x3" #> $ : num [1:5, 1:3] 0.938 0.938 -0.33 0.698 0.698 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : chr [1:5] "1" "2" "3" "4" ... #> .. ..$ : chr [1:3] "x1" "x2" "x3" #> $ : num [1:5, 1:3] 0.938 -1.371 -1.371 -0.33 0.362 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : chr [1:5] "1" "2" "3" "4" ... #> .. ..$ : chr [1:3] "x1" "x2" "x3"
# data frame------------------------------------------------------------------ X <- as.data.frame(X) Xstar <- nb( data = X, B = B ) str(Xstar)
#> List of 5 #> $ :'data.frame': 5 obs. of 3 variables: #> ..$ x1: num [1:5] 0.362 -0.33 0.938 0.938 0.698 #> ..$ x2: num [1:5] -0.59949 0.7343 -0.00716 -0.00716 -0.71075 #> ..$ x3: num [1:5] -0.956 -0.705 0.183 0.183 -0.328 #> $ :'data.frame': 5 obs. of 3 variables: #> ..$ x1: num [1:5] -0.33 -1.371 0.362 -1.371 -0.33 #> ..$ x2: num [1:5] 0.734 -0.347 -0.599 -0.347 0.734 #> ..$ x3: num [1:5] -0.705 -1.036 -0.956 -1.036 -0.705 #> $ :'data.frame': 5 obs. of 3 variables: #> ..$ x1: num [1:5] -1.371 -0.33 -0.33 -1.371 0.938 #> ..$ x2: num [1:5] -0.347 0.7343 0.7343 -0.347 -0.00716 #> ..$ x3: num [1:5] -1.036 -0.705 -0.705 -1.036 0.183 #> $ :'data.frame': 5 obs. of 3 variables: #> ..$ x1: num [1:5] 0.938 0.698 0.698 -0.33 0.938 #> ..$ x2: num [1:5] -0.00716 -0.71075 -0.71075 0.7343 -0.00716 #> ..$ x3: num [1:5] 0.183 -0.328 -0.328 -0.705 0.183 #> $ :'data.frame': 5 obs. of 3 variables: #> ..$ x1: num [1:5] -1.371 0.362 -1.371 -0.33 0.938 #> ..$ x2: num [1:5] -0.347 -0.59949 -0.347 0.7343 -0.00716 #> ..$ x3: num [1:5] -1.036 -0.956 -1.036 -0.705 0.183