This report aims to investigate the exponential distribution in R and compare it with the Central Limit Theorem.

The exponential distribution can be simulated in R using rexp(n,\(\lambda\)) where n is the sample size and \(\lambda\) is the rate parameter. The mean of exponential distribution is \(1/\lambda\) and the varaince is \(1/\lambda^2\). It performs 1000 simulations to investigate the distribution of averages of 40 exponentials.For the purpose of this investigation the rate parameter is set to \(\lambda = 0.2\) for all of the simulations.

Before beginning of our investigation, we need to generate the distrubtion and save it so that we can use it for our analysis throughout the report. We first set our parameters n and \(\lambda\) and then use R’s rexp function to simulate the generation of the distribution 1000 times and save the mean of the distribution for each simulation.

lambda <- 0.2
n <- 40
data = NULL
for(i in 1:1000) data = c(data,mean(rexp(n,lambda)))

Question 1. Comparing the sample mean and theoretical mean of the distribution.

As we already have the dataset containing the means from 1000 simulation, all we need to do is find the average of these means to evaluate our sample mean.

sampleMean <- mean(data)

Hence our sample mean is 4.9911.

Now to find the theoretical mean, we have to make certain assumptions. We assume that the each simulation is independent and we can safely assume that it has the same parameters and hence are identical. So the theoretical mean is evaluated using the expression \(1/\lambda\).

theoreticalMean <- 1/lambda

Hence our theoretical mean is 5. So we can see that the sample mean is very close to the theoretical mean.

Question 2. Comparing the sample variance and the theoretical variance of the distribution.

As we already have the dataset containing the means from 1000 simulation, all we need to do is find the variance of these means to evaluate our sample variance.

sampleVariance <- var(data)

Hence our sample variance is 0.5992.

Working under the same assumptions, we made under question 1 to calculate the theoretical mean, the theoretical varaince can be evaluated by the expression \((1/\lambda^2)/n\).

theoreticalVariance <- (1/(lambda^2))/n

Hence our theoretical variance is 0.625. So we can see that the sample varaince is very close to the theoretical varaince.

Question 3. Showing that the distribution is apporximately normal

We need to plot the histogram of the dataset of the means to see what the distribution of the mean is.

hist(data)

plot of chunk unnamed-chunk-6

We notice that the distribution looks approximately normal and thus the distrbution of the sample means follows the Central Limit Theorem.