View source: R/central_limit_theorem.R
clt  R Documentation 
A movie to illustrate the ideas of the sampling distribution of a mean and the central limit theorem.
clt(
n = 20,
distn,
params = list(),
panel_plot = TRUE,
hscale = NA,
vscale = hscale,
n_add = 1,
delta_n = 1,
arrow = TRUE,
leg_cex = 1.25,
...
)
n 
An integer scalar. The size of the samples drawn from the
distribution chosen using 
distn 
A character scalar specifying the distribution from which
observations are sampled. Distributions If The The other cases use the distributional functions in the

params 
A named list of additional arguments to be passed to the
density function associated with distribution If a parameter value is not supplied then the default values in the
relevant distributional function set using 
panel_plot 
A logical parameter that determines whether the plot
is placed inside the panel ( 
hscale , vscale 
Numeric scalars. Scaling parameters for the size
of the plot when 
n_add 
An integer scalar. The number of simulated datasets to add to each new frame of the movie. 
delta_n 
A numeric scalar. The amount by which n is increased (or decreased) after one click of the + (or ) button in the parameter window. 
arrow 
A logical scalar. Should an arrow be included to show the simulated sample mean from the top plot being placed into the bottom plot? 
leg_cex 
The argument 
... 
Additional arguments to the rpanel functions

Loosely speaking, a consequence of the
Central Limit Theorem
is that the mean of a large number of independent and
identically distributed random variables, each with mean \mu
and
finite standard deviation \sigma
, has approximately a
normal distribution, even if these original variables are not normally
distributed.
This movie considers examples where this limiting result holds and
illustrates graphically the closeness of the limiting approximation
provided by the relevant normal limit to the true finiten
distribution. Of course, when distn = "normal"
this result is
exact.
Samples of size n
are repeatedly simulated from the distribution
chosen using distn
. These samples are summarized using a plot
that appears at the top of the movie screen. For each sample the mean
of these n
values is calculated, stored and added to another plot,
situated below the first plot.
This plot is either a histogram or an empirical c.d.f., chosen using a
radio button.
A rug
is added to a histogram provided that it
contains no more than 1000 points.
The p.d.f. (for a continuous variable) or p.m.f. (for a discrete variable) of the original variables is added to the top plot.
Once it starts, four aspects of this movie are controlled by the user.
There are buttons to increase (+) or decrease () the sample size, that is, the number of values over which a mean is calculated.
Each time the button labelled "simulate another n_add
samples of size n" is clicked n_add
new samples are simulated
and their sample mean are added to the bottom histogram.
There is a button to switch the bottom plot from displaying a histogram of the simulated means and the limiting normal p.d.f. to the empirical c.d.f. of the simulated data and the limiting normal c.d.f.
There is a checkbox to add to the bottom plot the approximate
(large n
) normal p.d.f./c.d.f. (with mean \mu
and
standard deviation \sigma / \sqrt{n}
), implied by the CLT.
Nothing is returned, only the animation is produced.
movies
: a userfriendly menu panel.
smovie
: general information about smovie.
cltq
: Central Limit Theorem for sample quantiles.
# Exponential data
clt()
# Uniform data
clt(distn = "uniform")
# Poisson data
clt(distn = "poisson")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.