0% found this document useful (0 votes)
20 views2 pages

Statistical Inference Part11

This simulation exercise generates 1,000 samples of averages of 40 exponentially distributed random variables with rate parameter 0.2. It calculates the sample mean and variance, and compares them to the theoretical mean and variance. A histogram of the sample averages is also plotted along with the density function of a normal distribution with the same mean and standard deviation, showing the sample averages are approximately normally distributed.

Uploaded by

briofons
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)
20 views2 pages

Statistical Inference Part11

This simulation exercise generates 1,000 samples of averages of 40 exponentially distributed random variables with rate parameter 0.2. It calculates the sample mean and variance, and compares them to the theoretical mean and variance. A histogram of the sample averages is also plotted along with the density function of a normal distribution with the same mean and standard deviation, showing the sample averages are approximately normally distributed.

Uploaded by

briofons
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/ 2

Simulation Exercise

briofons
January 24, 2015
Introduction
This is the project for the Statiscal inference course by Coursera. This project has two excercises First, a
simulation exercises and second Basic inferential data analysis.
Sypnosis
The exponential distribution can be simulated in R with rexp(n, lambda) where lambda is the rate parameter.
Set lambda = 0.2 for all of the simulations. In these simulations we create the distribution of averages of 40
exponentials over thousands observations assuming how I said before, lambda = 0.2
Question 1
lambda = 0.2
n = 40
set.seed(7777)
distribucion <- data.frame(x = sapply(1:1000, function(x) {mean(rexp(n, lambda))}))
We show the simulation mean, variance:
cmean <- mean(distribucion$x)
cmean
## [1] 5.035271
cvar <- var(distribucion$x)
cvar
## [1] 0.6188305
theorical mean and the theorical variance is:
1/0.2
## [1] 5
((1/lambda)/sqrt(40))^2
## [1] 0.625
Question 2 As we can see the cmean is 5.035 and we expected 5.0 and the variance is 0.78 in the simulation
and the thoerical is 0.7905.
Question 3. Show that the distribution is approximately normal.

library(ggplot2)
ggplot(data = distribucion, aes(x = x)) +
geom_histogram(aes(y=..density..),
binwidth = 0.20, color = I('black')) +
stat_function(fun = dnorm, arg = list(mean = 5, sd = sd(distribucion$x)))

0.5

density

0.4

0.3

0.2

0.1

0.0
4

x
Now we want to see if the distribution simulation is like a normal distribution as we can see in this plot how
is approximately our simulation with normal distribution. And we can say yes.

You might also like