set.seed(123)
sim_means = NULL
sim_var = NULL
sim_sd =NULL
Exponential<-rexp(40,.2)
hist(Exponential, breaks =20,col="grey",xlab="Random numbers from an exponential with n=40, lambda =0.2")
for (i in 1:1000) sim_means = c(sim_means,mean(rexp(40,.2)))
for (i in 1:1000) sim_var = c(sim_var, var(rexp(40,.2)))
for (i in 1:1000) sim_sd = c(sim_sd, sd(rexp(40,.2)))
msn<-mean(sim_means,1)
vsn<-mean(sim_var)
sdn<-mean(sim_sd)
nor_means<-rnorm(1000,5,5)
par(mfrow=c(1,2))
hist(sim_means, breaks = 20,col ="green", prob=TRUE)
lines(density(sim_means),lwd=4)
abline(v=5, lwd=3,col="orange")
hist(nor_means, breaks=20,col="grey", prob=TRUE)
lines(density(nor_means),lwd=4)
abline(v=5, lwd=3,col="orange")
###Graphical representations of the distributions of the simulated statistics from simulation (variations left) and standard deviation (right). Theoretical value av orange vertical line
par(mfrow=c(1,2))
hist(sim_var, breaks = 20, col="blue")
abline(v=25, lwd=3,col="orange")
hist(sim_sd, breaks = 20, col="red")
abline(v=5, lwd=3,col="orange")
##The mean of the simulated mean , var and sd values are 4.98, 24.77 and 4.88, respectively. This is compared to the teoretical values 5, 25 and 5. The figures shows that simulated mean and standard deviation are quite close to normal distribution around theoretical value , whereas variation is more “off”.