0% found this document useful (0 votes)
19 views

Stat Inference CPP 1

1. The document describes running 1000 simulations of averages of 40 exponential distributions with rate parameter λ=0.2. It compares the sample mean and standard deviation to the theoretical values. 2. The sample mean of 4.976691 is very close to the theoretical mean of 5, with an error of only 0.3%. However, the sample standard deviation of 0.6167586 is much smaller than the theoretical value of 1, with an error of 97.5%. 3. A histogram and Q-Q plot show that while the distribution of the sample means is not exactly normal, it provides a good approximation, demonstrating the Central Limit Theorem.

Uploaded by

F
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Stat Inference CPP 1

1. The document describes running 1000 simulations of averages of 40 exponential distributions with rate parameter λ=0.2. It compares the sample mean and standard deviation to the theoretical values. 2. The sample mean of 4.976691 is very close to the theoretical mean of 5, with an error of only 0.3%. However, the sample standard deviation of 0.6167586 is much smaller than the theoretical value of 1, with an error of 97.5%. 3. A histogram and Q-Q plot show that while the distribution of the sample means is not exactly normal, it provides a good approximation, demonstrating the Central Limit Theorem.

Uploaded by

F
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Statistical Inference Course Project - Part I - Simulation

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).

3. Show that the distribution is approximately normal.


First, an histogram is illustrative for viewing the sample distribution
hist(sims, breaks=30 ,main = "Distribution of means", xlab = "Mean", ylab="Density", freq=FALSE)
abline(v=tmean, col="red");abline(v=smean, col="blue")
x=seq(3,8,length=1000);lines(x,dnorm(x,mean=smean,sd=ssd),col="green", type="l")
legend(5.8,0.5, c("Sample Mean","Theoretical Mean", "Normal Distribution"), lty=c(1,1,1),
lwd=c(2.5,2.5,2.5),col=c("blue","red", "green"), cex=0.7)

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

Also, we can compare the Q-Q plots


qqnorm(sims)
qqline(sims)

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.

You might also like