🎯 Objective: any P((X1,…,Xp)∈Z) ➔ simulate m draws ➔ average the indicators ➔ WLLN guarantees convergence ➔ answers problems with no closed form.
📦 Core Components: generate ➔ check I(⋅∈Z) ➔ average ➔ converge | resolution1/m ➔ need m≫1/p.
⚡ Key Constraint: an event rarer than 1/m is usually never observed ⟹ estimate =0; size m so the event is expected many times.
📝 How It Works
1. The General Problem
Target ➔ RVs X1,…,Xp∈X and a set Z⊆Xp ➔ find P((X1,…,Xp)∈Z).
Hard by hand ➔ X1,X2∼N(0,1): P(∣X1∣+∣X2∣>2) · X1∼Poi(λ1), X2∼Poi(λ2): P(X1−X23/2>0) ➔ answerable analytically but hard; trivial to pose ones that are impossible. Simulation always gives an answer.
Generate ➔ (X1(i),…,Xp(i)) from their joint distribution, i=1,…,m.
Check ➔ I((X1(i),…,Xp(i))∈Z)=1 if the condition holds, 0 otherwise.
Average ➔ θ^m=m1∑i=1mI((X1(i),…,Xp(i))∈Z) — the empirical probability.
Converge ➔ larger m ⟹ more accurate.
3. Resolution and Rare Events
Resolution ➔ 1/m = the smallest non-zero probability the estimate can take; the estimate moves in steps of 1/m.
Rare events ➔ p<1/m cannot be estimated well ⟹ choose m≫1/p.
Break Q1 ➔ event seen 23 times in m=1000 ⟹ p^=0.023; p^→p as m→∞.
4. Beyond Probabilities
Any distribution summary ➔ x=m draws from p(x): E[X]≈mean(x) · V[X]≈var(x) · Q(0.2)≈quantile(x, 0.2) · p(x)≈hist(x, probability = TRUE) ➔ all sharpen as m grows.
🧮 Proof Blueprint
Theorem ➔ θ^m=m1∑i=1mI(X(i)∈Z)→θ=P(X∈Z) as m→∞.
Strategy ➔ each indicator is a Bernoulli RV ⟹ θ^m is a sample mean ⟹ WLLN.
Derivation Steps:
Biθ^mθ^m=I(X(i)∈Z)∈{0,1},P(Bi=1)=P(X∈Z)=θ⇒Bi∼iidBe(θ)=m1i=1∑mBi(the mean of m Bernoulli RVs)→E[Bi]=θas m→∞(weak law of large numbers)
Q.E.D. ➔ the empirical probability is consistent for θ; being a Bernoulli mean, its variance is θ(1−θ)/m (Studio 4 drill) — why small-m runs wobble.
⚙️ Core Implementation
🔹 Monte Carlo in two lines of R
Code / Layout Details
X = rnorm(m, 0, 1) # m draws of X ~ N(0,1)mean(sqrt(abs(X)) > 1) # logical vector -> mean = proportion TRUE = empirical probability
💡 Common Mistake:hist(x, Probability = T) as printed on the slide ➔ R’s argument is lowercase probability (or freq = FALSE); the capitalised name is not matched and the y-axis stays as counts.
📊 Exam Execution Trace & Applied Exercises
Manual Execution Trace
X∼N(0,1), target P(∣X∣>1):
m
Resolution 1/m
Estimate
100
0.01
0.3300
1,000
0.001
0.3310
10,000
0.0001
0.3179
100,000
0.00001
0.3176
109
10−9
0.3172
Reading ➔ convergence is not monotone (m=1000 is no closer than m=100) — each run is random; only the typical error shrinks.
Applied Exercise
Problem: derive the exact value the simulation chases: X∼N(0,1), Q=∣X∣, find P(Q>1) — the slide’s CDF route, then the shortcut.
Final Extracted Output:P(Q>1)≈0.317. The slides print 0.3171; 1−erf(1/2)=0.31731 — a rounding slip on the slide, and the 109 run (0.3172) agrees with 0.3173 to within simulation error.
⚠️ Common Mistakes
💡 m too small for a rare event ➔ p^=0 is not evidence that p=0; it means p≲1/m.
💡 Sampling each Xj from the wrong law ➔ draw from the joint distribution; independent marginals are only valid when the Xj are independent.
💡 No seed ➔ the estimate changes every run; set.seed() first when the number must be reproduced (Pseudo-Random Number Generators).
🧠 Active Recall
Why does the proportion of simulated draws landing in Z converge to P(X∈Z)?
Answer
Short answer: each indicator is a Be(θ) RV with θ=P(X∈Z), so the proportion is a sample mean, which the WLLN sends to θ.
Why:Indicator ➔ Bernoulli ➔ WLLN ➔ m1∑I(X(i)∈Z)→E[I]=θ as m→∞.
You need P(A)≈10−5 and simulate m=104 times. What goes wrong, and what m do you need?
Answer
Short answer: the expected count is mp=0.1, so the estimate is almost always 0 — below the resolution 1/m=10−4; take m≫105 (e.g. 107, expecting ≈100 hits).
Why:Resolution ➔ the estimate lives on the grid {0,m1,m2,…}; it can only resolve p once the event is observed many times.