Statistical Inference Part11
Statistical Inference Part11
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.