The averages of 1000 iid exponentials are simulated. The mean and variance of the average distribution are compared with the theoretical values, and the distribution is verified as normal.
According to the Central Limit Theorem, the averages of the 40 exponentials here are normally distributed with mean of 1/lamda=5. One thousand simulations of the mean of exponential variables are generated and plotted here.
# generate 1000 averages of the 40 exponentials
set.seed(10)
expMean<-replicate(1000,mean(rexp(40,0.2)))
hist(expMean, probability = 1, col = "green", xlab = "averages",
main = "The sample mean vs the distribution mean")
# add the sample mean
abline(v = round(mean(expMean),2), lwd = 4, lty = 3)
# add the theoretical mean
abline(v = 5, lwd = 4, lty = 3, col = "red")
legend("topright", legend = c("sample mean = 5.05", "theoretical mean = 5"),
col = c("black", "red"), lwd = 4, lty = 3)
The sample mean shown as black dash with a value of 5.05 is very close to the theoretical mean shown as red dash which is 5. This is exactly what the Central Limit Theorem expects.
# generate 1000 averages of the 40 exponentials
set.seed(10)
expMean<-replicate(1000,mean(rexp(40,0.2)))
hist(expMean, probability = 1, col = "green", xlab = "averages",
main = "The sample variance vs the distribution variance")
# add the sample mean and 1st variance line away from the sample mean
abline(v = round(mean(expMean),2), lwd = 4, lty = 3)
abline(v = round(mean(expMean),2)+round(var(expMean),2), lwd = 4, lty = 3, col = "red")
abline(v = round(mean(expMean),2)-round(var(expMean),2), lwd = 4, lty = 3, col = "red")
legend("topright", legend = c("sample mean", "The 1st variance from the sample mean"),
col = c("black", "red"), lwd = 4, lty = 3)
The variance from the simulation is 0.637, while the theoretical variance of the distribution is \[ \frac{(\sigma)^2}{n=40}=0.625 \]
They are very close to each other again. The slight difference should be from the finite size of our simulations.
# generate 1000 averages of the 40 exponentials
expMean<-replicate(1000,mean(rexp(40,0.2)))
hist(expMean, probability = 1, col = "green", xlab = "averages",
main = "The distribution of averages" )
# the theoretical normal distribution according to CLI
normDistribution<-function(x)dnorm(x,5,5/sqrt(40))
curve(normDistribution, 2, 8, add = TRUE, col = "red", lwd = 4)
As predicted by the Central Limit Theorem, the averages are approximately normally distributed with both the mean and variance close to the expected value. We can clearly see here our simulated results go along the bell curve.