Weak law of Large Numbers

Goal: Show that \(P(|\bar X_n - \mu > \epsilon)\) can be made arbitrarily small, by taking large n. 

Set-up: Flip a fair coin a large number of times, compute proportion of heads, compare to .5, and then repeat in a large number of trials to estimate probability.

n_flips <- 5000 #number of coin flips
trials <- 10^5 #number of experiments

props <- rep(0, trials) #initialize a vector to store our results

for (i in 1:trials){
  my_sample <- sample(0:1, n_flips, replace = T) #flip the coin n_flips times
  props[i] <- mean(my_sample) #compute the proportion of heads and store as ith
                              #element of props vector
}
hist(props) #look at histogram to see what proportion 

            #of trials had mean close to 0.5
epsilon <- 0.05 #set a threshold for closeness
mean(abs(props - .5) > epsilon) #determine the proportion of trials that
## [1] 0
                                 #had mean within this threshold of 0.5

Strong Law of Large Numbers

Goal: Show that \(\bar X_n\) can be made arbitrarily close to \(\mu\) by taking large \(n\).

n_flips <- 10^5 #This is how many coins we will flip

my_sample <- sample(0:1, n_flips, replace = T) #flip the coin n_flips times
running_prop <- cumsum(my_sample)/1:n_flips #create a running proportion of heads
plot(running_prop, type = "l")

#The plot should show the running proportion ff heads tending toward 0.5

Central Limit Theorem

Goal: Show that the distribution of \(\bar X_n\) is approximately Normal.

## Expo
mean <- 1  #The mean Expo(1) is 1
variance <- 1 #The variance Expo(1) is 1
sd <- sqrt(variance)
 
n<-10^4 #Set the sample size
n_trials <- 10^4 #set the number of trials of the experiment

standardized_values <- rep(0, n_trials) 
#create a vector to store standardized values

for (i in 1:n_trials){
  my_sample <- rexp(n, 1) #sample n times from expo(1)
  sample_mean <- mean(my_sample) #compute the mean of the sample
  standardized_values[i] <- (sample_mean - mean )/(sd/sqrt(n))
     #create a standardized value for the sample mean, by subtracting
     #true mean, and dividing by standard deviation of sample mean
}
hist(standardized_values)

#The histogram should look approximately Normal