Announcements

Means of i.i.d. samples

Limits of sequences

Weak law of large numbers

Strong law of large numbers

How to think about laws of large numbers

# Largest sample size
max_n <- 20001
# True mean
true_mu <- (1 + sqrt(5))/2
# Generate a large sample
X <- rnorm(max_n, mean = true_mu, sd = 1) 
# Make a list of sample sizes
n <- seq(from = 5, to = max_n, by = 100)
# Compute sample means for each sample size
Xbar_n <- sapply(n, function(first_n) mean(X[1:first_n]))
# Create a data frame for plotting
lln <- data.frame(n = n, Xbar_n = Xbar_n)
# Plot the sample sizes
ggplot(lln, aes(n, Xbar_n)) + geom_point() + geom_hline(yintercept = true_mu) +
  ylab("Sample mean") + theme_minimal() + ylim(c(min(1.4, min(Xbar_n)), max(2, max(Xbar_n))))

Square-root convergence

“In the long run we are all dead” - Keynes

set.seed(43)
X <- rcauchy(max_n) 
Xbar_n <- sapply(n, function(first_n) mean(X[1:first_n]))
lln <- data.frame(n = n, Xbar_n = Xbar_n)
ggplot(lln, aes(n, Xbar_n)) + geom_point() + ylab("Sample mean") + theme_minimal() +
  ylim(c(min(1.4, min(Xbar_n)), max(2, max(Xbar_n)))) + ggtitle("Heavy tails break the LLN")

R markdown lab