Samples randomly from the elements of object with replacement.

## Usage

bootstrap(object, ...)

# S4 method for numeric
bootstrap(object, do, n, ..., f = NULL)

## Arguments

object

A numeric vector.

...

Extra arguments to be passed to do.

do

A function that takes object as an argument and returns a single numeric value.

n

A non-negative integer giving the number of bootstrap replications.

f

A function that takes a single numeric vector (the result of do) as argument.

## Value

If f is NULL (the default), bootstrap() returns a named numeric

vector with the following elements:

original

The observed value of do applied to object.

mean

The bootstrap estimate of mean of do.

bias

The bootstrap estimate of bias of do.

error

he bootstrap estimate of standard error of do.

If f is a function, bootstrap() returns the result of f applied to the n values of do.

Other resampling methods: jackknife()

N. Frerebeau

## Examples

x <- rnorm(20)

## Bootstrap
bootstrap(x, do = mean, n = 100)
#>    original        mean        bias       error
#> -0.31003022 -0.36538846 -0.05535824  0.25116541

## Estimate the 25th and 95th percentiles
quant <- function(x) { quantile(x, probs = c(0.25, 0.75)) }
bootstrap(x, n = 100, do = mean, f = quant)
#>        25%        75%
#> -0.4233110 -0.1714454

## Get the n bootstrap values
bootstrap(x, n = 100, do = mean, f = function(x) { x })
#>   [1]  0.05882350 -0.15970975 -0.16824740 -0.25337802  0.38357259 -0.27767305
#>   [7] -0.56937703 -0.17413748 -0.52393747 -0.03761762 -0.37639113 -0.62335220
#>  [13]  0.02098242 -0.48991571 -0.38256150 -0.35694976 -0.07544047 -0.28480161
#>  [19] -0.38464752 -0.55362749 -0.27333930 -0.48971194 -0.11691814 -0.98175087
#>  [25] -0.74759480 -0.38207080 -0.52612229 -0.52627593 -0.48806821 -0.03992511
#>  [31] -0.38862562 -0.01227077 -0.97275850 -0.41971631 -0.03975755 -0.07345552
#>  [37] -0.47651196  0.07988537 -0.34898297 -0.52959421 -0.32875221 -0.53683465
#>  [43] -0.53870283 -0.15155093 -0.22187541 -0.55008251 -0.93603395 -0.25134170
#>  [49]  0.09068206 -0.30633353  0.01512999  0.02636154 -0.62805636 -0.41543211
#>  [55] -0.73731395 -0.60169945 -0.10066947 -0.26596719 -0.10152999  0.01594432
#>  [61] -0.20390957  0.25543398 -0.17004627 -1.00197428  0.03192212  0.09843582
#>  [67] -0.71917920 -0.72579064 -0.39998269 -0.49303580 -0.37553424 -0.42163805
#>  [73] -0.42700161 -0.26265073 -0.43257369 -0.29944782 -0.33025893 -0.21952608
#>  [79] -0.33849245 -0.68065268 -0.25271155  0.12362128  0.01747910 -0.54110655
#>  [85] -0.15135539  0.03421979 -0.06693228 -0.79303070 -0.04313817 -0.34621952
#>  [91]  0.25973890 -0.57828512 -0.18786661 -0.05036271 -0.42062992 -0.10856037
#>  [97] -0.25766274 -0.01699731 -0.19125433 -0.21562539

## Jackknife
jackknife(x, do = mean) # Sample mean
#>   original       mean       bias      error
#> -0.3100302 -0.3100302  0.0000000  0.2514894

## Get the leave-one-out values instead of summary
jackknife(x, do = mean, f = function(x) { x })
#>  [1] -0.2526611 -0.3397853 -0.1980706 -0.3260544 -0.3590609 -0.3867903
#>  [7] -0.2304625 -0.3133305 -0.3134950 -0.3114684 -0.2972055 -0.3594519
#> [13] -0.4350331 -0.2405060 -0.3533174 -0.2282944 -0.2988733 -0.3235791
#> [19] -0.3549264 -0.2782384