By Megan Williams
Description 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 distributio n is 1/lambda and the standard deviation is also also 1/lambda. Set lambda = 0.2 for all of the simulations. In this simulation, you will investigate the distribution of averages of 40 exponential(0.2)s. Note that you will need to do a thousand or so simulated averages of 40 exponentials. Illustrate via simulation and associated explanatory text the properties of the distribution of the mean of 40 exponential(0.2)s.
Questions 1 (show where the distribution is centered at and compare it to the theoretical center of the distribution) & 2 (show how variable it is and compare it to the theoretical variance of the distribution)
Lambda = 0.2
n = 40
nSims = 1:1000
set.seed(820)
Means <- data.frame(x = sapply(nSims, function(x) {
mean(rexp(n, Lambda))
}))
head(Means)
## x
## 1 5.750
## 2 3.808
## 3 4.058
## 4 3.999
## 5 4.313
## 6 4.418
m = mean(Means$x)
m
## [1] 4.999
sd = sd(Means$x)
sd
## [1] 0.7909
Expected standard deviation
(1/Lambda)/sqrt(40)
## [1] 0.7906
Variance of simulations
var(Means$x)
## [1] 0.6256
Expected Variance
((1/Lambda)/sqrt(40))^2
## [1] 0.625
Solutions:
-1.The expected center (5.0) is very close to the center of the distribution (4.9988).
-2.The standard deviation (0.7909) is also close to the expected standard deviation (0.79056).
Question 3 (show that the distribution is approximately normal)
library(ggplot2)
ggplot(data = Means, aes(x = x)) + geom_histogram(aes(y = ..density..), fill = I("darkolivegreen3"),
binwidth = 0.2, color = I("black")) + stat_function(fun = dnorm, arg = list(mean = 5,
sd = sd(Means$x)))
Solution:
-3. The histogram plot depicts a distribution that is approximately normal (mean = 5; sd = .7909).
Question 4 (evaluate the coverage of the confidence interval for 1/lambda: X¯±1.96Sn√)
mean(Means$x) + c(-1, 1) * 1.96 * sd(Means$x)/sqrt(nrow(Means))
## [1] 4.950 5.048
Solution:
-4. The 95% confidence interval for the mean of the means is 4.950 - 5.047.