q: 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 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. …

  1. Show where the distribution is centered at and compare it to the theoretical center of the distribution.
x<-NULL;n<-1000;lambda<-0.2;n<-40;times<-1000;
for(i in 1:times)
{
  x <- c(x, mean(rexp(n,lambda)))
}
hist(x)

plot of chunk unnamed-chunk-1

  1. Show how variable it is and compare it to the theoretical variance of the distribution.
S<-var(x)
S2<-1/(0.2^2)/40
  1. Show that the distribution is approximately normal.
d<-density(x)
plot(d)

plot of chunk unnamed-chunk-3

  1. Evaluate the coverage of the confidence interval for 1/lambda: \[\hat X \pm 1.96 \frac{S}{\sqrt{n}}\] .
ci<-NULL
ci<-c(mean(x)-1.96*S^(1/2)/n^(1/2))
ci<-c(ci,(mean(x)+1.96*S^(1/2)/n^(1/2)))
ci
## [1] 4.795 5.281