This analysis will investigate the exponential distribution in R and compare it with the Central Limit Theorem. We will simulate 1000 runs of the exponential distribution and compare sample results to population calculations to see how close they are to each other.
The simulation below will run 1000 random exponential distributions of 40 samples with lambda of 0.2. We will then take the mean of each distribution. With this simulation, we are hoping to approximate the mean of the true population.
n=40
lambda = 0.2
#simulation
mns = NULL
for (i in 1 : 1000) mns = c(mns, mean(rexp(n,lambda)))
This section will compare the population and sample means. As shown below, the population mean is 5, and the sample mean is very close to 5, with a very small difference between the population and sample means. The difference in means is due to a slightly different variance in the sample distribution. The close result, however, is expected from the Central Limit Theorem.
1/lambda
## [1] 5
mean(mns)
## [1] 4.992613
1/lambda - mean(mns)
## [1] 0.007387077
This section will explore the sample variance versus the theoretical variance. We would expect the variances to be close, but not exactly equal due to the randomness in the simulation.
popvar <- ((1/lambda)^2)/n
popvar
## [1] 0.625
sampvar <- var(mns)
sampvar
## [1] 0.6048352
popvar - sampvar
## [1] 0.02016475
This section will compare the distribution of one random distribution of n = 40 and lambda = 0.2 versus the mean of 1000 runs of the random distribution with the sample parameters. You can see the disribution of the means is approximately normally distributed, with an deven distribution around the mean on both sides, and a bell shaped curve.
hist(rexp(n, lambda), main="Histogram of One Simulation")
hist(mns, main="Histogram of the Mean of 1000 Simulations")