clt.ani: Demonstration of the Central Limit Theorem

Description Usage Arguments Details Value Author(s) References See Also

View source: R/clt.ani.R

Description

First of all, a number of obs observations are generated from a certain distribution for each variable X_j, j = 1, 2, ..., n, and n = 1, 2, ..., nmax, then the sample means are computed, and at last the density of these sample means is plotted as the sample size n increases (the theoretical limiting distribution is denoted by the dashed line), besides, the P-values from the normality test shapiro.test are computed for each n and plotted at the same time.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
clt.ani(
  obs = 300,
  FUN = rexp,
  mean = 1,
  sd = 1,
  col = c("bisque", "red", "blue", "black"),
  mat = matrix(1:2, 2),
  widths = rep(1, ncol(mat)),
  heights = rep(1, nrow(mat)),
  xlim,
  ...
)

Arguments

obs

the number of sample means to be generated from the distribution based on a given sample size n; these sample mean values will be used to create the histogram

FUN

the function to generate n random numbers from a certain distribution

mean, sd

the expectation and standard deviation of the population distribution (they will be used to plot the density curve of the theoretical Normal distribution with mean equal to mean and sd equal to sd/√{n}; if any of them is NA, the density curve will be suppressed)

col

a vector of length 4 specifying the colors of the histogram, the density curve of the sample mean, the theoretical density cuve and P-values.

mat, widths, heights

arguments passed to layout to set the layout of the two graphs.

xlim

the x-axis limit for the histogram (it has a default value if not specified)

...

other arguments passed to plot.default to plot the P-values

Details

As long as the conditions of the Central Limit Theorem (CLT) are satisfied, the distribution of the sample mean will be approximate to the Normal distribution when the sample size n is large enough, no matter what is the original distribution. The largest sample size is defined by nmax in ani.options.

Value

A data frame of P-values.

Author(s)

Yihui Xie

References

Examples at https://yihui.org/animation/example/clt-ani/

See Also

hist, density


animation documentation built on Oct. 7, 2021, 9:18 a.m.