Overview:

This report will step through a simulation exercise involving a exponential distribution where we will run the distribution through 1000 simulations and then explore the results and discuss their implications.

Simulations:

First, we simulate the exponential distribution (with rexp(n,lambda)) 1000 times.

Notes: -All simulations use lambda = 0.2 (as per instruction).

    -set.seed(12345) is present for all simulations.
    
    
    

Below is the code used:

Part 1 - We create 1000 instances of the exponential distribution with parameters (n=40 and lambda=0.2).

Part 2 - We then take the mean of each of these 1000 instances and plot them with their resulting mean.

Part 3 - We then take the mean of each of these 1000 instances and plot them with their resulting mean.

lambda<-0.2
n<-40

my_dist<-rexp(n,lambda)
mean_my_dist<-mean(my_dist)

# Part 1
my_sim = NULL
for(i in 1 : 1000) my_sim = c(my_sim,mean(rexp(n,lambda)))

#Part 2
mean_my_sim<-mean(my_sim)

my_sim2 = NULL
for(i in 1 : 1000) my_sim2 = c(my_sim2,sd(rexp(n,lambda)))

#Part 3
sd_my_sim2<-mean(my_sim2)

We now plot the simulation results and draw some conclusions from the results.

First, one instance of the distribution with sample and theoretical mean plotted

#Plot mean from distribution and also the mean from the theoretical

hist(my_dist,main="Exponential Distribution: Distribution values histogram")

abline(v=5,col="red")
abline(v=mean_my_dist,col="blue")

legend("topright", c("Theoretical Mean = 5",paste("Distribution Mean = ",mean_my_dist)), 
       col = c("red", "blue"),
       pch = c(19, 19), cex = 0.8, 
       box.col = "darkgreen"
       )

Second, we plot the mean of each of the 1000 simulations with their resulting mean also along with the theoretical mean.

#Plot mean from the simulation and also the mean from the theoretical

hist(my_sim,main="Exponential Distribution: Simulation values histogram")
    
  
abline(v=5,col="red")
abline(v=mean_my_sim,col="blue")

legend("topright", c("Theoretical Mean = 5",paste("Sample Mean = ",mean_my_sim)), 
       col = c("red", "blue"),
       pch = c(19, 19), cex = 0.8, 
       box.col = "darkgreen"
       )

Third, we plot the standard deviation of each of the 1000 simulations with their resulting mean also along with the theoretical standard deviation.

#Plot mean of sd values from the simulation values and also the mean from the theoretical

hist(my_sim2,main="Exponential Distribution: Mean Standard Deviation of simulation values histogram")

abline(v=5,col="red")
abline(v=sd_my_sim2,col="blue")

legend("topright", c("Theoretical Mean = 5",paste("Distribution Mean = ",sd_my_sim2)), 
       col = c("red", "blue"),
       pch = c(19, 19), cex = 0.8, 
       box.col = "darkgreen"
       )

Sample mean vs theoretical mean:

The theoretical mean of the exponential distribution is 1/lambda, which is 1/0.2 = 5

The sample mean of the simulation = 4.9705397 is close to the theoretical 5

Sample variance vs theoretical variance:

The theoretical standard deviation is also 1/lambda, which is 1/0.2 = 5

The sample standard deviation of the simulation = 4.9304115 is close to the theoretical 5

Distribution:

Show that the distribution is approximately normal.

We plot our simulations result against a standard normal result (both are as % of total observations (not frequency counts)).

#Plot mean of sd values from the simulation values and also the mean from the theoretical

hist(my_sim2,main="Exponential Distribution: Mean Standard Deviation of simulation values histogram",freq=FALSE)

abline(v=5,col="red")
abline(v=sd_my_sim2,col="blue")

legend("topright", c("Theoretical Mean = 5",paste("Distribution Mean = ",sd_my_sim2),"Normal Distribution"), 
       col = c("red", "blue","green"),
       pch = c(19, 19), cex = 0.8, 
       box.col = "darkgreen"
       )


curve(dnorm(x,mean=5,sd=1),0,10,add=TRUE,col="green")