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

## Jackknife resampling
jackknife(h)
#>                  original     mean       bias      error
#> Altamira         3.269200 3.246457 -0.9779158 0.08145529
#> Cueto de la Mina 2.955298 2.932856 -0.9649994 0.15907033
#> El Juyo          2.491683 2.469588 -0.9500688 0.19670002
#> El Cierro        2.485604 2.462723 -0.9838709 0.22195573
#> La Paloma        2.329187 2.305876 -1.0023704 0.25266291

bootstrap(h, f = summary)
#>                       Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
#> Altamira         2.9433811 3.228458 3.281614 3.279012 3.330767 3.525044
#> Cueto de la Mina 1.8388354 2.894162 2.991616 2.981012 3.083455 3.384161
#> El Juyo          1.6831475 2.383264 2.534352 2.514869 2.653568 3.144314
#> El Cierro        1.6496588 2.344457 2.495462 2.475503 2.624966 3.000800
#> La Paloma        0.6931472 2.165292 2.335162 2.316862 2.502661 2.941134