Interactively Demonstrate the Central Limit Theorem
ShinyCLTExamp.RdLaunches a Shiny app wrapping clt.examp: it simulates
several datasets from each of 4 different population shapes for a
given sample size, and plots histograms of the samples (and of their
means) with a normal reference curve.
Arguments
- n
Initial sample size.
- reps
Number of samples to take from each distribution. Passed through to
clt.examp.- nclass
Number of bars in the histograms. Passed through to
clt.examp.- norm.param
List with parameters passed to
rnorm. Passed through toclt.examp.- gamma.param
List with parameters passed to
rgamma. Passed through toclt.examp.- unif.param
List with parameters passed to
runif. Passed through toclt.examp.- beta.param
List with parameters passed to
rbeta. Passed through toclt.examp.
Details
This function requires the shiny package to be installed. With the default sample size of 1 the plots show the shapes of the 4 populations; increasing the sample size shows the sampling distribution of the mean becoming more normal, illustrating the Central Limit Theorem. It is best to select and retype the sample size value rather than use small increments.
Only n is interactive (via the “Sample Size” input in
the app); reps, nclass, norm.param,
gamma.param, unif.param, and beta.param are set
once when ShinyCLTExamp is called and passed through to every
call of clt.examp made by the app.
Value
Launches the app in non-blocking mode (via
startApp) and returns a ShinyAppHandle
immediately, so the R console remains available while the app runs
in the background. Use handle$stop() to stop the app.
Author
Greg Snow 538280@gmail.com
Examples
if(interactive()) {
h <- ShinyCLTExamp()
# h$stop() # run this when finished with the app
h <- ShinyCLTExamp(reps = 2000, gamma.param = list(shape = 2, rate = 1))
# h$stop() # run this when finished with the app
}