Peer Graded Assignment: Statistical Inference Course Project (Part 1)
Instructions
This project is composed of two parts:
A simulation exercise.
Basic inferential data analysis.
Part 1: Simulation Exercise Instructions
Overview
In this part we will investigate the exponential distribution in R and compare it with the Central Limit Theorem. The exponential distribution can be simulated in R with rexp(n, lambda) where lambda is the rate parameter. The mean of exponential distribution is 1/lambda and the standard deviation is also 1/lambda. Set lambda = 0.2 for all of the simulations. You will investigate the distribution of averages of 40 exponentials. Note that you will need to do a thousand simulations.
Question 1 : Show the sample mean and compare it to the theoretical mean distribution
n <- 40
Simulations <- 1000
Lambda <- 0.2
SampleMean <- NULL
for(i in 1:Simulations) {
SampleMean <- c(SampleMean, mean(rexp(n, Lambda)))
}
mean(SampleMean)
## [1] 4.978479
Thus, compared to the theoretical mean distribution of 5 , our mean 5 is close.
Question 2: Show the sample is (via variance) and compare it to the thoretical variance of the distribtution.
The theoretical standard deviation of the distribution is also 1/lambda , which, for a lambda of 0.2 , equates to 5 . The variance is the square of the standard deviation, which is 25 .
Variance <- var(SampleMean)
0.6 is close to the theoretical distribution.
Show that the distribution is appoximately normal
hist(SampleMean, breaks = n, prob = T, col = "green", xlab = "Means")
x <- seq(min(SampleMean), max(SampleMean), length = 100)
lines(x, dnorm(x, mean = 1/Lambda, sd = (1/Lambda/sqrt(n))), pch = 25, col = "blue")

qqnorm(SampleMean)
qqline(SampleMean, col = "red")

The distribution averages of 40 exponentials is very close to a normal distribution