Stat Inference CPP 1
Stat Inference CPP 1
Exercise
Francisco Nazar A.
March 14, 2015
In this document we perform a the exerciseof running 1000 simulations of the averages of 40 exponential
distributions. The parameters obtained (mean and standard deviation) are compared to the theoretical ones
and the distribution is compared to a normal distribution. First, we set all the constants. Also, we set the
seed.
lambda=0.2 # rate parameter
ne=40 # number of exponentials
ns=1000 # number of simulations
tmean=1/lambda # theoretical mean
tsd=1/lambda # theoretical standard deviation
set.seed(2407) # set seed for start simulation
we then create an empty array and simulate to obtain the distribution, also obtaining the mean and the
standard deviation
sims <- rep(0, ns)
for (i in 1:ns) {
sims[i] <- mean(rexp(ne, lambda))
}
smean<- mean(sims)
ssd<-sd(sims)
then the questions are addressed.
1. Show the sample mean and compare it to the theoretical mean of the distribution.
We can compare directly the two values
smean # sample mean
## [1] 4.976691
smean-tmean # absolute diference between sample and theoretical means
## [1] -0.02330891
(smean-tmean)/tmean*100 # error percentaje between sample and theoretical means
## [1] -0.4661782
so about 0.3%.
1
2. Show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution.
Again, we compare directly the values
ssd^2 # sample standard deviation squared
## [1] 0.6167586
tsd^2-ssd^2 # absolute diference between sample and theoretical standard deviations
## [1] 24.38324
(tsd^2-ssd^2)/tsd^2*100 # error percentaje between sample and theoretical standard deviations
## [1] 97.53297
about 97.5% with respect to the theoretical value (25). Evidently the values are quite different, being the
sample notably smaller (0.6).
0.5
Distribution of means
0.3
0.2
0.1
0.0
Density
0.4
Sample Mean
Theoretical Mean
Normal Distribution
5
Mean
2
6
5
4
3
Sample Quantiles
Normal QQ Plot
Theoretical Quantiles
hence, the data is APPROXIMATELY normally distributed. In other words, the normal distribution is a
good aproximation to the simulations, and the Central Limit Theorem (CLT) is observed.