The exponential distribution in R is investigated and compared with the Central Limit Theorem. The exponential distribution is simulated in R with rexp(n, lambda) where lambda is the rate parameter. The mean of exponential distribution is 1/lambda and the standard deviation is also 1/lambda. Lambda = 0.2 is set for all of the simulations. The distribution of averages of 40 exponentials is investigated.

This short report is written to do the following:

  1. Show the sample mean and compare it to the theoretical mean of the distribution.

  2. Show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution.

  3. Show that the distribution is approximately normal.

Simulations

  1. Comparison between sample mean and theoretical mean distribution
lambda = 0.2
n = 40
nsims = 1:1000
set.seed(1)
mns = NULL
for(i in nsims){mns = c(mns, mean(rexp(n, lambda)))}
hist(mns, main = "1000 averages of 40 random uniform", cex.main = 0.7)
abline(v = mean(mns), col = "green", lty = 2)
abline(v = 5, col = "red")
legend(6, 250, c("Sample Mean", "Theoretical Mean"), lty = c(1,2), lwd = c(1,1), col = c("green","red"), cex = 0.5)

mean(mns)
## [1] 4.990025
  1. Comparison between sample mean and theoretical mean variance
hist(mns, main = "1000 averages of 40 random variables", xlab = "Mean Averages", cex.main = .7)
abline(v = mean(mns), col = "green")
abline(v = mean(mns) + sd(mns), col = "red", lwd = 2.5, lty = 2)
abline(v = mean(mns) - sd(mns), col = "red", lwd = 2.5, lty = 2)

abline(v = mean(mns) + sqrt(5^2/40), col = "blue", lwd = 2.5)
abline(v = mean(mns) - sqrt(5^2/40), col = "blue", lwd = 2.5)

legend(6, 250, c("Sample mean", "Sample SD", "Theoretical SD"), lty=c(1,1,2), lwd= c(1,1,1), col = c("green", "blue", "red"), cex = 0.5)

  1. See if the distribution is normal
par(mfrow = c(2,2))
dist <- rexp(1000, rate = lambda)
hist(dist, main = "1000 random variables", cex.main = 0.9)
abline(v = mean(dist), col = "blue", lty = 2)
abline(v = 1/lambda, col = "red")
legend(6, 550, c("Sample mean","Theoretical mean"), col = c("blue","red"), lty = c(1,1), lwd = c(1,1), cex = 0.8)

hist(mns, main = "1000 averages of 40 random uniform", cex.main = 0.9)
abline(v = mean(mns), col = "blue", lty = 2)
abline(v = 1/lambda, col = "red")
legend(5.5, 200, c("Sample mean","Theoretical mean"), col = c("blue","red"), lty = c(1,2), lwd = c(1,1), cex = 0.8)

qqnorm(mns)
qqline(mns, col = 2)

From the Q-Q plot, the linearity of the points suggets that the distribution is normal.