In this project you will investigate the exponential distribution in R and compare it with the Central Limit Theorem. 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. You will investigate the distribution of averages of 40 exponentials. Note that you will need to do a thousand simulations.
Illustrate via simulation and associated explanatory text the properties of the distribution of the mean of 40 exponentials. You should 1. Show the sample mean and compare it to the theoretical mean of the distribution. 2. Show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution. 3. Show that the distribution is approximately normal.
set.seed(123) # A set of any numbers
lambda <- 0.2 # Set lambda = 0.2 for all of the simulations
n <- 40 # distribution of averages of 40 exponentials
simulations <- 1000 # Note that you will need to do a thousand simulations.
# doStuff
simulations_done <- replicate(simulations, rexp(n, lambda))
means_exp <- apply(simulations_done, 2, mean)
mean_of_means_exp <- mean(means_exp)
lmbda_mean <- 1/lambda
hist(means_exp, xlab = "Mean", main = "Exponential Simulations", col = "black")
abline(v = mean_of_means_exp, col = "green")
abline(v = lmbda_mean, col = "red")
sd_dist <- sd(mean_of_means_exp)
sd_theory <- (1/lambda)/sqrt(n)
varianccia_dist <- sd_dist^2
varianccia_theory <- ((1/lambda)*(1/sqrt(n)))^2
# doStuff
simulations_done <- replicate(simulations, rexp(n, lambda))
means_exp <- apply(simulations_done, 2, mean)
mean_of_means_exp <- mean(means_exp)
lmbda_mean <- 1/lambda
x <- seq(min(means_exp), max(means_exp), length=100)
y <- dnorm(x, mean=1/lambda, sd=(1/lambda/sqrt(n)))
hist(means_exp,breaks=n,prob=T,col="red",xlab = "Means",main="Density X Means",ylab="Density")
lines(x, y, pch=20, col="black", lty=5)
qqnorm(means_exp)
qqline(means_exp, col = 2)