One and two sample bootstrap sampling and permutation tests.
Basic resampling. Supply the data and statistic to resample.
bootstrap(data, statistic, R = 10000, args.stat = NULL, seed = NULL, sampler = samp.bootstrap, label = NULL, statisticNames = NULL, block.size = 100, trace = FALSE) bootstrap2(data, statistic, treatment, data2 = NULL, R = 10000, ratio = FALSE, args.stat = NULL, seed = NULL, sampler = samp.bootstrap, label = NULL, statisticNames = NULL, block.size = 100, trace = FALSE) permutationTest(data, statistic, R = 9999, alternative = "two.sided", resampleColumns = NULL, args.stat = NULL, seed = NULL, sampler = samp.permute, label = NULL, statisticNames = NULL, block.size = 100, trace = FALSE, tolerance = .Machine$double.eps ^ 0.5) permutationTest2(data, statistic, treatment, data2 = NULL, R = 9999, alternative = "two.sided", ratio = FALSE, paired = FALSE, args.stat = NULL, seed = NULL, sampler = samp.permute, label = NULL, statisticNames = NULL, block.size = 100, trace = FALSE, tolerance = .Machine$double.eps ^ 0.5)
- vector, matrix, or data frame.
- a function, or expression (e.g.
mean(myData, trim = .2).
- number of replicates (bootstrap samples or permutation resamples).
- a vector with two unique values.
For two-sample applications, suppy either
- an object like
data; the second sample.
- one of
statisticreturns a vector, this may be a vector of the same length.
- logical, if
FALSEthen statistics for two samples are combined using statistic1 - statistic2 (the statistics from the two samples). If
TRUE, it uses statistic1 / statistic2.
- integer, or character (a subset of the column names of
data); if supplied then only these columns of the data are permuted. For example, for a permutation test of the correlation of x and y, only one of the variables should be per
- a list of additional arguments to pass to
statistic, if it is a function.
- logical, if
TRUEthen observations in
data2are paired, and permutations are done within each pair. Not yet implemented.
- old value of .Random.seed, or argument to set.seed.
- a function for resampling, see
- used for labeling plots (in a future version).
- a character vector the same length as the vector returned by
- integer. The
Rreplicates are done this many at a time.
- logical, if
TRUEan indication of progress is printed.
- when computing P-values, differences smaller than
tolerance(absolute or relative) between the observed value and the replicates are considered equal.
There is considerable flexibility in how you specify the data and statistic.
statistic, you may supply a function, or an expression.
For example, if
data = x, you may specify any of
statistic = mean
statistic = mean(x)
statistic = mean(data)
- a list with class
"permutationTest2", that inherits from
"resample", with components:
observed the value of the statistic for the original data. replicates a matrix with
n number of observations in the original data, or vector of length 2 in two-sample problems. p
R number of replications. seed the value of the seed at the start of sampling. call the matched call. statistics a data frame with
prows, with columns
"mean"(the mean of the replicates), and other columns appropriate to resampling; e.g. the bootstrap objects have columns
"Bias", while the permutation test objects have
- The two-sample versions have an additional component:
resultsBoth containing resampling results from each data set. containing two components, the results from resampling each of the two samples. These are
bootstrapobjects; in the
permutationTest2case they are the result of sampling without replacement.
- There are functions for printing and plotting these objects,
plot(currently the same as
statistic = colMeans(data)
statistic = mean(myData$x)
statistic = mean(myData[, "x"])
# See full set of examples in resample-package, including different # ways to call the functions depending on the structure of the data. data(Verizon) CLEC <- with(Verizon, Time[Group == "CLEC"]) bootC <- bootstrap(CLEC, mean) bootC hist(bootC) qqnorm(bootC)