0% found this document useful (0 votes)
68 views3 pages

Inferencial Test PDF

The document describes a simulation exercise to investigate the exponential distribution and compare it to the central limit theorem. It involves simulating the average of 40 exponential distributions 1000 times and comparing the sample mean, variance, and distribution to the theoretical values. The results show that the sample mean is very close to the theoretical mean of 5. The sample variance and standard deviation are also similar to the theoretical values and the distribution of sample means follows a normal bell curve shape matching the theoretical normal distribution closely.

Uploaded by

fakhruldeen
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)
68 views3 pages

Inferencial Test PDF

The document describes a simulation exercise to investigate the exponential distribution and compare it to the central limit theorem. It involves simulating the average of 40 exponential distributions 1000 times and comparing the sample mean, variance, and distribution to the theoretical values. The results show that the sample mean is very close to the theoretical mean of 5. The sample variance and standard deviation are also similar to the theoretical values and the distribution of sample means follows a normal bell curve shape matching the theoretical normal distribution closely.

Uploaded by

fakhruldeen
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

inferential statistics: Part 1: Simulation Exercise

Mohamed Fouad Fakhruldeen

4/19/2020

Synopsis

In this project you will investigate the exponential distribution in R and compare it with the Central Limit
Theorem. The exponential distribution can be simulated in R with rexp(n, lambda) where lambda is the
rate parameter. The mean of exponential distribution is 1/lambda and the standard deviation is also
1/lambda. Set lambda = 0.2 for all of the simulations. You will investigate the distribution of averages of 40
exponentials. Note that you will need to do a thousand simulations. Illustrate via simulation and associated
explanatory text the properties of the distribution of the mean of 40 exponentials. You should 1. Show the
sample mean and compare it to the theoretical mean of the distribution. 2. Show how variable the sample is
(via variance) and compare it to the theoretical variance of the distribution. 3. Show that the distribution
is approximately normal.

Simulations

as per the requirement of the course project, lambda is set to 0.2 and n = 40, and simulation for 1000 times
while calculating the mean of each time

lambda <- 0.2 # Set lambda = 0.2 for all of the simulations.
n <- 40 # distribution of averages of 40 exponentials
nsim <- 1000 # Note that you will need to do a thousand simulations
set.seed(582) # setting seed
sim <- data.frame(mean=numeric(nsim))
for (i in 1:nsim) { # simulate s times
## The exponential distribution can be simulated in R with rexp(n, lambda)
samples <-rexp(n,lambda) # simulate n samples
## Calculate the average/mean of each row (40 exponentials): sample mean
sim[i,1]<-mean(samples) # sample mean
}

1. Sample Mean versus Theoretical Mean

showing the sample mean and theoritical mean

## calculate the mean both theoritical and sample means


theoretical_mean <- 1/lambda
sample_mean <- mean(sim$mean)
meansa <-data.frame("Mean"=c(sample_mean,theoretical_mean), row.names = c("Samples Mean: ","Theoretical
print(meansa)

1
## Mean
## Samples Mean: 5.007277
## Theoretical Mean: 5.000000

the sample mean is 5.007 which is very close the theoritical mean which is equal to 5

## plotting the means


hist(sim$mean, freq=TRUE, breaks=25, main="Distribution of Sample Means" , xlab="Sample Means", col = '
abline(v=sample_mean, col='brown2', lwd=4, lty = 'dotdash') # Sample Mean
abline(v=theoretical_mean, col='blue', lwd=4, lty = 'dotted') # Theoretical Mean
legend('topright', c("Theoretical Mean","Sample Mean"), col=c("blue", "brown2"), lty=c('dotted','dotdash

Distribution of Sample Means


100

Theoretical Mean
Sample Mean
80
Frequency

60
40
20
0

3 4 5 6 7 8

Sample Means

and as the histogram shows, the mean for both sample and theoritical values are very close.

2. Sample Variance versus Theoretical Variance

comparing variamce of theoritical and sample values

theoretical_var <-((1/lambda)^2)/n
sample_var <- var(sim$mean)
sample_sd <- sd(sim$mean)
theoretical_sd <- (1/lambda)/sqrt(n)
## print the numeric value of means
vara <-data.frame("Variance"=c(sample_var,theoretical_var,sample_sd, theoretical_sd), row.names = c("Sam
print(vara)

2
## Variance
## Samples Var: 0.6582042
## Theoretical Var: 0.6250000
## Sample SD: 0.8112978
## Theoretical SD: 0.7905694

The variance of this sample distribution is 0.658 and the theoretical variance is 0.625. Both of them are
very close. The actual standard deviation of the sample distribution is 0.811 The theoretical sd is 0.791.
differences for both variance and standard deviations are small.

3. Distribution

to show if the distribuation is normal we plot the distribution to check if it has the bell curve and if it’s
similar to theoritical distribution

hist(sim$mean, prob=T, main="Distribution of Sample Means vs Theoretical Density", xlab="Sample Means",


lines(density(sim$mean), col = 'blue', lwd=2) # simulated
abline(v=theoretical_mean, col='red', lwd=2) # Theoretical Mean - Red Line
xa <- seq(min(sim$mean), max(sim$mean), length=100) # Theoretical
ya <- dnorm(xa, mean=1/lambda, sd=(1/lambda/sqrt(n)))
lines(xa, ya, pch=8, col="red", lty=1)
legend('topright', c("Simulation", "Theoretical"), col=c("blue", "red"), lty=c(1,1)) # Legend

Distribution of Sample Means vs Theoretical Density


0.5

Simulation
Theoretical
0.4
0.3
Density

0.2
0.1
0.0

3 4 5 6 7 8

Sample Means

both lines for sample and theoritical distributions are nearly identical to normal distribution.

You might also like