In this project, we investigate using simulations, exponential distribution in R and compare it with Central Limit Theorem.

We simulate the exponential distribution using the r function ‘rexp(n,rate)’, where n is the sample size. For the given experiment, the rate or lamda is set at 0.2. We run the simulation 1000 times using the function replicate.

Sample Mean vs. Theoretical Mean

samp_size<- 40
lambda <-0.2
exp<-replicate(1000,mean(rexp(samp_size,lambda))) #experimental data
samp_mean<-mean(exp) #sample mean
theo_mean<-1/lambda #theoretical mean

We can see, the sample mean = 5.0338213 is very close to the theoretical mean = 5

We now plot the distribution of sample mean. The red line indicates the theoretical mean calculated using: \[\frac{1}{\lambda}=\frac{1}{0.2}=5\]

hist(exp, main = "Histogram of Sample Means", col = "lightblue", xlab="Sample Mean")
abline(v=5,col="red",lwd = 3)

Sample Variance vs. Theoretical Variance

Sample variance is calculated using R function var(). Whereas, we calculate theoretical variance using the relation: \[\frac{\frac{1}{\lambda^2}}{samplesize}\]

samp_var<-var(exp) #sample variance
theo_var<-((1/lambda)^2)/samp_size #theoretical variance
# hist(exp, breaks=10, freq=F, main = "Histogram of Sample Means", col = "lightblue", xlab="Sample Mean")
# curve(dnorm(x, mean=5, sd=sqrt(25/40)), add=TRUE, col = "red", lwd = 3)

Again we observe, the sample variance = 0.6140004 is similar to the theoretical variance = 0.625

Distribution

Further, to validate the distribution we plot random normal distrubution of thoretical mean and compare it with distribution of sample means.

theor_dist<-rnorm(exp,mean = theo_mean,sd=(theo_var)^0.5)
par(mfrow=c(1,2))
hist(theor_dist,main = "Dist. of Theoretical Means", col = "green", xlab="Theoretical Mean")
hist(exp,main = "Dist. of Sample Means", col = "blue", xlab="Sample Mean")

From the above plot, we can say that the distribution of sample mean and normal distribution of theoretical mean looks similar.

Since the distribution of sample means resembles a normal distribution, we can say the results comply with the central limit theorem.