Overview

The report includes investigation of the exponential function in R rexp(n, lambda) and how it compares to the Central Limit Theorem.
Here,

Simulations

Facts about the exponential distribution

  • Mean = 1 / lambda
  • Standard Deviation = 1 / lambda

Data considered for the simulation

  • lamda = 0.2
  • Number of exponentials (n) = 40
  • Number of simulations = 1000

Working

Lets see what the function rexp returns in detail.

set.seed(2)
n <- 40
lambda <- 0.2
exp <- rexp(n, lambda)
head(exp)
## [1] 9.3267622 2.0237404 0.7332633 8.6535486 0.4476309 3.3344882
sum(exp < 0)
## [1] 0
range(exp)
## [1]  0.01969881 24.31107653

The function does look like an exponential distribution as there are no negative values.

To perform 1000 simulations, the for loop is used where the variable mns is concatenated with the mean of every new simulation.

set.seed(2)
mns = NULL
for (i in 1 : 1000) mns = c(mns, mean(rexp(n, lambda)))
hist(mns,breaks=20, main="Simulated means of Exponential Distribution", xlab="Means", col="lightblue")

Question 1 : Sample Mean versus Theoretical Mean

The mean of the exponential distribution is given as 1 / lambda. Lets calculate both the theoretical and sampled means.

# Theoretical Mean--
theoretical.mean <- 1 / lambda

# Sampled Mean-- 
sampled.mean <- mean(mns)

# plotting the two means 
hist(mns,breaks=20, main="Sampled Mean vs Theoretical Mean", xlab="Means", col="lightblue")
abline(v=sampled.mean, lwd="2", col="blue")
abline(v=theoretical.mean, lwd="2", col="red")
legend("topright", legend=c("Theoretical Mean", "Sampled Mean"), col=c("red", "blue"), lty=c(1,1))

As we see in the figure above, the theoretical mean and sampled mean are almost equal with their values being 5 and 5.0163562 respectively.

Question 2 : Sample Variance versus Theoretical Variance

The standard deviation is 1/lambda.
After simulations, the standard error is 1/ lambda/sqrt(n).
So the variance will be square of that value.
Lets calculate the theoretical and sampled variance.

# theoretical variance-- 
theoretical.var <- ((1/lambda)/sqrt(n))^2

# sampeld variance-- 
sampled.var <- round(var(mns), 3)

The theoretical variance has the value of 0.625 and the sample variance has a value of 0.669. As we can see, these values are pretty close too.

Question 3 : Distribution

We investigate whether the exponential distribution follows normal distribution according to the Central Limit Theorem.

# Plotting the Expected value curve
hist(mns,breaks=20, main="Simulation of Expected Values", xlab="Means", col="darkslategrey", prob=TRUE)

# Plotting the line curve for the exponential distribution
lines(density(mns), lwd=2, col="violet")

# plotting the line curve for a normal distribution 
x <- seq(min(mns), max(mns), length = n)
y <- dnorm(x, mean= theoretical.mean, sd = sqrt(theoretical.var))
lines(x,y,lwd =2, col="orange")

legend("topright", legend=c("Exponential", "Normal"), title = "Distribution", col=c("violet", "orange"), lty=c(1,1))

As we can see from the above graph, the exponential very closely resembles a normal distribution. It can be inferred that on increasing the number of simulations, the distribution would more closely resemble a normal distribution.