resample (version 0.4)

resample: Nonparametric resampling

Description

This function is called by bootstrap and other resampling functions to actually perform resampling, but may also be called directly.

Usage

resample(data, resampleFun, sampler, R = 10000, seed = NULL,
         statisticNames = NULL, block.size = 100,
         trace = FALSE, ..., observedIndices = 1:n,
         call = match.call())

Arguments

data

vector, matrix, or data frame.

resampleFun

a function with argument data and ii, that calculates a statistic of interest for data[ii] or data[ii, , drop=FALSE], for a vector or matrix, respectively.

sampler

a function like samp.bootstrap or samp.permute.

R

number of resamples.

seed

old value of .Random.seed, or argument to set.seed.

statisticNames

a character vector the same length as the vector returned by statistic.

block.size

integer. The R replicates are done this many at a time.

trace

logical, if TRUE an indication of progress is printed.

addition arguments passed to sampler.

observedIndices

integer vector of indices, used for calculating the observed value. When this is called by bootstrap2 or permutationTest2, those should be indices corresponding to one sample in a merged data set.

call

typically the call to bootstrap or another function that calls resample. This may be a character string, e.g. when called from bootstrap2.

Value

an object of class "resample"; this is a list with components:

observed

the observed statistic, length p.

replicates

a matrix with R rows and p columns.

n

number of observations

p

the length of the statistic returned by resampleFun.

R

number of resamples.

seed

the value of seed when this function is called.

Details

This is called by bootstrap, bootstrap2, permutationTest, and permutationTest2 to actually perform resampling. The results are passed back to the calling function, which may add additional components and a class, which inherits from "resample".

This may also be called directly. In contrast to the other functions, where you have flexibility in how you specify the statistic, here resampleFun must be a function.

See Also

bootstrap, bootstrap2, permutationTest, permutationTest2, samp.bootstrap, samp.permute.

For an overview of all functions in the package, see resample-package.

Examples

Run this code
# NOT RUN {
# See full set of examples in resample-package, including different
# ways to call all the functions depending on the structure of the data.
data(Verizon)
CLEC <- with(Verizon, Time[Group == "CLEC"])
bootC <- bootstrap(CLEC, mean, seed = 0)
bootC
# }

Run the code above in your browser using DataLab