Demonstration of the concept of confidence intervals

Description Usage Arguments Details Value Author(s) References

View source: R/


This function gives a demonstration of the concept of confidence intervals in mathematical statistics.


1 = 0.95, size = 50, cl = c("red", "gray"), ...)



the confidence level (1 - α), e.g. 0.95


the sample size for drawing samples from N(0, 1)


two different colors to annotate whether the confidence intervals cover the true mean (cl[1]: no; cl[2]: yes)


other arguments passed to plot.default


Keep on drawing samples from the Normal distribution N(0, 1), computing the intervals based on a given confidence level and plotting them as segments in a graph. In the end, we may check the coverage rate against the given confidence level.

Intervals that cover the true parameter are denoted in color cl[2], otherwise in color cl[1]. Each time we draw a sample, we can compute the corresponding confidence interval. As the process of drawing samples goes on, there will be a legend indicating the numbers of the two kinds of intervals respectively and the coverage rate is also denoted in the top-left of the plot.

The argument nmax in ani.options controls the maximum times of drawing samples.


A list containing


confidence level


sample size


a matrix of confidence intervals for each sample


coverage rate


Yihui Xie


George Casella and Roger L. Berger. Statistical Inference. Duxbury Press, 2th edition, 2001.

animation documentation built on May 19, 2017, 8:08 a.m.

Search within the animation package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.