This project investigates the mean of the exponential distribution and tests this against the Central Limit Theorem. The exponential distribution is simulated and the distribution of the mean of 40 samples is shown to be normal.
The exponential distibution is created with a lambda of 0.2 for all the following simulations.
First we simulate taking the mean of 40 samples 1000 times:
library(lattice)
num_sims <- 1000
lambda <- 0.2
num_samples = 40
means<-NULL
for (i in 1 : num_sims) means <- c(means, mean(rexp(num_samples, lambda)))
And next the variance of 40 samples, again 1000 times:
vars<-NULL
for (i in 1 : num_sims) vars <- c(vars, var(rexp(num_samples, lambda)))
The mean of the exponential distribution is 1/lambda. We chose 0.2 as lambda therefore the theoretical mean is 5.
From a histogram of the simulated means we can see the average mean is approximately 5.
histogram(means)
The average for our simulation is in fact 4.9652709.
The Central Limit Theorem states that this will converge to 5 as the number of samples and number simulations is increased.
The variance of the exponential distribution is (1/lambda squared). We chose 0.2 as lambda therefore the theoretical variance is 25.
From a histogram of the simulated variance we can see the average variance is approximately 25.
histogram(vars)
The average for our simulation is in fact 24.9947884.
The Central Limit Theorem states that this will converge to 25 as the number of samples and number simulations is increased.
To compare our simulated distribution of means to the normal distribution we can overlay a normal distribution on the historgram of means.
The standard deviation of the sample mean is given by the standard deviation divided by the number of samples.
Using this we calculate that the mean of the distributon of means is 5 and the standard deviation of the distribution of means is 0.7905694.
x <- seq(2,8,length=200)
y <- dnorm(x,mean=1/lambda, sd=(1/lambda) / sqrt(num_samples))
hist(means, main='Histogram of means of simulated sets of samples from\n an exponential disribution overlayed with the normal\n distribution for the expected mean and standard deviation')
lines(x,y*500)
Overlaying a normal distribution with mean = 5 and sd = 0.7905694 shows that our simulated means are normally distributed.