Central Limit Theorem

Illustrating Central Limit Theorem with simulations

BurakH
Data Scientist

Overview

  • Ilustrate Central Limit Theorem
  • 50 data points chosen from the exponential distribution
  • Vary the \(\lambda\) parameter in the exponential distribution and number of simulations
  • As a function of these two, observe that the distribution of the sample means is normal

Exponential Distribution

The probability density function of the exponential distribution is given by the equation \[P(x,\lambda) = \lambda\, \exp(-\lambda\, x)\]

The exponential distributon has mean and standard deviation equal to \(1/\lambda\). Below is the plot for the probability density function the exponential distribution

plot of chunk unnamed-chunk-1

Simulations

We choose 50 random points from the exponential distribution and simulate nsim times to obtain sample distribution of means and variances:

means <- NULL; vars <- NULL; n <- 50
for (i in 1:nsim){
  rand <- rexp(n,lam)
  means <- c(means,mean(rand))
  vars <- c(vars,var(rand))
}

By central limit theorem, the sample means "mu" should be normally distributed.

The application

Using the Shiny App, you can vary nsim and \(\lambda\) to see the central limit theorem in action. The app can be accessed from the Central Limit Theorem App

An example result is shown for nsim = 1000, n = 50 and \(\lambda = 0.2\). The plot below shows the distribution of the sample means (histogram) and the red curve is the standard normal variate:

\[Z=\frac{X_{\rm means} - \mu}{\sigma/\sqrt{n}}\]

plot of chunk unnamed-chunk-4