Summary

In this project the exponential distribution in R is investigated and compared with the Central Limit Theorem. The exponential distribution can be simulated with rexp(n,lambda) command, where lambda is the rate parameter. Both the mean and the standard deviation of exponential distribution is 1/lambda.

The simulation confirms that sample distribution tends towards the theoretical distribution, as proposed by the Central Limit Theorm.

Simulations

A thousand simulations are performed. The value for lambda is set at 0.2 and the distribution of means of 40 exponentials are investigated.

The simulations (1) compare the sample mean with the theoretical mean of the distribution, (2) show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution, and (3) show that the distribution is approximately normal.

Question 1: Compare the sample mean with the theoretical mean of the distribution

Set seed for reproducability.

set.seed(1813)

Set lambda, the number of exponentials, and the number of simulations.

lambda <- 0.2
n <- 40
n.sim <- 1000

Perform 1000 simulations and calculate the means.

sim.runs <- replicate(n.sim, rexp(n,lambda))
mean.runs <- colMeans(sim.runs)

Compare the sample mean with the theoretical mean.

sample.mean <- mean(mean.runs)

Print the sample mean.

print(sample.mean)
## [1] 4.988505

Print the theoretical mean.

theoretical.mean <- 1/lambda

Print the theoretical mean.

print(theoretical.mean)
## [1] 5

Plot the simulation results and include also the sample mean and the theoretical mean values.

hist(mean.runs, breaks = 40, xlab = "Mean", main = "Distribution of 1000 Simulated Exponential Means", col = "yellow")
abline(v = sample.mean, col = "darkblue")
abline(v = theoretical.mean, col = "red")

Conclusion: The sample mean of the exponential distribution is a good approximately to the theoretical mean, as suggested by the Central Limit Theorm.

Question 2: Show how variable the sample is and compare it to the theoretical variance of the distribution

Calculate the standard deviation and variance of the simulated results and compare them to the theoretical values. Print the results.

sample.sd <- sd(mean.runs)
sample.var <- sample.sd^2
print(sample.var)
## [1] 0.6262789
theoretical.sd <- (1/lambda)/sqrt(n)
theoretical.var <- theoretical.sd^2
print(theoretical.var)
## [1] 0.625

Conclusion: The variance of the sample means is approximately equal to the theoretical variance.

Question 3: Show that the distribution of sample means is approximately normal

hist(mean.runs, breaks = 40, xlab = "Mean", 
     main = "Normal and Sample Means Distributions", col = "yellow")
x.fit <- seq(min(mean.runs), max(mean.runs), length = 1000) 
y.fit <- dnorm(x.fit, mean = 1/lambda, sd = 1/lambda/sqrt(n))
lines(x.fit, y.fit*223, lty=2)

Conclusion: The distribution of sample means is approximately normal.