In this project you will investigate the exponential distribution in R and compare it with the Central Limit Theorem. The exponential distribution can be 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. Set lambda = 0.2 for all of the simulations. You will investigate the distribution of averages of 40 exponentials. Note that you will need to do a thousand simulations.

Illustrate via simulation and associated explanatory text the properties of the distribution of the mean of 40 exponentials. You should 1. Show the sample mean and compare it to the theoretical mean of the distribution.

lambda <- 0.2
n <- 100
nSimulations <- 1:1000
set.seed(20)
sampleMeans <- data.frame(x=sapply(nSimulations, function(x) {
  mean(rexp(n, lambda))
}))
summary(sampleMeans)
##        x        
##  Min.   :3.447  
##  1st Qu.:4.630  
##  Median :4.954  
##  Mean   :4.984  
##  3rd Qu.:5.314  
##  Max.   :6.587
mu <- mean(sampleMeans$x)
mu
## [1] 4.983641
standDev <- sd(sampleMeans$x)
standDev
## [1] 0.4915754

Expected Standard Deviation:

(1/lambda)/sqrt(n)
## [1] 0.5
  1. Show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution.
var(sampleMeans$x)
## [1] 0.2416464

Expected Variance:

((1/lambda)/sqrt(n)^2)
## [1] 0.05
  1. Show that the distribution is approximately normal.
library(ggplot2)
ggplot(data = sampleMeans, aes(x = x)) + geom_histogram(aes(y = ..density..), fill = I("blue"), 
    binwidth = 0.1, color = I("black")) + stat_function(fun = dnorm, arg = list(mean = 5, 
    sd = sd(sampleMeans$x)))

confidence <- mean(sampleMeans$x) + c(-1, 1) * 1.96 * sd(sampleMeans$x)/sqrt(nrow(sampleMeans))
(confidence[1]/confidence[2])*100
## [1] 98.7847