-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatTheory.Rmd
More file actions
65 lines (43 loc) · 1.83 KB
/
StatTheory.Rmd
File metadata and controls
65 lines (43 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
title: "Statistical Inference Project Part 1"
author: "Scott Roberts"
date: "April 2, 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Executive Summary
The purpose of this study is to compare the exponential distribution with the Central Limit Theorem. What we expect to see is that the mean of the exponentials generate will collect around the theoretical mean.
Simulations
The simulations to run are to generate 40 exponentials, take the mean and repeat this in a simulation 1000 times. We can then visually see the distribution around the mean. The sample mean is close to the theoretical mean of 5.
Figure 1
```{r rand, echo=TRUE}
set.seed(567)
#The number of simulations
sim <- 1000
#Number of exponentials to generate
vector <- 40
lambda <- .2
#Generate 1000 simulations
randexp = NULL
for (i in 1 : sim) randexp = c(randexp, mean(rexp(vector,lambda)))
```
The Sample mean v. Theoretical Mean for 1000 simulations show that the sample mean is close to the theoretical mean.
```{r}
theorymean <- 1/lambda
theoryvar <- 1/(lambda*sqrt(vector))^2
#The theoretical mean of the 40 exponentials
theorymean
# The Sample Mean
mean(randexp)
# The Samle and the Theoretical Variance are also very similar.
theoryvar
var(randexp)
###Visually show the normal distribution in two graphs, QQ-Plot and Histogram.
qqnorm((randexp))
qqline(randexp)
hist(randexp, xlab="Mean of the Exponentials", main ="Distribution of a Thousand Simulations")
abline(v=mean(randexp), col="red")
```
Distribution: Based on the above figures the distribution is approximately normal based on the center of the histograms center around the mean of 5. In the Q-Q plot, the curve is almost straight, implying a normal distribution. In the histogram, as the number of sample means increases the distribution becomes more symetrical.