Overview
In this exercise, Iām gonna perform 1000 simulations on 40 exponentials Data. Firstly, mean, variance and standard deviation of are calculated by general R manipulation. Then, by formula, mean, variance and standrd deviation is calculated and compare them. At the end, the data is visualized to check its approximation with Normal Distribution.
1. Expected values Calculation of simulated data.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
set.seed(555)
lamda<-0.2
n<-40
simulations<-1:1000
simulatedData<-data.frame(x=sapply(simulations, function(x) {mean(rexp(n,lamda))}))
meanData<-apply(simulatedData, 2, mean)
standarDeviataion<-apply(simulatedData, 2, sd)
Variance<-apply(simulatedData,2,var)
3. Showing mean, variance and standard deviation of simulated data
meanData
## x
## 4.991502
Variance
## x
## 0.6366598
standarDeviataion
## x
## 0.7979096
4. Showing mean, variance and standard deviation of Central Limit Theorem
cltMean
## [1] 5
CLTvariance
## [1] 0.625
CLTstandardDeviation
## [1] 0.7905694
5. Compare the expected values with the valus of central limit theorem.
By showing values, it is concluded that expected values are approximately equal to the values of Central Limit Theorem.
6. Visualization of simulated data to approximate it with Normal Distribution
g<-ggplot(simulatedData, aes(x=x))
g<-g+geom_histogram(aes(y=..density..),binwidth = 0.20)
g<-g+stat_function(fun=dnorm, args=list(mean=meanData, sd=standarDeviataion))
g<-g+geom_vline(xintercept = meanData, color="red")
print(g)
