set.seed(1337)
lambda <- 0.2
ExpotentialCount <- 40
mns <- NULL
for(i in 1:1000) {
mns <- c(mns, mean(rexp(ExpotentialCount, lambda)))
}
Sample_Mean <- mean(mns)
Sample_Mean
## [1] 5.055995
Theoritical_Mean <- lambda^-1
Theoritical_Mean
## [1] 5
MeanDiff <- abs(Sample_Mean - Theoritical_Mean)
paste("There is a difference of ", round(MeanDiff, digits = 5), " beteween Sample Mean and Theoritical Mean", sep ="")
## [1] "There is a difference of 0.056 beteween Sample Mean and Theoritical Mean"
Sample_Variance <- var(mns)
Sample_Variance
## [1] 0.6543703
Theoritical_Variance <- (lambda * sqrt(ExpotentialCount))^-2
Theoritical_Variance
## [1] 0.625
VarianceDiff <- abs(Sample_Variance - Theoritical_Variance)
paste("There is a difference of ", round(VarianceDiff, digits = 5), " beteween Sample Variance and Theoritical Variance", sep ="")
## [1] "There is a difference of 0.02937 beteween Sample Variance and Theoritical Variance"
The following histogram shows 1000 simulations of 40 exponentially distributed variables. We added a normal distribution line as well as the sample and theoritical means. As per the char we can conclude that the distribution is approximately normal.
Chart <- hist(mns, freq = F, breaks=20, col="white",
xlab="1000 means of 40 exponentials in 20 breaks",
main="1000 averages of 40 exponentially distributed variables")
abline(v=mean(mns), col="red") # mean of sample means
x <- seq(min(mns),max(mns),length=50)
y <- dnorm(x, mean=1/lambda, sd=(1/lambda)/sqrt(ExpotentialCount))
lines(x, y, col="blue", lwd=1)
abline(v=1/lambda, col="green")