1: Law of Large Numbers (LLN)

The LLN goes hand-in-hand when finding the mean of a sample population. Essentially, it states that when we conduct a sample, as the sample size we observe (n) grows, the sample’s average will be more likely to be closer to the true population’s mean. Every time we take a sample, there’s a chance that some of the observed cases are extreme values within the population and will skew our sample mean. But as we collect more observations per sample, individual extreme values have less influence on the sample mean, allowing it to become more stable around the true population mean.

helpful YT video YouTube Video

2. Central Limit Theory (CTL)

Similar to LLN, the CTL changes as our sample size increases, but instead of honing in on the population mean, the CTL states that as n increases, the sampling distribution of the mean becomes approximately normal. As in the distribution becomes akin to the Normal Distribution (bell curve), even if the original population isn’t normally distributed itself. The distribution of the sample mean will also be less spread out than the actual population, since it deals with means rather than a collection of individual values. Again like the LLN, as n increases, so does the impact of extreme values.

3. Differences

The LLN deals with a single sample mean, while the CLT covers a collection, or distribution of sample means. As n increases, the LLN states that the sample mean becomes a more accurate representation of the true population mean. The CLT on the other hand, the sampling distribution of the mean becomes approximately normal while the standard error, or the amount of variation among the collected sample means decreases. Therefore, the LLN is intended for the sample mean to converge towards the population mean, while the CLT is about the shape and spread of the distribution of the sample means.

4. Distribution: Student T

Similar to Normal Distribution, Student T delas with finding the Population Mean (Mu). But whereas Normal can be used when the Population Standard Deviation (σ) is known, where Studnet-T takes its place when the Mu is unknown and instead rely on the Sample Standard Deviation (s). Studnet T also specializes when the sample size is relatively small (usually when n is 30 or less).

Since Student T deals with the Sample Standard Deviation, the level of uncertainty is higher, so to combat this, we make use of the confidence tails when building our Confidence Interval (CI). As n increases, like with the CLT, the Student T’s distribution becomes close to the Normal Distribution.

To build the CI, we use this formula:

\[ \bar{x} \pm t_{\nu,\alpha/2}\left(\frac{s}{\sqrt{n}}\right) \]

ν: n - 1 (degrees of freedom)

α (significance level): 1 - Confidence Level

The α/2 is for a 2-tailed CI, an α for each side of the confidence area.

The last major part is the Error Bound for a Mean (EBM). It’s the value that we =- from the sample mean, which is bascially the sample’s margin of error. Sample Mean +- EBM (Margin of Error)

\[ EBM = t_{\nu,\alpha/2}\left(\frac{s}{\sqrt{n}}\right) \] To comput in R, the function is t.test(). It has 2 main arguements. X for specifying the data you want to perfrom the test on. As well as Confidence Level: conf.level = . YOu just need to input a value for X, the confidence level is defaulted to 0.95 (alpha of 0.05).

I made a small random sample of 25 with a median of 82.5 and a sd of 7. I used the rnorm() function to generate a string of random values that follow a normal distribution with the listed parameters. Lets pretend you don’t actually know the mean and sd and used the t.test function to estimate the population mean.

set.seed(14)

N <- 25
MySamplePopulation_Mean <- 82.5
MySamplePopulation_SD <- 7
MySamplePopulation <- rnorm(n = N, mean = MySamplePopulation_Mean, sd = MySamplePopulation_SD)
MySamplePopulation
##  [1] 77.86705 94.53268 97.35167 92.98008 82.24702 91.12362 82.04583 89.98296
##  [9] 79.86124 89.80228 79.82025 84.59595 87.21968 80.45029 85.91637 88.67961
## [17] 95.53924 93.78208 83.44836 90.11660 73.63230 81.10992 83.47206 80.54465
## [25] 87.46244
mean(MySamplePopulation)
## [1] 86.14337
t.test(MySamplePopulation, conf.level = 0.9)
## 
##  One Sample t-test
## 
## data:  MySamplePopulation
## t = 69.956, df = 24, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 90 percent confidence interval:
##  84.03659 88.25015
## sample estimates:
## mean of x 
##  86.14337

5. CLT

So I followed the given example on CLT. Starting off with clearing data from R and setting a seed to keep consistent random values/distribution. Then created a population mean and standard deviation from my randomly generated uniform distribution dataset.

rm(list = ls())
gc()
##           used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
## Ncells  631323 33.8    1446242 77.3         NA   715668 38.3
## Vcells 1195792  9.2    8388608 64.0      32768  2010415 15.4
cat("\f")
set.seed(77)
spykids <- runif(n = 12000, min = 10, max = 20)
spykids[1:12]
##  [1] 12.91284 17.17469 18.62375 19.50074 17.38841 14.57470 18.51428 18.46515
##  [9] 15.67378 14.56909 18.72398 19.88195
mu <- mean(spykids)
mu
## [1] 14.98969
standev <- sd(spykids)
standev
## [1] 2.861289
library("psych")
## Warning: package 'psych' was built under R version 4.5.2
describe(spykids)
##    vars     n  mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 12000 14.99 2.86  14.95   14.98 3.65  10  20    10 0.02    -1.18 0.03

The hist() function let me see the actual distribution of the random uniform values.

hist(x = spykids, main = "Uniform Distribution (min=10, max=25, n=12,000)", xlab = "", ylim = c(0,700))

Creating a blank matrix to house the series of sample sets, all with a set sample size of

zoro <- matrix(data = rep(x = 0, times = 12000), nrow = 12000, ncol = 1)
zoro[1:12]
##  [1] 0 0 0 0 0 0 0 0 0 0 0 0
describe(zoro)
##    vars     n mean sd median trimmed mad min max range skew kurtosis se
## X1    1 12000    0  0      0       0   0   0   0     0  NaN      NaN  0
for (i in 1:12000){
  zoro[i,] <- mean(sample(x = spykids, size = 100, replace = T))}
zoro[1:12]
##  [1] 15.07535 15.32423 14.93775 14.88340 15.37872 14.97848 14.50758 14.80562
##  [9] 14.97733 14.65435 15.08840 15.65066
describe(zoro)
##    vars     n  mean   sd median trimmed  mad   min   max range skew kurtosis se
## X1    1 12000 14.99 0.29  14.99   14.99 0.29 13.73 16.13  2.39 0.03    -0.02  0
hist(zoro, main = "Sample Mean (n=100)", xlab = "")

zoro <- matrix(data = rep(x = 0, times = 48000), nrow = 12000, ncol = 4)
n<- c(2, 6, 30, 1000)

for (j in 1:4){
  for (i in 1:12000){
    zoro[i,j] <- mean(sample(x = spykids, size = n[j], replace = T))
  }
}

colnames(zoro) <- c("Sample Size = 2", "Sample Size = 6", "Sample Size = 30", "Sample Size = 1000")
summary(zoro)
##  Sample Size = 2 Sample Size = 6 Sample Size = 30 Sample Size = 1000
##  Min.   :10.07   Min.   :10.57   Min.   :12.91    Min.   :14.68     
##  1st Qu.:13.53   1st Qu.:14.20   1st Qu.:14.63    1st Qu.:14.93     
##  Median :14.97   Median :15.00   Median :14.98    Median :14.99     
##  Mean   :14.99   Mean   :15.00   Mean   :14.99    Mean   :14.99     
##  3rd Qu.:16.42   3rd Qu.:15.81   3rd Qu.:15.34    3rd Qu.:15.05     
##  Max.   :19.98   Max.   :19.16   Max.   :17.08    Max.   :15.38
par(mfrow = c(3,2))
hist(x = spykids, main = "Uniform Dist Hist (n=12,000)", xlab = "")

for (k in 1:4){
  hist(x = zoro[,k],
       main = "Uniform Dist Sample Mean Hist", xlim = c(10,20), xlab = paste0("Sample Size ", n[k], " (Column ", k, " from Matrix)"))
}