Inferencial Test PDF
Inferencial Test PDF
4/19/2020
Synopsis
In this project you 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. Illustrate via simulation and associated
explanatory text the properties of the distribution of the mean of 40 exponentials. You should 1. Show the
sample mean and compare it to 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. 3. Show that the distribution
is approximately normal.
Simulations
as per the requirement of the course project, lambda is set to 0.2 and n = 40, and simulation for 1000 times
while calculating the mean of each time
lambda <- 0.2 # Set lambda = 0.2 for all of the simulations.
n <- 40 # distribution of averages of 40 exponentials
nsim <- 1000 # Note that you will need to do a thousand simulations
set.seed(582) # setting seed
sim <- data.frame(mean=numeric(nsim))
for (i in 1:nsim) { # simulate s times
## The exponential distribution can be simulated in R with rexp(n, lambda)
samples <-rexp(n,lambda) # simulate n samples
## Calculate the average/mean of each row (40 exponentials): sample mean
sim[i,1]<-mean(samples) # sample mean
}
1
## Mean
## Samples Mean: 5.007277
## Theoretical Mean: 5.000000
the sample mean is 5.007 which is very close the theoritical mean which is equal to 5
Theoretical Mean
Sample Mean
80
Frequency
60
40
20
0
3 4 5 6 7 8
Sample Means
and as the histogram shows, the mean for both sample and theoritical values are very close.
theoretical_var <-((1/lambda)^2)/n
sample_var <- var(sim$mean)
sample_sd <- sd(sim$mean)
theoretical_sd <- (1/lambda)/sqrt(n)
## print the numeric value of means
vara <-data.frame("Variance"=c(sample_var,theoretical_var,sample_sd, theoretical_sd), row.names = c("Sam
print(vara)
2
## Variance
## Samples Var: 0.6582042
## Theoretical Var: 0.6250000
## Sample SD: 0.8112978
## Theoretical SD: 0.7905694
The variance of this sample distribution is 0.658 and the theoretical variance is 0.625. Both of them are
very close. The actual standard deviation of the sample distribution is 0.811 The theoretical sd is 0.791.
differences for both variance and standard deviations are small.
3. Distribution
to show if the distribuation is normal we plot the distribution to check if it has the bell curve and if it’s
similar to theoritical distribution
Simulation
Theoretical
0.4
0.3
Density
0.2
0.1
0.0
3 4 5 6 7 8
Sample Means
both lines for sample and theoritical distributions are nearly identical to normal distribution.