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.
Simuation of exponential distribution with following data in R with rexp(n, lambda),lambda = 0.2 and exponentials (n = 40) for thousand simulations.
Set Seed , size , lambda
set.seed(100)
n <- 40
lambda <- 0.2
Set No. of simulation according to samples of size 40 in thousand columns and 40 rows
simulations <- 1000
sim_exp <- replicate(simulations, rexp(n, lambda))
Calculate mean of each column
mean_sim_exp <- apply(sim_exp, MARGIN = 2, mean)
mean_analytical<-- mean(mean_sim_exp)
mean_analytical
Evaluation of first 10 mean of thousands simulation
head(mean_sim_exp, 10)
[1] 4.137412 6.051703 4.415869 4.404714 3.210413 5.475307 4.405938 6.573635 5.399291 [10] 4.913581
Sample_mean<-mean(mean_sim_exp)
Sample_mean
[1] 4.999702
mean_theory <- 1/lambda
mean_theory
[1] 5 #Histogram
hist(mean_sim_exp, xlab = "mean", main = "Exponential Simulations",col="green")
Showing sample mean
abline(v = Sample_mean, col = "red")
abline(v = mean_theory, col = "blue")
sd_sim_exp<-sd(sim_exp)
sterror_sim_exp<-sd(sim_exp)/sqrt(n)
sterror_sim_exp
[1] 0.7965831
qqnorm(mean_sim_exp)
qqline(mean_sim_exp, col = 2)
Distribultion of the central limit theorem is approximately close to 40 simulated exponentials