set.seed(seed = 13)
Law of Large Numbers states that as you increase the number of trials, the observed probabilities of the observations will start to reflect the actual probability. For example, the larger our sample size is, the closer our sample average will be to the actual population average.
The Central Limit Theorem states the larger the sample size, the more the distribution of the sample mean will resemble a normal distribution, despite the shape of the population distribution.
The Law of Large Numbers and the Central Limit Theorem both revolve around what happens as the sample size of a population increases. However, the Law of Large Numbers deals with the accuracy of the sample mean, while the Central Limit Theorem deals with the distribution of the sample mean.
I chose a gamma distribution. The gamma distribution is a continuous probability distribution that is used to model the time until one or more events occur. For example, you could use this distribution to model time until a light bulb burns out. Since this distribution is dealing with time, we can only model non-negative numbers. The R functions related to gamma distributions are dgamma, pgamma, qgamma, and rgamma, which give the PDF, CDF, quantile function, and simulate randomly variates, respectively. These functions typically ask you to define vector of quantiles, shape, and rate.
# Creating our Gamma distribution
mygamma <- rgamma(
n = 10000,
shape = 2,
rate = 2
)
# Adding the mean of the population
popmu <- mean(mygamma)
popmu
## [1] 1.000985
hist(mygamma,
probability = TRUE,
breaks = 40,
main = "Gamma Distribution (shape = 2, rate = 2)",
xlab = "Waiting time")
mymat <- matrix(
rep(
x=0,
times=50000
),
nrow= 50,
ncol = 1000
)
str(mymat)
## num [1:50, 1:1000] 0 0 0 0 0 0 0 0 0 0 ...
for (i in 1:1000){mymat[1:50,i]=sample(mygamma, 50, replace = TRUE)}
str(mymat)
## num [1:50, 1:1000] 0.2403 4.0851 0.0934 0.2566 0.7817 ...
mymeans=colMeans(mymat)
plot(density(mymeans),
main = "Density of Sample Means of Gamma Distribution",
xlab = "Sample Mean",
ylab = "Density",
)
mymedians = apply(mymat, 2, median)
plot(density(mymedians),
main = "Density of Sample Medians of Gamma Distribution",
xlab = "Sample Median",
ylab = "Density",
)
In 5A, the distribution of the sample means of a gamma population begins to resemble a normal distribution, which makes sense according to the CLM. 5B shows that the Sample Medians are approaching a normal distribution but it still some what positively skewed. This could be do to the median being a more robust statistic than the mean.