# Please load the packages.
library(ggplot2)
library(ipsRdbs)
# Start with a clean workspace
rm(list=ls())
1
<- see_the_clt_for_uniform() a
<- par(no.readonly = TRUE)
old.par par(mfrow=c(2, 3))
<- see_the_clt_for_uniform(nsize=1)
a1 <- see_the_clt_for_uniform(nsize=2)
a2 <- see_the_clt_for_uniform(nsize=5)
a3 <- see_the_clt_for_uniform(nsize=10)
a4 <- see_the_clt_for_uniform(nsize=20)
a5 <- see_the_clt_for_uniform(nsize=50) a6
par(old.par)
<- see_the_clt_for_uniform(nsize=12) ybars
<- (ybars - mean(ybars))/sd(ybars)
zbars <- 100
k <- seq(from=min(zbars), to= max(zbars), length=k)
u <- rep(NA, k)
ecdf for(i in 1:k) ecdf[i] <- length(zbars[zbars<u[i]])/length(zbars)
<- pnorm(u)
tcdf plot(u, tcdf, type="l", col="red", lwd=4, xlab="", ylab="cdf")
lines(u, ecdf, lty=2, col="darkgreen", lwd=4)
<- c("cdf of sample means", "cdf of N(0, 1)")
symb legend(x=-3.5, y=0.4, legend = symb, lty = c(2, 1),
col = c("darkgreen","red"), bty="n")
# Demonstrate the WLLN for uniform
<- see_the_wlln_for_uniform(nsize=1, nrep=50000) a1
<- see_the_wlln_for_uniform(nsize=10, nrep=50000) a2
<- see_the_wlln_for_uniform(nsize=50, nrep=50000) a3
<- see_the_wlln_for_uniform(nsize=100, nrep=50000) a4
plot(a4, type="l", lwd=2, ylim=range(c(a1$y, a2$y, a3$y, a4$y)), col=1,
lty=1, xlab="mean", ylab="density estimates")
lines(a3, type="l", lwd=2, col=2, lty=2)
lines(a2, type="l", lwd=2, col=3, lty=3)
lines(a1, type="l", lwd=2, col=4, lty=4)
<- c("n=1", "n=10", "n=50", "n=100")
symb legend(x=0.37, y=11.5, legend = symb, lty =4:1, col = 4:1)