Learn R Programming

animation (version 2.0-5)

sample.strat: Demonstration for the stratified sampling

Description

Demonstration for the stratified sampling.

Usage

sample.strat(pop = ceiling(10 * runif(10, 0.5, 1)), 
    size = ceiling(pop * runif(length(pop), 0, 0.5)), p.col = c("blue", 
        "red"), p.cex = c(1, 3), ...)

Arguments

pop
a vector for the size of each stratum in the population.
size
a corresponding vector for the sample size in each stratum (recycled if necessary).
p.col,p.cex
different colors /magnification rate to annotate the population and the sample
...
other arguments passed to rect to annotate the ``strata''

Value

  • None (invisible `NULL').

Details

Each rectangle stands for a stratum, and the simple random sampling without replacement is performed within each stratum. The points being sampled are marked out (by red circles by default).

References

http://animation.yihui.name/samp:stratified_sampling

See Also

sample, sample.simple, sample.cluster, sample.ratio, sample.system

Examples

Run this code
oopt = ani.options(nmax = ifelse(interactive(), 50, 
    2))
par(mar = rep(1, 4), lwd = 2)

sample.strat(col = c("bisque", "white"))

## HTML animation page
saveHTML({
    par(mar = rep(1, 4), lwd = 2)
    ani.options(nmax = ifelse(interactive(), 50, 2))
    sample.strat(col = c("bisque", "white"))
}, img.name = "sample.strat", htmlfile = "sample.html", ani.height = 350, 
    ani.width = 500, title = "Demonstration of the stratified sampling", 
    description = c("Every rectangle stands for a stratum, and the simple", 
        "random sampling without replacement is performed within each stratum."))

ani.options(oopt)

Run the code above in your browser using DataLab