lln.ani()

Demonstration of the Law of Large Numbers

Yihui Xie & Lijia Yu 2017-04-04

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

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.

library(animation)
ani.options(interval = 0.01, nmax = 150)

lln.ani(pch = ".")

plot of chunk demo-a

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

plot of chunk demo-b

The sample mean approaches to the population mean as the sample size n grows