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

Peer Graded Assignment: Statistical Inference Course Project

This document summarizes a statistical inference project that investigates the exponential distribution in R and compares it to the Central Limit Theorem. 1000 simulations were run taking the average of 40 exponentials each to examine the distribution of the averages. The sample mean was calculated and compared to the theoretical mean. The sample variance was also calculated and found to approximate the theoretical variance. Finally, a histogram of the simulated means was plotted along with a normal density curve to show the distribution is approximately normal, consistent with the Central Limit Theorem.

Uploaded by

nel
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)
161 views

Peer Graded Assignment: Statistical Inference Course Project

This document summarizes a statistical inference project that investigates the exponential distribution in R and compares it to the Central Limit Theorem. 1000 simulations were run taking the average of 40 exponentials each to examine the distribution of the averages. The sample mean was calculated and compared to the theoretical mean. The sample variance was also calculated and found to approximate the theoretical variance. Finally, a histogram of the simulated means was plotted along with a normal density curve to show the distribution is approximately normal, consistent with the Central Limit Theorem.

Uploaded by

nel
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

Peer Graded Assignment: Statistical Inference Course

Project
Yuan Wei
August 7, 2016
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.2.5

Overview
This assignment investigate the exponential distribution in R and compare it with the Central Limit Theorem.
Running simulations
1000 simulations were run to investigate the distribution of averages of 40 exponentials. Ggplot 2 package
was used to generating the plot.
set.seed(100)
lambda <- 0.2
sim <- 1000
n <- 40

# Simulate and take mean


simulations <- replicate(sim, rexp(n,lambda))
sim.means <- colMeans(simulations)
To calculate the sample mean and compare it to the theoretical mean of the distribution.
# Calculate simulated mean and true mean
dis.mean <- mean(sim.means)
true.mean <- 1/lambda
# Plot histogram of simulated mean with true mean
g <- ggplot(as.data.frame(sim.means), aes(sim.means))
g + geom_histogram(fill = "white", colour = "blue", binwidth = 0.25) +
geom_vline(xintercept = true.mean) +
xlab("mean") +
ggtitle("Mean of 1000 simulations")

Mean of 1000 simulations


150

count

100

50

0
3

mean
Show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution.
# Calculate true standard deviations and variance
true.std <- 1/lambda/sqrt(n)
true.var <- true.std^2
# Calculate simulated mean and true mean
dis.std <- sd(sim.means)
dis.var <- dis.std^2
# Display results
print("Distribution variance")
## [1] "Distribution variance"
dis.var
## [1] 0.6432442
print("Theoretical variance")
## [1] "Theoretical variance"

true.var
## [1] 0.625
Show that the distribution is approximately normal.
# Plot histogram of simulated mean with true mean
g <- ggplot(as.data.frame(sim.means), aes(sim.means))
g + geom_histogram(fill = "white", colour = "blue", binwidth = 0.25, aes(y=..density..)) +
stat_function(fun = dnorm, colour = "red", args = list(mean = true.mean, sd = true.std)) +
xlab("mean") +
ggtitle("Mean of 1000 simulations")

Mean of 1000 simulations


0.6

density

0.4

0.2

0.0
3

mean

You might also like