Overview:

A simulation exercise will be performed to investigate the means and variances of 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.

1.Sample Mean versus Theoretical Mean.Show the sample mean and compare it to the theoretical mean of the distribution.

The following code will run a simulation of 1000 caculations for the means of exponential distributions of 40 observations.

#Provided data for this exercise
lambda<-0.2
#expected mean
miu<-1/lambda # expected mean
sigma<-1/lambda # expected std dev
n<-40 # number of observations
nsim<-1000 # number of simulations

set.seed(1000)
exp_means=NULL
for (i in 1 : nsim) exp_means = c(exp_means, mean(rexp(n,lambda)))
sample_mean <- mean(exp_means)
hist(exp_means,main="Histogram of 1000 exponential distribution means",breaks=25)
abline(v = miu, col= 2, lwd = 2,lty=2)
abline(v = sample_mean, col= 3, lwd = 1)
legend('topright', c("Expected Mean", "Sample Mean"),
       lty= c(2,1),
        bty = "n", col = c(col = 2, col = 3))

As can be seen in the histogram the mean of the simulated exponential distribution is very approximate to the expected provided sample mean (Miu). The numbers below for the respecive means show their close proximity.

#Expected Mean
miu
## [1] 5
#Sample Mean
sample_mean
## [1] 4.986963

2.Sample Variance versus Theoretical Variance. The Theoratical variance is equal to the variance of the original population divided by the number of samples n. Var(X) = sigma^2/n.

#Expected Variance

lambda<-0.2

sigma <- 1/lambda # standard dev
expected_var <- sigma^2/n # expected variance
expected_var
## [1] 0.625
#Sample Variance
sample_var <- var(exp_means) # sample variance
sample_var
## [1] 0.654343
hist(exp_means,main="Exponential distribution for 1000 means",
     breaks=20,xlim=c(0,9))
abline(v = expected_var, col= 2, lwd = 2,lty=2)
abline(v = sample_var, col= 3, lwd = 1)
legend('topright', c("Expected Variance", "Sample Variance"), lty= c(2,1),bty = "n", col = c(col = 2, col = 3))

After comparing both variances 0.625 vs 0.654 we can conclude that the variances are almost equal.

3.Distribution:Show that the distribution is approximately normal.

The following chart depicts that the means of the sample exponential distribution are very approximate to the bell curve of the normal distribution.The simulation is done with 10,000 samples of 40 exponential random observations.

lambda <- 0.2
miu <- 1/lambda
sigma <- 1/lambda
n <-40
nsim=10000
for (i in 1 : nsim) exp_means = c(exp_means, mean(rexp(n,lambda)))
sample_mean <- mean(exp_means)

hist(exp_means, breaks = 50, prob = TRUE, 
     main = "Exponential Distrib Mean compared to Normal Distrib")
    xfit <- seq(min(exp_means), max(exp_means), length = 100)
    yfit <- dnorm(xfit, mean = miu, sd = (sigma/sqrt(40)))
    lines(xfit, yfit, pch = 22, col = "blue", lwd = 4)

Here is another way to compare the exponential means based on the t statistic of the Center Limit Theorem. The simulation is done with 10,000 samples.

lambda<-0.2
#sample mean
miu<-1/lambda
sigma<-1/lambda
n<-40
nsim<-10000


clt_means<-as.numeric(0)
for (sim in 1:nsim) {
  
  means<-rexp(n=n,rate=lambda)
  smean <- as.numeric(mean(means))
  clt <- (smean - miu)*qnorm(0.975)*(sigma/sqrt(n))
  clt_means[sim] <- clt
}
clt <- (smean - miu)*qnorm(0.975)*(sigma/sqrt(n))

hist(clt_means, col="green", freq=F,breaks=30,main="Exponential Distribution Means compared to Normal Distrib")
curve( dnorm(x,mean=(sample_mean-miu),sd=1.2),-3.5,4.5, add=T, col="blue",lw=4)

Based on the qqplot of exponential distribution compared to the normal distributions below, it is evident that the exponential distributions is very approximate or “follows” the standard normal distribution.

qqnorm(exp_means);qqline(exp_means)