Rudolf Adamkovič Personal site


Simulation

Repeatedly increase the sample size from \(n = 1\) to the population size:

set.seed(0)

N <- 1000      # the population size
Z <- 0 : N     # the population
mu <- mean(Z)  # the population mean
D <- rep(0, N) # absolute deviations

for(n in 1 : N)
  D[n] <- mean(sample(Z, n)) - mu

plot(
  D,
  main = "A demonstration of the law of large numbers.",
  type = "l",
  lwd = 2,
  xlab = "Sample size",
  ylab = "Absolute deviation"
)
abline(h = 0)

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.