This report is focused on the investigation of the exponential distribution in R and its comparison with the Central Limit Theorem.
Lambda is set to be 0.2 for all the simulations. I will investigate the distribution of averages of 40 exponentials with 1000 simulations.
The distribution of averages of 40 exponentials after 1000 simulations will be like:
setwd("~/Desktop/coursera/Statistical Inference")
mns<- NULL
for (i in 1:1000){
mns<- c(mns, mean(rexp(40, .2)))
}
hist(mns, col = "light blue", main = "The distribution of averages of 40 samples after 1000 simulation", cex.main = 0.7)
The sample mean is:
mean(mns)
## [1] 4.968554
The theoretical mean of the distribution is:
1/.2
## [1] 5
To show the sample mean and the theoretical mean of the distribution on the plot: The sample mean is marked by a red vertical line and the theoretical mean of the distribution is marked by a green vertical line
hist(mns, main = "The distribution of averages of 40 samples after 1000 simulation")
abline(v = mean(mns), col = "red", lwd = 2)
abline(v = 1/.2, col = "green", lwd = 2)
From the figure we can see that the sample mean is 4.99 and the theoretical mean of distribution is 5. These two are very close.
To compare the sample variance and the theoretical variance of the exponential distribution: The sample variance is:
sd(mns)
## [1] 0.773427
The theoretical variance of the exponential distribution is:
1/.2
## [1] 5
From the results we can see that the variance of the sample is much smaller than the theoretical variance of the exponential distribution.
To show that the sample distribution is approximately normal compared to the original exponential distribution:
par(mfrow = c(1,2))
hist(rexp(1000, .2), main = "The distribution of 1000 random exponentials", cex.main = .6)
hist(mns, main = "The distribution of 1000 averages of 40 random exponentials", cex.main = .6)
From the figures above we can see that the distributions of the sample averages and the original exponentials are different, and the distribution of the sample averages is approximately normal.