Chan Ching Chuen
2023-10-11
The app is a demonstration of the Central Limit Theorem, using the uniform distribution. To recap, let \(X_1, X_2, ... X_n\) denote a random sample of n independent observations from a population with mean \(\mu\) and variance \(\sigma^2\). Then the sample mean \(\bar{X_n}\), has a distribution that converges to normal distribution with mean equals \(\mu\) and variance \(\sigma^2/n\).
In this demonstration we use the uniform distribution, and let user to play with different sample size \(n\), and simulate this a number of times, say 1000, and display the histograms for the simulations of the \(\bar{X_n}\) comparing against the theoretical normal distribution predicted by the Central Limit Theorem.
For an explanation of how the Central Limit Theorem works, see https://en.wikipedia.org/wiki/Central_limit_theorem.
The user is going to input 4 paramters: the sample size \(n\) in the previous slide, and the number of simulations \(N\) that controls how many sample means to simulate. The uniform distribution is defined by 2 parameters \(b\) and \(a\) which define the upper and lower bound respectively.
nsamp <- 30
nsims <- 1000
b <- 1
a <- 0
#simulate sample means
gen_xn <- replicate(nsims, mean(runif(nsamp, min=a, max=b)))
head(gen_xn)## [1] 0.5188705 0.5272075 0.4674096 0.5707356 0.4122941 0.4298820
A sample plot using parameters in the previous page is shown below, showing how the simulation approximates a normal distribution:
For future developments, we can consider
including more distributions other than the uniform distribution, for example the exponential distribution and poisson distribution, to illustrate how the Central Limit Theorem works on different distributions
adding illustration of the underlying distribution to give a sense how the sample means from distributions of different “shapes” all converge to the normal distribution