bootstrap | R Documentation |
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)
data |
vector, matrix, or data frame. |
statistic |
a function, or expression (e.g. |
R |
number of replicates (bootstrap samples or permutation resamples). |
treatment |
a vector with two unique values.
For two-sample applications, suppy either |
data2 |
an object like |
alternative |
one of |
ratio |
logical, if |
resampleColumns |
integer, or character (a subset of the column names of |
args.stat |
a list of additional arguments to pass to |
paired |
logical, if |
seed |
old value of .Random.seed, or argument to set.seed. |
sampler |
a function for resampling, see |
label |
used for labeling plots (in a future version). |
statisticNames |
a character vector the same length as the vector returned by
|
block.size |
integer. The |
trace |
logical, if |
tolerance |
when computing P-values, differences smaller than |
There is considerable flexibility in how you specify the data and statistic.
For the 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)
If data
is a data frame, the expression may refer to columns in
the data frame, e.g.
statistic = mean(x)
statistic = mean(myData$x)
statistic = mean(myData[, "x"])
If data
is not just the name of an object, e.g.
data = subset(myData, age > 17)
, or if data2
is supplied, then use the name 'data', e.g.
statistic = colMeans(data)
a list with class
"bootstrap"
, "bootstrap2"
,
"permutationTest"
,
or "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 |
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
|
There are functions for printing and plotting these objects,
in particular print
, hist
, qqnorm
,
plot
(currently the same as hist
),
quantile
.
Tim Hesterberg timhesterberg@gmail.com,
https://www.timhesterberg.net/bootstrap-and-resampling
resample-package
,
samp.bootstrap
,
CI.percentile
,
CI.t
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.