140140Let $\mu$ denote the common mean of this sample:
141141
142142$$
143- \mu := \mathbb E X = \int_{-\infty}^{\infty} x f(dx)
143+ \mu := \mathbb E X = \int_{-\infty}^{\infty} x f(x) dx
144144$$
145145
146146In addition, let
@@ -228,7 +228,7 @@ def generate_histogram(X_distribution, n, m):
228228 ax.axvline(x=mu, ls="--", lw=3, label=fr"$\mu = {mu}$")
229229
230230 ax.set_xlim(min(sample_means), max(sample_means))
231- ax.set_xlabel(r'$\bar x $', size=12)
231+ ax.set_xlabel(r'$\bar X_n $', size=12)
232232 ax.set_ylabel('density', size=12)
233233 ax.legend()
234234 plt.show()
@@ -263,14 +263,16 @@ def generate_multiple_hist(X_distribution, ns, m, log_scale=False):
263263 ax.axvline(x=mu, ls="--", lw=3, label=fr"$\mu = {mu}$")
264264
265265 ax.set_xlim(min(sample_means), max(sample_means))
266- ax.set_xlabel(r'$\bar x $', size=12)
266+ ax.set_xlabel(r'$\bar X_n $', size=12)
267267 ax.set_ylabel('density', size=12)
268268 ax.legend()
269269 plt.show()
270270```
271271
272272``` {code-cell} ipython3
273- generate_multiple_hist(st.norm(loc=5, scale=2), ns=[20_000, 50_000, 100_000], m=10_000)
273+ generate_multiple_hist(st.norm(loc=5, scale=2),
274+ ns=[20_000, 50_000, 100_000],
275+ m=10_000)
274276```
275277
276278The histogram gradually converges to $\mu$ as the sample size n increases.
@@ -305,7 +307,7 @@ def scattered_mean(distribution, burn_in, n, jump, ax, title, color, ylog=False)
305307 ax.set_yscale("symlog")
306308 ax.set_title(title, size=10)
307309 ax.set_xlabel(r"$n$", size=12)
308- ax.set_ylabel(r"$\bar x $", size=12)
310+ ax.set_ylabel(r"$\bar X_n $", size=12)
309311 yabs_max = max(ax.get_ylim())
310312 ax.set_ylim(ymin=-yabs_max, ymax=yabs_max)
311313 return ax
@@ -340,7 +342,7 @@ Let's go through a very simple example where LLN fails with IID violated:
340342Assume
341343
342344$$
343- X_0 \sim \mathcal{N} (0,1)
345+ X_0 \sim N (0,1)
344346$$
345347
346348In addition, assume
352354We can then see that
353355
354356$$
355- \bar X_n := \frac{1}{n} \sum_{t=1}^n X_i = X_0 \sim \mathcal{N} (0,1)
357+ \bar X_n := \frac{1}{n} \sum_{t=1}^n X_i = X_0 \sim N (0,1)
356358$$
357359
358- Therefore, the distribution of the mean of $X$ follows $\mathcal{N} (0,1)$.
360+ Therefore, the distribution of the mean of $X$ follows $N (0,1)$.
359361
360362However,
361363
@@ -452,8 +454,9 @@ xmin, xmax = -3 * σ, 3 * σ
452454ax.set_xlim(xmin, xmax)
453455ax.hist(Y, bins=60, alpha=0.4, density=True)
454456xgrid = np.linspace(xmin, xmax, 200)
455- ax.plot(xgrid, st.norm.pdf(xgrid, scale=σ), 'k-', lw=2, label='$N(0, \sigma^2)$')
456- ax.set_xlabel(r"$Y$", size=12)
457+ ax.plot(xgrid, st.norm.pdf(xgrid, scale=σ),
458+ 'k-', lw=2, label='$N(0, \sigma^2)$')
459+ ax.set_xlabel(r"$Y_n$", size=12)
457460ax.set_ylabel(r"$density$", size=12)
458461
459462ax.legend()
@@ -501,7 +504,7 @@ fig, ax = plt.subplots(figsize=(10, 6))
501504xmin, xmax = -3 * σ, 3 * σ
502505ax.set_xlim(xmin, xmax)
503506ax.hist(Y, bins=60, alpha=0.4, density=True)
504- ax.set_xlabel(r"$Y $", size=12)
507+ ax.set_xlabel(r"$Y_n $", size=12)
505508ax.set_ylabel(r"$density$", size=12)
506509xgrid = np.linspace(xmin, xmax, 200)
507510ax.plot(xgrid, st.norm.pdf(xgrid, scale=σ), 'k-', lw=2, label='$N(0, \sigma^2)$')
@@ -554,15 +557,18 @@ We mentioned above that LLN can still hold sometimes when IID is violated.
554557Let's investigate this claim further.
555558
556559Assume we have a AR(1) process as below:
560+
557561$$
558562X_{t+1} = \alpha + \beta X_t + \sigma \epsilon _{t+1}
559563$$
560564
565+ and
566+
561567$$
562- X_0 \sim \mathcal{N} \left(\frac{\alpha}{1-\beta}, \frac{\sigma^2}{1-\beta^2}\right)
568+ X_0 \sim N \left(\frac{\alpha}{1-\beta}, \frac{\sigma^2}{1-\beta^2}\right)
563569$$
564570
565- where $\epsilon_t \sim \mathcal{N} (0,1)$
571+ where $\epsilon_t \sim N (0,1)$
566572
5675731. Prove this process violated the independence assumption but not the identically distributed assumption;
5685742. Show LLN holds using simulations with $\alpha = 0.8$, $\beta = 0.2$.
592598
593599$$
594600\begin{aligned}
595- Var(X_t+1 ) &= \beta^2 Var(X_{t}) + \sigma^2\\
601+ \mathrm{ Var}(X_{t+1} ) &= \beta^2 \mathrm{ Var} (X_{t}) + \sigma^2\\
596602&= \frac{\beta^2\sigma^2}{1-\beta^2} + \sigma^2 \\
597603&= \frac{\sigma^2}{1-\beta^2}
598604\end{aligned}
@@ -607,7 +613,7 @@ This holds true for all $X_t$ and $\epsilon _{t}$ where $t = 0, ..., n$
607613Therefore,
608614
609615$$
610- X_t \sim \mathcal{N} \left(\frac{\alpha}{1-\beta}, \frac{\sigma^2}{1-\beta^2}\right) \quad t = 0, ..., n
616+ X_t \sim N \left(\frac{\alpha}{1-\beta}, \frac{\sigma^2}{1-\beta^2}\right) \quad t = 0, ..., n
611617$$
612618
613619
@@ -635,9 +641,11 @@ for t in range(n-1):
635641ax.scatter(range(100, n), means[100:n], s=10, alpha=0.5)
636642
637643ax.set_xlabel(r"$n$", size=12)
638- ax.set_ylabel(r"$\bar x $", size=12)
644+ ax.set_ylabel(r"$\bar X_n $", size=12)
639645yabs_max = max(ax.get_ylim(), key=abs)
640- ax.axhline(y=α/(1-β), ls="--", lw=3, label=r"$\mu = \frac{\alpha}{1-\beta}$",color = 'black')
646+ ax.axhline(y=α/(1-β), ls="--", lw=3,
647+ label=r"$\mu = \frac{\alpha}{1-\beta}$",
648+ color = 'black')
641649
642650plt.legend()
643651plt.show()
0 commit comments