knitr::opts_chunk$set(warning = FALSE, message = FALSE,echo = TRUE)
We will investigate the distribution of averages of 40 exponentials. Note that We have to do a thousand simulations.
set.seed(1)
lambda <- 0.2
n <- 40
simulations <- 1000
Exponentials <- replicate(simulations, rexp(n, rate = lambda))
ExponentialsMean <- apply(Exponentials, 2, mean)
AnalyticalMean <- mean(ExponentialsMean)
AnalyticalMean
## [1] 4.990025
TheoryMean <- 1/lambda
TheoryMean
## [1] 5
From the results we can see that mean of our simulated distribution is 4.990025 which is very close to the theoretical mean 1/lambda = 5
StandardDeviation <- sd(ExponentialsMean)
StandardDeviation
## [1] 0.7817394
Variance <- StandardDeviation^2
Variance
## [1] 0.6111165
TheoryStandardDeviation <- (1/lambda)/sqrt(n)
TheoryStandardDeviation
## [1] 0.7905694
TheoryVariance <- ((1/lambda)*(1/sqrt(n)))^2
TheoryVariance
## [1] 0.625
As we can see theyโre very close, 0.6111165 and 0.625, respectively.
hist(ExponentialsMean, xlab = "mean", main = "Exponential Simulations")
abline(v = AnalyticalMean, col = "red")
abline(v = TheoryMean, col = "blue")
Here we can see purple line because the ablines of theoritical mean and analytical mean coincides with each other as they are very close.
X <- seq(min(ExponentialsMean), max(ExponentialsMean), length.out = 200)
Y <- dnorm(X, mean = TheoryMean, sd = TheoryStandardDeviation)
hist(ExponentialsMean, breaks = n, prob = TRUE, col = "wheat", xlab = "Means",
main="Density of Means", ylab="Density")
lines(X, Y, col="black", lty=1)
abline(v = TheoryMean, col = "red")
TheoryCI<- TheoryMean + c(-1,1) * 1.96 * TheoryStandardDeviation/sqrt(n)
TheoryCI
## [1] 4.755 5.245
ActualCI<- AnalyticalMean + c(-1,1) * 1.96 * StandardDeviation/sqrt(n)
ActualCI
## [1] 4.747762 5.232289
From the plot we see that the normalized distribution of sample means is approximately the same as the standard normal distribution as we can see comparing it to the density function, the black bell-shaped curve. As confidence interval of distribution is (4.755 , 5.245) and the actual confidence interval is (4.747762 , 5.232289).This is consistent with what is stated in the Central Limit Theorem.