In this project we want to ilustrate the validity of the Central Limit Theorem. This theorem has an important role in statistical theory as it states that the distributions of the means of a large number of observations will be normal ragardless of the true underlying distribution. In fact, the existence of this theorem ensures the good results of many statistical procedures. To ilustrate this, here we will extract 1000 values from 40 generated exponential distributions, we will calculate the corresponding mean values and we will show that the distributions of this 40 means is indeed normally distributed.
A Poisson process describes the occurences of events in time. In general we count the events and the time points at which they happen. The time intervals between each pair of events follows an exponential distribution. Mathematically: \(P(x)=\lambda*exp(-\lambda*x)\) for \(x>0\). where \(\lambda\) is the rate parameter and represents the expected (theoretical) number of events that occur per unit of time; therefore, the expected mean time for the occurrence of an event is \(1/\lambda\) and its expected variance is \(1/\lambda^2\). In this exercice we used the simplest asumption: \(\lambda\) is constant, but in general \(\lambda\) can be a deterministic or stochastic function of time.
# Input parameters
Nsim = 1000 #number of simulations
Nexp = 40 # exponential distributions per simulation
lambda = 0.2 #rate parameter
mValues = NULL #values of the calculated means
# Simulations
for (i in 1 : Nsim) {
set.seed(999*i)
sim<-rexp(Nexp,lambda) #R function for the exponential distribution
mValues<-c(mValues,mean(sim))
}
Now we can compare the values of the expected mean for the exponential distribution \(1/\lambda\) and the average of the mean values obtained in our simulations:
# Expected value for the mean of an exponential distribution
1/lambda
## [1] 5
# Average of the means obtained by simulations
mean(mValues)
## [1] 4.974445
# Expected (theoretical) value of the variance for the exponential distribution
((1/lambda)/sqrt(Nexp))^2
## [1] 0.625
# Variance calculated from the sampled simulated distributions of the mean
var(mValues)
## [1] 0.6296492
As we can see the theoretical mean and variances and similar to their corresponding sample-estimated values. In the next section we will graphically show that the simulated distribution of the mean values generated from exponential distributions follows indeed a normaldistribution.
In the next figure we show an example of the exponential distribution extracted with values extracted from the R function rexp and a plot of the theoretical density of the poisson distribution.
#Creating an exponential distribution from scratch.
x<-seq(0,40,by=0.1)
p<-lambda*exp(-lambda*x)
#two pannel figure
par(mfrow=c(1,2), tcl=-0.5, family="serif", omi=c(0.2,0.2,0,0))
hist(rexp(1000,lambda),breaks=40,freq=TRUE,xlab="Values extracted from rexp",ylab="Frequency",main="Histogram")
plot(x,p,type="l",xlab="x",ylab="Density",main="Exponential distribution")
In the next figure we show the correspondence between the simulation estimated mean and the expected (theoretical) value for the mean of this distribution. Therefore, even when the generating distribution is exponential as shown in the previous figure, the distribution of the means of samples taken from the exponential distribution follows a normal distribution and the average of these means is fairly close to the theoretical mean of the exponential distribution.