In this report I will investigate the exponential distribution in R and compare it with the Central Limit Theorem.
I will investigate the distribution of averages of 40 exponentials.
I will compare the distribution of 1000 random uniforms.
I will wet lambda = 0.2 for all of the simulations.
set.seed(25082502)
lambda = 0.2 ## Set lambda as per instructions
n_dist = 40
n_sim = 1000
d = data.frame(mean=numeric())
for (i in 1:n_sim){
sample = rexp(n_dist, lambda)
d[i,1] = mean(sample)
}
Below we have the sample mean and the mean of exponential distribuition
mean(d$mean) #sample mean
## [1] 4.988568
1/lambda #mean of exponential distribution
## [1] 5
Comparing the sample mean and the mean of exponential distribuition, we see that the sample mean of the distribution is close to the center of the distribution.
hist(d$mean,xlab = "mean", main = "Comparing Sample and Theoretical means")
abline(v=mean(d$mean), col = "blue")
abline(v=1/lambda, col = "red")
The theoretical variance of the distribution is ??2/n
Comparing the sample variance and the theoretical variance, we see that the sample variance is close to the theoretical variance.
var(d$mean) #Sample Variance
## [1] 0.6081224
(1/lambda)^2/n_dist #Theoretical Variance
## [1] 0.625
Below, we see the distribution is bell-shaped and resemble the normal distribution.
hist(d$mean,xlab = "mean", prob = T, main = "Comparing the Simulation with Theoretical Distribuition")
lines(density(d$mean))
abline(v=1/lambda, col='red', lwd=1)
xfit <- seq(min(d$mean), max(d$mean), length=100)
yfit <- dnorm(xfit, mean=1/lambda, sd=(1/lambda/sqrt(n_dist)))
lines(xfit, yfit, pch=22, col="red", lty=1)
legend('topright', c("Simulation", "Theoretical"),
col=c("black", "red"), lty=c(1,1))
The results of the sample are close to the results of the distribution, as we have seen in the results and plots above. In conclusion, the normal distribution of the mean of 40 random exponentials is consistent with the characteristic of the Central Limit Theorem.