lln.ani {animation}R Documentation

Demonstration of Law of Large Numbers

Description

This function plots the sample mean as the sample size grows to check whether the sample mean approaches to the population mean.

Usage

lln.ani(FUN = rnorm, mu = 0, np = 30, pch = 20, col.poly = "bisque",
    col.mu = "gray", ...)

Arguments

FUN a function to generate random numbers from a certain distribution: function(n, mu)
mu population mean; passed to FUN
np times for sampling from a distribution (not the sample size!); to examine the behaviour of the sample mean, we need more times of sampling to get a series of mean values
pch symbols for points; see Details
col.poly the color of the polygon to annotate the range of sample means
col.mu the color of the horizontal line which denotes the population mean
... other arguments passed to points

Details

np points are plotted to denote the distribution of the sample mean; we will observe that the range of the sample mean just becomes smaller and smaller as the sample size increases and ultimately there will be an obvious trend that the sample mean converges to the population mean mu.

The parameter nmax in ani.options means the maximum sample size.

Value

None (invisible `NULL').

Note

The argument pch will influence the speed of plotting, and for a very large sample size (say, 300), it is suggested that this argument be specified as '.'.

Author(s)

Yihui Xie

References

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

http://animation.yihui.name/prob:law_of_large_numbers

Examples

oopt = ani.options(interval = 0.01, nmax = 150)
lln.ani(pch = ".")

# chi-square distribution; population mean = df
lln.ani(function(n, mu) rchisq(n, df = mu), mu = 5, cex = 0.6)

## Not run: 
 
# save the animation in HTML pages
ani.options(ani.height = 480, ani.width = 600, outdir = getwd(), nmax = 100,
    interval = 0.1, title = "Demonstration of the Law of Large Numbers",
    description = "The sample mean approaches to the population mean as
    the sample size n grows.")
ani.start()
par(mar = c(3, 3, 1, 0.5), mgp = c(1.5, 0.5, 0))
lln.ani(cex = 0.6)
ani.stop()

## End(Not run)
ani.options(oopt)

[Package animation version 1.0-4 Index]