Learn R Programming

animation (version 0.2-0)

conf.int: Demonstration of Confidence Intervals

Description

This function gives a demonstration of the concept of confidence intervals in mathematical statistics in this way: 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.

Usage

conf.int(level = 0.95, size = 50, 
    control = ani.control(interval = 0.3), ...)

Arguments

level
the confidence level (1 - alpha), e.g. 0.95
size
the sample size for drawing samples from N(0, 1)
control
control parameters for the animation; see ani.control
...
other arguments passed to ani.control

Value

  • A list containing
  • levelconfidence level
  • sizesample size
  • CIa matrix of confidence intervals for each sample
  • CRcoverage rate

Details

Intervals that cover the true parameter are denoted in gray color, otherwise in red color. As the process of drawing samples goes on, there will be a legend indicating the numbers of the two kinds of intervals respectively. The argument nmax in control means the times of drawing samples.

References

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

Examples

Run this code
conf.int()

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

Run the code above in your browser using DataLab