Learn R Programming

animation (version 0.2-0)

boot.iid: Bootstrap for i.i.d data

Description

Demonstrate bootstrapping for i.i.d data: use sunflower scatter plot to illustrate the situation of sampling, and histogram to show the distribution of the statistic of interest.

Usage

boot.iid(x = runif(20), statistic = mean, m = length(x), 
    control = ani.control(), ...)

Arguments

x
a numerical vector (the original data).
statistic
A function which returns a value of the statistic of interest when applied to the data x.
m
the sample size for bootstrapping (m-out-of-n bootstrap)
control
control parameters for the animation; see ani.control
...
other arguments passed to ani.control

Value

  • A list containing
  • t0The observed value of 'statistic' applied to 'x'.
  • tstarBootstrap versions of the 'statistic'.

Details

This is actually a very naive version of bootstrapping but may be useful for novices. The blue points denote the orignial dataset, while the red points with (possible) leaves denote sample points being resampled; the number of leaves just means how many times these points are resampled, as bootstrap samples with replacement.

References

There are many references explaining the bootstrap and its variations. For a relatively complete one, you may just refer to: Efron, B. and Tibshirani, R. (1993) An Introduction to the Bootstrap. Chapman & Hall.

See Also

sunflowerplot, ani.start, ani.stop

Examples

Run this code
# bootstrap for 20 random numbers following U(0, 1) 
boot.iid(interval = 0.5)

# for the median of 15 points from chi-square(5) 
boot.iid(x = rchisq(15, 5), statistic = median, interval = 0.5) 

# save the animation in HTML pages
ani.start()
boot.iid(saveANI = TRUE, width = 600, height = 500, interval = 0.2)
ani.stop()

Run the code above in your browser using DataLab