Overview
This report disscuss the exponential distribution in R and compare it with the Central Limit Theorem. The flow of report is as follows:
- Simulation
- Sample Mean versus Theoretical Mean
- Sample Variance versus Theoretical Variance
- Distribution
Simulations
Import library
Given values for simulation
Seeding Random Variate Generators
Run simulation
Plot Histogram and Scatter
b <- ggplot(mns, aes(x=mns)) + geom_histogram(aes(y=..count..), colour="black", fill="white") + ggtitle("Mean of Exponential Distribution") + xlab("Mean") + ylab("Count") + theme_dark()
ggplot(mns_df, aes(x=mns_df$Mean,y=mns_df$Frequency)) + geom_point(aes(color =mns_df$Frequency, size =mns_df$Frequency), alpha = 0.5) + scale_color_gradientn(colors = c("#00AFBB", "#E7B800", "#FC4E07"),name="Mean") + scale_size(range = c(0.5, 12), ,name="Frequency") + ggtitle("Frequency vs Mean") + xlab("Mean") + ylab("Frequency") + theme_dark()Sample Mean versus Theoretical Mean
smple_mean = round(mean(mns$mns),digits = 2)
theo_mean = round(1/lambda,digits = 2)
b <- b + geom_vline(xintercept = smple_mean, colour = "red",linetype="dashed") + geom_vline(xintercept = theo_mean, color = "blue",linetype="dashed") + theme_dark() + theme(legend.position = "bottom")
b
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. # Sample Variance versus Theoretical Variance
Distribution
theo_sd <- data.frame(round(dnorm(mns$mns,mean = theo_mean,sd = sqrt(theo_var), log = FALSE),digits = 2))
ggplot(mns, aes(x=mns)) + geom_histogram(aes(y=..density..,fill=..density..), colour="black") + geom_density(alpha=.2, fill="#FF6666") + ggtitle("Mean Distribution of Theorial vs Sample ") + xlab("Mean") + ylab("Density") + geom_density(alpha=.2, fill="#FF6666") + geom_area(stat = "function", fun = dnorm, args=list( mean=theo_mean, sd=sqrt(theo_var)), fill = "#f7ce9e", color = "red", alpha = 0.5) + theme_dark()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.