Skip to content

Random Sampling, Monte Carlo, and Limit Theorems

Random sampling connects probability models to computation. We use Python to generate i.i.d. samples, construct Monte Carlo estimates, and study their uncertainty. The LLN explains consistency; the CLT explains the approximate shape and scale of simulation error.

A sample mean has a mean and a variance that follow from the underlying model. Monte Carlo replaces an integral or a probability by an average of simulated indicators or values, with an error that typically shrinks like \(1/\sqrt{n}\). Rare events need larger samples than a generic \(n\) of a few thousand.

Key Concepts

  • I.i.d. samples and the sampling distribution of the sample mean
  • Monte Carlo estimators and Monte Carlo standard error
  • The law of large numbers
  • The central limit theorem
  • Reproducible simulation with a fixed seed

Learning Objectives

  • Generate random samples and construct Monte Carlo estimators.
  • Calculate the mean and variance of a sample mean.
  • Use the LLN and CLT appropriately.
  • Report a Monte Carlo standard error and choose a sample size for a target accuracy.

Session Preparation:

Attempt the core exercises from Session 5, especially the exercise on moments of a sum.

Syllabus and input

Session material


Exercises

Exercise 1 — Sampling distribution

Water samples have mean sulfate content \(7.48\) mg/L and standard deviation \(1.60\) mg/L. For an independent sample of size 10:

  1. Find the mean and standard deviation of the sample mean.
  2. Assuming normal observations, find \(P(6.49<\bar X<8.47)\).
  3. Simulate the experiment and compare with the theoretical probability.
Answer

\(E[\bar X]=7.48\) and \(\operatorname{SD}(\bar X)=1.60/\sqrt{10}\). Standardise the two bounds using this standard deviation. A large simulation should agree up to Monte Carlo error.

Exercise 2 — CLT and sample size

Tree counts have mean 19.86 and standard deviation 23.65.

  1. Find the standard error for sample sizes 8, 30, and 100.
  2. Explain why the normal approximation is questionable for \(n=8\) if the population is strongly right-skewed.
  3. Simulate a skewed distribution with the same approximate mean and compare the three sample-mean distributions.

Exercise 3 — Aggregate counts

Daily accident counts are independent \(\operatorname{Poisson}(10)\). Use the CLT to approximate the probability of more than 3800 accidents in 365 days. Compare with a simulation.

Answer

The annual sum has mean and variance 3650. With continuity correction, approximate \(P(S\ge3801)\) by \(P\bigl(Z>(3800.5-3650)/\sqrt{3650}\bigr)\).

Exercise 4 — Monte Carlo area

Estimate \(\pi\) by sampling points uniformly in \([-1,1]^2\). Report the estimate and an estimated Monte Carlo standard error for \(n=10^2,10^3,10^4,10^5\). Explain the observed \(1/\sqrt n\) rate.

Exercise 5 — Reproducible simulation

Estimate \(E[e^U]\) for \(U\sim\operatorname{Uniform}(0,1)\). Use a fixed random seed, state the estimator, compare with the exact value \(e-1\), and construct a plot of cumulative estimates against sample size.

Exercise 6 — Law of Large Numbers in action

Let \(X_i\) be independent Bernoulli variables with \(P(X_i=1)=0.3\).

  1. Plot the running mean \(\bar X_n\) for \(n=1,\ldots,10{,}000\).
  2. Repeat the experiment for 100 independent runs and compare the spread at \(n=10,100,1000,10{,}000\).
  3. Estimate \(P(|\bar X_n-0.3|>0.02)\) for each sample size.
  4. Explain what the LLN does and does not say about any single finite sample.

Exercise 7 — Sample means from a uniform population

Let \(X_1,\ldots,X_n\) be independent \(\operatorname{Uniform}(0,1)\) variables.

  1. Find \(E[\bar X_n]\) and \(\operatorname{Var}(\bar X_n)\).
  2. Use the CLT to approximate \(P(0.45<\bar X_{30}<0.55)\).
  3. Simulate the sampling distribution for \(n=2,10,30\).
  4. Compare the approximation with simulation and explain the effect of \(n\).
Answer

\(E[\bar X_n]=1/2\) and \(\operatorname{Var}(\bar X_n)=1/(12n)\). Standardise the bounds using standard error \(1/\sqrt{12n}\).

Exercise 8 — Accuracy of a rare-event estimate

Suppose a simulation estimates a probability \(p\approx0.001\) using the average of independent event indicators.

  1. Find the approximate standard error when \(n=10^4,10^5,10^6\).
  2. How large must \(n\) be for the standard error to be at most \(10^{-4}\)?
  3. Simulate the estimator repeatedly and inspect the number of runs producing no observed events.
  4. Explain why a large general-purpose sample size may still be inadequate for rare events.
Answer

The standard error is \(\sqrt{p(1-p)/n}\). Requiring it to be at most \(10^{-4}\) gives \(n\ge p(1-p)/10^{-8}\approx99{,}900\).