Simulates observations from a multinomial distribution.
Usage
resample(object, ...)
# S4 method for numeric
resample(object, do, n, size = sum(object), ..., f = NULL)
Arguments
- object
A
numeric
vector of count data (absolute frequencies).- ...
Extra arguments passed to
do
.- do
A
function
that takesobject
as an argument and returns a single numeric value.- n
A non-negative
integer
specifying the number of bootstrap replications.- size
A non-negative
integer
specifying the sample size.- f
A
function
that takes a single numeric vector (the result ofdo
) as argument.
Value
If f
is NULL
, resample()
returns the n
values of do
. Else,
returns the result of f
applied to the n
values of do
.
See also
Other resampling methods:
bootstrap_diversity
,
jackknife_diversity
Examples
## Sample observations from a multinomial distribution
x <- sample(1:100, 50, TRUE)
resample(x, do = median, n = 100)
#> [1] 45.5 48.0 45.5 47.0 49.0 51.5 48.0 51.0 42.0 47.0 47.5 46.5 48.0 44.5 42.0
#> [16] 48.5 48.0 45.0 43.5 47.5 43.5 46.5 44.5 48.0 42.0 51.0 47.5 43.5 42.5 43.5
#> [31] 47.5 50.0 44.5 46.0 49.0 52.5 47.0 46.5 42.5 47.0 51.5 45.0 51.0 47.5 45.0
#> [46] 49.5 45.5 48.0 48.5 45.0 45.0 47.5 48.0 51.5 46.5 46.0 46.5 44.5 45.0 47.0
#> [61] 43.5 43.5 50.0 47.5 48.5 48.0 48.0 46.5 50.0 45.5 45.5 44.0 45.5 49.0 48.0
#> [76] 46.5 49.0 42.0 46.5 43.0 49.5 42.0 45.5 48.5 46.0 44.5 50.0 46.5 47.0 47.5
#> [91] 49.5 44.0 47.0 43.5 48.5 48.0 46.5 46.0 46.0 40.0
## Estimate the 25th, 50th and 95th percentiles
quant <- function(x) { quantile(x, probs = c(0.25, 0.50, 0.75)) }
resample(x, n = 100, do = median, f = quant)
#> 25% 50% 75%
#> 45.0 46.5 48.5