Description/Overview of the Problem
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. Investigate the distribution of averages of 40 exponentials by doing a thousand simulations.
Question 1. Show the sample mean and compare it to the theoretical mean of the distribution;
AND
Question 2. Show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution.
Lambda = 0.2
n = 40
id = 1:1000
set.seed(900)
Sample_Means <- data.frame(x = sapply(id, function(x) {mean(rexp(n, Lambda))}))
head(Sample_Means,5)
## x
## 1 6.052102
## 2 4.935885
## 3 4.934792
## 4 5.322497
## 5 3.453807
Mean of Distributions
Mean_Of_Sample_Means = mean(Sample_Means$x)
Mean_Of_Sample_Means
## [1] 5.00007
Theoretical Mean
1/Lambda
## [1] 5
Standard Deviation of Simulations
sd = sd(Sample_Means$x)
sd
## [1] 0.7921167
Expected Standard Deviation (mean/ sqrt(n))
(1/Lambda)/sqrt(40)
## [1] 0.7905694
Variance of Simulations
var(Sample_Means$x)
## [1] 0.6274488
Expected Variance (mean/ sqrt(n))^2
((1/Lambda)/sqrt(40))^2
## [1] 0.625
#Plot the histogram of Averages
hist(Sample_Means$x, breaks=50, prob=TRUE,main="Distribution of averages of samples,
drawn from exponential distribution with lambda=0.2",
xlab="")
# Density of the Means of Samples
lines(density(Sample_Means$x))
# Theoretical center of distribution
abline(v=1/Lambda, col="red")
# Theoretical density of the averages of samples
xfit <- seq(min(Sample_Means$x), max(Sample_Means$x), length=100)
yfit <- dnorm(xfit, mean=1/Lambda, sd=(1/Lambda/sqrt(40)))
lines(xfit, yfit, pch=22, col="red", lty=2)
# Add Legend
legend('topright', c("simulation", "theoretical"), lty=c(1,2), col=c("black", "red"))
Solution 1: Theoretical Mean which is 5 (1/Lambda) is very close to the center of the distribution 5.00007 Solution 2: The standard deviation 0.7921167 is also close to the expected standard deviation which is 0.7905694 (1/Lambda)/sqrt(40)
Question 3. Show that the distribution is approximately normal.
Solution: The distribution is forming a bell curve and hence Gaussian in nature.
qqnorm(Sample_Means$x)
qqline(Sample_Means$x, col = 2)
The distribution of averages of 40 exponentials is very close to a normal distribution because of the Central Limit Thorem(CLT).