ECON 320 Lab Exercise — Week 8: Asymptotic Analysis¶
Name : [Your Name]
Lab Section: [Your Lab Section Here]
Code for week 8's attendance: NO ATTENDANCE CODE IS REQUIRED FOR THIS WEEK
Please submit the exercise on Canvas in form of a HTML/PDF file.¶
🧭 Instructions¶
Run and understand the provided code cells: they illustrate the Law of Large Numbers (LLN) and the Central Limit Theorem (CLT) in action.
(Feel free to change parameters like sample size or number of repetitions to explore how the results change!)
At the end, write a 2–3 sentence reflection summarizing what you learned from these experiments.
🎯 Learning Goals¶
Understand why asymptotic analysis matters for judging estimators.
See the Law of Large Numbers (LLN): sample averages converge to the true mean.
See the Central Limit Theorem (CLT): properly scaled sample averages become approximately normal.
🌱 Motivation: Why Asymptotic Analysis Matters?¶
Asymptotic analysis asks: What happens as the sample size gets very large?
Ideally, a good estimator may not perform well in small samples, but as the sample grows, it should behave better and better.
Asymptotic analysis formalizes this idea: we expect our estimator to
converge to the true value (consistency)
have a predictable distribution (asymptotic normality) that allows reliable inference when the sample is large.
!pip install numpy matplotlib --quiet
import numpy as np
import matplotlib.pyplot as plt
# For reproducibility (feel free to experiment with different seeds!)
rng = np.random.default_rng(320)
1️⃣ Law of Large Numbers (LLN)¶
📜 Formal (Weak) LLN¶
Let $X_1, X_2, \dots, X_n$ be i.i.d. with $\mathbb{E}[X_i]=\mu$ and $\operatorname{Var}(X_i)=\sigma^2<\infty$. Define the sample mean $\bar X_n = \frac{1}{n}\sum_{i=1}^n X_i$. Then $$ \bar X_n \xrightarrow{p} \mu \quad (n\to\infty). $$ That is, for any $\varepsilon>0$, $\Pr(|\bar X_n-\mu|>\varepsilon)\to 0$ as $n\to\infty$.
Intuition: averaging cancels noise; larger $n$ means smaller fluctuations around the truth.
🔬 LLN Experiment (Uniform[0,1])¶
In this experiment, we draw samples from a population that follows a Uniform(0, 1) distribution —
- every value between 0 and 1 is equally likely, and the true population mean is $\mu = 0.5$.
We will:
Randomly draw samples of different sizes ($n = 10, 100, 1000, 10000$).
Compute and record their sample means.
Observe how the sample means move closer to the true mean as $n$ grows.
This demonstrates the Law of Large Numbers —
- with larger samples, the sample mean becomes a more accurate estimate of the population mean.
(Feel free to try other populations, such as Normal or Exponential, and see how the results change!)
# --- LLN experiment: sample mean vs true mean ---
mu_true = 0.5 # True mean of U(0,1)
ns = [10, 100, 1000, 10000] # Different sample sizes
means = [] # Create an empty list to store sample means
for n in ns:
x = rng.uniform(0, 1, size=n) # Generate n samples from U(0,1)
means.append(float(np.mean(x))) # Compute and store the sample mean
for n, m in zip(ns, means): # Print results
print("n=", n, ", sample_mean=", m) # Formatted output
# Plotting the results (sample mean vs true mean)
plt.figure(figsize=(6,4))
plt.plot(ns, means, marker='o')
plt.axhline(mu_true, linestyle='--', color='r', label='True Mean (0.5)')
plt.xscale('log')
plt.xlabel('Sample size (log scale)')
plt.ylabel('Sample mean')
plt.title('LLN: Sample mean approaches true mean (0.5)')
plt.tight_layout()
plt.legend()
plt.show()
Observation: As $n$ grows, the sample mean stabilizes near $0.5$. This visualizes consistency.
2️⃣ Central Limit Theorem (CLT)¶
📜 Formal CLT¶
Let $X_1, X_2, \dots, X_n$ be i.i.d. with mean $\mu$ and variance $\sigma^2<\infty$. Then $$ \sqrt{n}\,\frac{\bar X_n - \mu}{\sigma} \xrightarrow{d} \mathcal{N}(0,1) \quad (n\to\infty). $$ Equivalently, $\bar X_n \approx \mathcal{N}(\mu, \tfrac{\sigma^2}{n})$ for large $n$.
Intuition: even if each $X_i$ is skewed or non-normal, the average becomes approximately normal when $n$ is big.
🔬 CLT Experiment (Exponential distribution)¶
In this experiment, we draw many sets of samples from a population that follows an Exponential(1) distribution —
- a right-skewed distribution with true mean $\mu = 1$.
We will:
Randomly draw many sets of samples (e.g., 3000 repetitions) for different sample sizes ($n = 5, 30, 100$).
Compute the sample mean for each set.
Plot the histogram of the sample means to see how the shape changes as $n$ increases.
This demonstrates the Central Limit Theorem (CLT) —
- even though the original population is skewed, the distribution of the sample mean becomes increasingly bell-shaped and centered around the true mean as the sample size grows.
(Feel free to try other populations, such as Uniform or Normal, to see how quickly the CLT kicks in!)
# --- CLT experiment: distribution of sample means ---
# Function to draw many set of samples and compute their means
def sample_means_exponential(size, reps=3000):
"""
Draw 'reps' sets of samples from Exponential(1), each of size 'size'.
For each set, compute the sample mean. Return all means as a NumPy array.
"""
means = [] # Empty list to store sample means
for r in range(reps):
# 1) Draw ONE sample (a set) of size 'size' from Exponential(1)
sample = rng.exponential(scale=1.0, size=size)
# 2) Compute the mean of this sample
m = sample.mean()
# 3) Store it
means.append(m)
return np.array(means)
# Try multiple sample sizes to see the CLT in action
sizes = [5, 30, 100]
for n in sizes:
# Get many sample means for this n
means = sample_means_exponential(size=n, reps=3000)
# Plot the histogram of the sample means
plt.figure(figsize=(5.2, 3.6))
plt.hist(means, bins=40, density=True, edgecolor='white')
# True mean of Exponential(1) is 1
plt.axvline(1.0, linestyle='--', color='r', label='True Mean (1.0)')
plt.title(f"Sampling distribution of the mean (Exponential, n={n})")
plt.xlabel("Sample mean")
plt.ylabel("Density")
plt.legend()
plt.tight_layout()
plt.show()
Observation: As $n$ increases from 5 → 30 → 100, the sampling distribution of the mean looks increasingly bell-shaped and more tightly concentrated around 1 (the true mean).
This is the CLT in action.
❓ “How big is big?”¶
There is no single magic number.
Heavier tails / more skew → need larger $n$ for a good approximation.
📝 Reflection (2–3 sentences)¶
How do the LLN and CLT together explain the idea of “better with more data”?
Why do these results give us confidence when using OLS or other estimators in large samples?
Put your reflection here:
End of Lab Exercise.