Overview:

The objective of this project is to investigate the exponential distribution in R and compare it with the Central Limit Theorem. To generate data for this simulation we will be using lambda = 0.2. The objectives are 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

n = 1000 
lambda <- 0.2
mns <- NULL
for(i in 1: n){
        mns <- c(mns, mean(rexp(40, lambda)))
}

Sample mean vs Theoretical mean

#Sample Mean
sammean <- mean(mns)
sammean
## [1] 5.017626
#Theoritical Mean
themean <- 1/lambda
themean
## [1] 5
g <- ggplot(data.frame(mns), aes(x = mns)) + 
        geom_histogram(aes(y=..density..), binwidth=.3, colour = "black", alpha = .20) + 
        labs(x = "Mean", y = "Value", title = "Exponential Means Distribution n = 1000")
g + geom_vline(xintercept = sammean, color = "red", size = 1) + labs(title = "Exponential Means Distribution with sample mean")

g + geom_vline(xintercept = themean, color = "blue", size = 1) + labs(title = "Exponential Means Distribution with theoritical mean")

Sample Variance vs Theoretical Variance

#Sample standard deviation
samvar <- var(mns)
samvar
## [1] 0.6338725
#Theoritical standard deviation
thevar <- ((1/lambda)/sqrt(40))^2
thevar
## [1] 0.625

Distribution

#Plotting the histogram of mean values of 40 random exponential 
g <- ggplot(data.frame(mns), aes(x = mns)) + 
        geom_histogram(aes(y=..density..), binwidth=.3, colour = "black", alpha = .20) + 
        labs(x = "Mean", y = "Value", title = "Distribution of Random Exponential Means") +
        stat_function(fun = dnorm, arg = list(mean = mean(mns), sd = sd(mns)))
g