Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Statistical Inference Course Project Part I

Mateo Córdoba Toro


7/10/2020
1000 samples of the means of the exponential distribution are generated using a for , then the mean and
variance are calculated, finally the respective distribution of the samples is plotted reflecting their normal behavior.

Simulation Exercise
A sample of 1000 replicates is generated from the mean of an exponential assimilation of 40 observations.

set.seed(100)
n <- 40
lambda <- 0.2
B <- 1000

Sample = NULL
for (i in 1 : B) Sample = c(Sample, mean(rexp(n,lambda)))

Sample mean vs Theorical mean


The standard deviation formula is used to find the variance, both theoretically and empirically. the variance has a
small deviation, however it is minimal and tends to the theoretical value.

'Sample mean' <- round(mean(Sample),3)


'Theorical mean '<- round(1/lambda)
'Sample var ' <- round(var(Sample),3)
'Theorical var' <- (1/lambda)^2/n
cbind(`Sample mean`,`Theorical mean `)

## Sample mean Theorical mean


## [1,] 5 5

cbind(`Sample var `, `Theorical var`)

## Sample var Theorical var


## [1,] 0.643 0.625

Distribution Graph
It can be observed that after generating the sample, the distribution of the mean of the imulations is 5 as it is
theoretically.
The histogram shows normal behavior, a normal distribution cross is added with the specification of mean and
standard deviation to indicate that effectively after the replicates the distribution of the means is approximately
normal.

library(scales)
hist(Sample, main = 'Histogram of Averages of 40 Exponentials over 1000 Simulations',
xlab='Mean',
freq = FALSE,
col=alpha('steelblue',0.7))
curve(dnorm(x,5,sd(Sample)),
from = 3, to = 9,
add = TRUE, lwd=3,
col = alpha('orange', 0.6))
abline(v=5,lwd=3,col= alpha('red', 0.7), lty=2)

You might also like