library(knitr)

library(ggplot2)

Over view :

In this project we will investigate the exponential distribution in R and compare it with the Central Limit Theorem.

Simulations:

Creating 1000 simulations, each consisting of 40 exponentials

lambda<-0.2
samples<-40
sims<-1000

Execute the simulations

simExp<-replicate(sims, rexp(samples, lambda))

# Calculate the means of the exponential simulations

simMean<-apply(simExp, 2, mean)

# Creating histogram for the simulations

hist(simMean, breaks=20, main="Simulation means", col="green")

Task 1: Show the sample mean and compare it to the theoretical mean

sampleMean<-mean(simMean)

print(sampleMean)
## [1] 4.9539
theoreticalMean<-1/lambda

print(theoreticalMean)
## [1] 5
## Creating plot for the comparision of sample mean and theoretical mean

hist(simMean, col="darkblue", main="Sample Mean Vs Theoretical Mean",
breaks=20, xlab="Simulation means")

abline(v=theoreticalMean, lwd="5", col="green")

legend("topright", legend="Theoretical mean", box.lwd=0,box.col="white", col="green", pch=15)

Task 2: Comparing the sample variance to the theoretical variance of the distribution

sampleVar<- var(simMean)

print(sampleVar)
## [1] 0.6006456
theoreticalVar<-(1/lambda)^2/samples

print(theoreticalVar)
## [1] 0.625

Here we concluded that, from Task:1 and Task:2, the simulated values are nearly equal to theoretical values of the distribution

Task 3: Show that the distribution is approximately Normal.

hist(simMean, prob=TRUE, col="green", breaks=20,
 xlab="Simulation means", main="Normal approximation")

# Creating curve for normal distribution approximation

curve( dnorm(x, mean=sampleMean, sd=sd(simMean)), add=TRUE, col="blue", lwd=4)