Skip to contents

Samples randomly from the elements of object with replacement.

Usage

# S4 method for DiversityIndex
bootstrap(object, n = 1000, f = NULL)

Arguments

object

An R object (typically a DiversityIndex object).

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.

See also

Other resampling methods: jackknife(), resample()

Author

N. Frerebeau

Examples

## Data from Conkey 1980, Kintigh 1989
data("cantabria")

## Shannon diversity index
(h <- heterogeneity(cantabria, method = "shannon"))
#> [1] 3.269200 2.955298 2.491683 2.485604 2.329187

## Bootstrap resampling
bootstrap(h, f = NULL)
#>                  original     mean         bias      error
#> Altamira         3.269200 3.278498  0.009297979 0.08048385
#> Cueto de la Mina 2.955298 2.972580  0.017281827 0.15700290
#> El Juyo          2.491683 2.521575  0.029891792 0.19021698
#> El Cierro        2.485604 2.487144  0.001539771 0.22464720
#> La Paloma        2.329187 2.310936 -0.018250257 0.26487280

bootstrap(h, f = summary)
#>                      Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
#> Altamira         2.992719 3.222878 3.280765 3.276743 3.334473 3.549729
#> Cueto de la Mina 2.356353 2.894522 2.983316 2.977874 3.078325 3.369425
#> El Juyo          1.721241 2.376338 2.521911 2.515313 2.655347 3.117557
#> El Cierro        1.559581 2.351641 2.510941 2.486987 2.634027 2.978305
#> La Paloma        1.273028 2.151884 2.334882 2.308805 2.491505 2.931322

quant <- function(x) quantile(x, probs = c(0.25, 0.50))
bootstrap(h, f = quant)
#>                       25%      50%
#> Altamira         3.229277 3.287153
#> Cueto de la Mina 2.888914 2.986238
#> El Juyo          2.406740 2.535562
#> El Cierro        2.341829 2.499437
#> La Paloma        2.152664 2.339654