Overview

This project investigates the exponential distribution in R and compare it with the Central Limit Theorem. The experiment takes 1000 samples of 40 exponential ramdom values of exponential with lamda=0.2. There are 4 sections. In the first, the sample is generated. The second and the third compare the average and standard distribution of the 1000 samples with the theoretical mean and variance. Finally, the last section shows how the average of the 1000 mean of exponential distribution tends to Normal distribution.

Simulations

In this section the sample of 1000 exponentials of 40 values each with lambda=0.2 is generated

lambda<-0.2
n<-40
samples <- NULL
sim<-1000
for(i in 1:sim) samples = c(samples, rexp(n, lambda))
matsamples <- matrix(samples,sim, n)
avgdist<-apply(matsamples,1,mean)
sddist<-sd(avgdist)
#explore average mean
summary(avgdist)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.811   4.380   4.884   4.942   5.438   8.786

Sample Mean versus Theoretical Mean

In this section the mean of the 1000 exponentials of 40 values each with lambda=0.2 is compared with the theoritical mean. The result shows that they are very closed. The figure shows the sample mean in a black line. The theoretical mean is depicted with a red dotted line.

#The mean of the average of 1000 exponentials of size 40

mean(avgdist)
## [1] 4.942016
#Theorethical mean of exponential distribution
mean(1/lambda)
## [1] 5
hist(avgdist, breaks = 40, xlab = "Mean", main = "Distribution of 1000 Exponential Means", col = "cyan")
abline(v = mean(avgdist), col = "black",lwd=4)
abline(v = 1/lambda, col = "red",lwd=4,lty="dotted")

Sample Variance versus Theoretical Variance

In this section the sample variance and the theoretical variance are calculated and compared. Again, the values are very near.

sample_variance <- sddist^2
sample_variance
## [1] 0.6267653
theorical_variance <- ((1/lambda)/sqrt(n))^2
theorical_variance
## [1] 0.625

Normal Distribution tendency

This section depict the distribution of the 1000 averages compared to the normal distribution. The normal distribution is showed with dotted red lines. It can be observed how the distribution tends to Normal as Central Limit Theorem states,

hist(avgdist, breaks = 40, xlab = "Mean", main = "Comparition with Normal Distribution", col = "cyan")
x <- seq(min(avgdist), max(avgdist), length=sim)
y <- dnorm(x, mean=1/lambda, sd=(1/lambda/sqrt(n)))
lines(x, y*100, col="red", lwd=4,lty="dotted")