Learn R Programming

CarletonStats (version 2.2)

boot: Bootstrap

Description

Bootstrap a single variable or a grouped variable

Usage

boot(x, ...)

# S3 method for default boot( x, group = NULL, statistic = mean, conf.level = 0.95, B = 10000, plot.hist = TRUE, plot.qq = FALSE, x.name = deparse(substitute(x)), xlab = NULL, ylab = NULL, title = NULL, seed = NULL, ... )

# S3 method for formula boot(formula, data, subset, ...)

Value

A vector with the resampled statistics is returned invisibly.

Arguments

x

a numeric vector

...

further arguments to be passed to or from methods.

group

an optional grouping variable (vector), usually a factor variable. If it is a binary numeric variable, it will be coerced to a factor.

statistic

function that computes the statistic of interest. Default is the mean.

conf.level

confidence level for the bootstrap percentile interval. Default is 95%.

B

number of times to resample (positive integer greater than 2).

plot.hist

logical value. If TRUE, plot the histogram of the bootstrap distribution.

plot.qq

Logical value. If TRUE, create a normal quantile-quantile plot of the bootstrap distribution.

x.name

Label for variable name

xlab

an optional character string for the x-axis label

ylab

an optional character string for the y-axis label

title

an optional character string giving the plot title

seed

optional argument to set.seed

formula

a formula y ~ g where y is a numeric vector and g a factor variable with two levels. If g is a binary numeric vector, it will be coerced to a factor variable. For a single numeric variable, formula may also be ~ y.

data

a data frame that contains the variables given in the formula.

subset

an optional expression indicating what observations to use.

Methods (by class)

  • boot(default): Bootstrap a single variable or a grouped variable

  • boot(formula): Bootstrap a single variable or a grouped variable

Author

Laura Chihara

Details

Perform a bootstrap of a statistic applied to a single variable, or to the difference of the statistic computed on two samples (using the grouping variable). If x is a binary vector of 0's and 1's and the function is the mean, then the statistic of interest is the proportion.

Observations with missing values are removed.

References

Tim Hesterberg's website https://www.timhesterberg.net/bootstrap-and-resampling

Examples

Run this code

#ToothGrowth data (supplied by R)
#bootstrap mean of a single numeric variable
boot(ToothGrowth$len)

#bootstrap difference in mean of tooth length for two groups.
boot(ToothGrowth$len, ToothGrowth$supp, B = 1000)

#same as above using formula syntax
boot(len ~ supp, data = ToothGrowth, B = 1000)

Run the code above in your browser using DataLab