@@ -29,7 +29,7 @@ kernelspec:
2929:depth: 2
3030```
313132-In this quantecon lecture {doc}`A First Look at the Kalman filter <kalman>`, we used
32+In this QuantEcon lecture {doc}`kalman`, we used
3333a Kalman filter to estimate locations of a rocket.
34343535In this lecture, we'll use the Kalman filter to
@@ -38,7 +38,7 @@ human capital, neither of which the firm observes directly.
38383939The firm learns about those things only by observing a history of the output that the worker generates for the firm, and from understanding how that output depends on the worker's human capital and how human capital evolves as a function of the worker's effort.
404041-We'll posit a rule that expresses how the much firm pays the worker each period as a function of the firm's information each period.
41+We'll posit a rule that expresses how much the firm pays the worker each period as a function of the firm's information each period.
42424343In addition to what's in Anaconda, this lecture will need the following libraries:
4444@@ -48,7 +48,7 @@ In addition to what's in Anaconda, this lecture will need the following librarie
4848!pip install quantecon
4949```
505051-To conduct simulations, we bring in these imports, as in {doc}`A First Look at the Kalman filter <kalman>`.
51+To conduct simulations, we bring in these imports, as in {doc}`kalman`.
52525353```{code-cell} ipython3
5454import matplotlib.pyplot as plt
@@ -58,22 +58,22 @@ from collections import namedtuple
5858from scipy.stats import multivariate_normal
5959import matplotlib as mpl
6060mpl.rcParams['text.usetex'] = True
61-mpl.rcParams['text.latex.preamble'] = r'\usepackage{{amsmath}}'
61+mpl.rcParams['text.latex.preamble'] = r'\usepackage{amsmath,amsfonts}'
6262```
63636464## A worker's output
65656666A representative worker is permanently employed at a firm.
676768-The workers' output is described by the following dynamic process:
68+A worker's output is described by the following dynamic process:
69697070```{math}
7171:label: worker_model
72727373\begin{aligned}
74-h_{t+1} &= \alpha h_t + \beta u_t + c w_{t+1}, \quad c_{t+1} \sim {\mathcal N}(0,1) \\
74+h_{t+1} &= \alpha h_t + \beta u_t + c \epsilon_{t+1}, \quad \epsilon_{t+1} \sim N(0,1) \\
7575u_{t+1} & = u_t \\
76-y_t & = g h_t + v_t , \quad v_t \sim {\mathcal N} (0, R)
76+y_t & = g h_t + v_t , \quad v_t \sim N(0, R)
7777\end{aligned}
7878```
7979@@ -82,22 +82,23 @@ Here
8282* $h_t$ is the logarithm of human capital at time $t$
8383* $u_t$ is the logarithm of the worker's effort at accumulating human capital at $t$
8484* $y_t$ is the logarithm of the worker's output at time $t$
85-* $h_0 \sim {\mathcal N}(\hat h_0, \sigma_{h,0})$
86-* $u_0 \sim {\mathcal N}(\hat u_0, \sigma_{u,0})$
85+* $\epsilon_{t+1}$ is an IID standard normal shock to human capital
86+* $h_0 \sim N(\hat h_0, \sigma_{h,0})$
87+* $u_0 \sim N(\hat u_0, \sigma_{u,0})$
878888-Parameters of the model are $\alpha, \beta, c, R, g, \hat h_0, \hat u_0, \sigma_h, \sigma_u$.
89+Parameters of the model are $\alpha, \beta, c, R, g, \hat h_0, \hat u_0, \sigma_{h,0}, \sigma_{u,0}$.
89909091At time $0$, a firm has hired the worker.
91929293The worker is permanently attached to the firm and so works for the same firm at all dates $t =0, 1, 2, \ldots$.
93949495At the beginning of time $0$, the firm observes neither the worker's innate initial human capital $h_0$ nor its hard-wired permanent effort level $u_0$.
959696-The firm believes that $u_0$ for a particular worker is drawn from a Gaussian probability distribution, and so is described by $u_0 \sim {\mathcal N}(\hat u_0, \sigma_{u,0})$.
97+The firm believes that $u_0$ for a particular worker is drawn from a Gaussian probability distribution, and so is described by $u_0 \sim N(\hat u_0, \sigma_{u,0})$.
979898-The $h_t$ part of a worker's "type" moves over time, but the effort component of the worker's type is $u_t = u_0$.
99+The $h_t$ part of a worker's "type" moves over time, while the equation $u_{t+1} = u_t$ implies $u_t = u_0$ for all $t$.
99100100-This means that from the firm's point of view, the worker's effort is effectively an unknown fixed "parameter".
101+Thus, from the firm's point of view, effort is a fixed, unobserved component of the worker's type that must be inferred from output observations.
101102102103At time $t\geq 1$, for a particular worker the firm observed $y^{t-1} = [y_{t-1}, y_{t-2}, \ldots, y_0]$.
103104@@ -107,10 +108,10 @@ But the firm does observe the worker's output $y_t$ at time $t$ and remembers
107108108109## A firm's wage-setting policy
109110110-Based on information about the worker that the firm has at time $t \geq 1$, the firm pays the worker log wage
111+At time $t \geq 1$, before observing current output $y_t$, the firm sets the worker's log wage using the past output history $y^{t-1}$:
111112112113$$
113-w_t = g E [ h_t | y^{t-1} ], \quad t \geq 1
114+w_t = g \mathbb{E}[h_t | y^{t-1}], \quad t \geq 1
114115$$
115116116117and at time $0$ pays the worker a log wage equal to the unconditional mean of $y_0$:
@@ -129,7 +130,7 @@ Write system [](worker_model) in the state-space form
129130130131```{math}
131132\begin{aligned}
132-\begin{bmatrix} h_{t+1} \cr u_{t+1} \end{bmatrix} &= \begin{bmatrix} \alpha & \beta \cr 0 & 1 \end{bmatrix}\begin{bmatrix} h_{t} \cr u_{t} \end{bmatrix} + \begin{bmatrix} c \cr 0 \end{bmatrix} w_{t+1} \cr
133+\begin{bmatrix} h_{t+1} \cr u_{t+1} \end{bmatrix} &= \begin{bmatrix} \alpha & \beta \cr 0 & 1 \end{bmatrix}\begin{bmatrix} h_{t} \cr u_{t} \end{bmatrix} + \begin{bmatrix} c \cr 0 \end{bmatrix} \epsilon_{t+1} \cr
133134y_t & = \begin{bmatrix} g & 0 \end{bmatrix} \begin{bmatrix} h_{t} \cr u_{t} \end{bmatrix} + v_t
134135\end{aligned}
135136```
@@ -139,9 +140,9 @@ which is equivalent with
139140```{math}
140141:label: ssrepresent
141142\begin{aligned}
142-x_{t+1} & = A x_t + C w_{t+1} \cr
143+x_{t+1} & = A x_t + C \epsilon_{t+1} \cr
143144y_t & = G x_t + v_t \cr
144-x_0 & \sim {\mathcal N}(\hat x_0, \Sigma_0)
145+x_0 & \sim N(\hat x_0, \Sigma_0)
145146\end{aligned}
146147```
147148@@ -204,7 +205,7 @@ h_0, u_0 = x[0, 0], x[1, 0]
204205```
205206206207Next, to compute the firm's policy for setting the log wage based on the information it has about the worker,
207-we use the Kalman filter described in this quantecon lecture {doc}`A First Look at the Kalman filter <kalman>`.
208+we use the Kalman filter described in this QuantEcon lecture {doc}`kalman`.
208209209210In particular, we want to compute all of the objects in an "innovation representation".
210211@@ -246,26 +247,26 @@ x_hat_t = np.concatenate((x[:, 1][:, np.newaxis],
246247u_hat_t = x_hat_t[1, :]
247248```
248249249-For a draw of $h_0, u_0$, we plot $E y_t = G \hat x_t $ where $\hat x_t = E [x_t | y^{t-1}]$.
250+For a draw of $h_0, u_0$, we plot $\mathbb{E}[y_t | y^{t-1}] = G \hat x_t$ where $\hat x_t = \mathbb{E}[x_t | y^{t-1}]$.
250251251-We also plot $E [u_0 | y^{t-1}]$, which is the firm inference about a worker's hard-wired "work ethic" $u_0$, conditioned on information $y^{t-1}$ that it has about him or her coming into period $t$.
252+We also plot $\mathbb{E}[u_0 | y^{t-1}]$, which is the firm inference about a worker's hard-wired "work ethic" $u_0$, conditioned on information $y^{t-1}$ that it has about him or her coming into period $t$.
252253253-We can watch as the firm's inference $E [u_0 | y^{t-1}]$ of the worker's work ethic converges toward the hidden $u_0$, which is not directly observed by the firm.
254+We can watch as the firm's inference $\mathbb{E}[u_0 | y^{t-1}]$ of the worker's work ethic converges toward the hidden $u_0$, which is not directly observed by the firm.
254255255256```{code-cell} ipython3
256257fig, ax = plt.subplots(1, 2)
257258258-ax[0].plot(y_hat_t, label=r'$E[y_t| y^{t-1}]$')
259+ax[0].plot(y_hat_t, label=r'$\mathbb{E}[y_t| y^{t-1}]$')
259260ax[0].set_xlabel('Time')
260-ax[0].set_ylabel(r'$E[y_t]$')
261-ax[0].set_title(r'$E[y_t]$ over time')
261+ax[0].set_ylabel(r'$\mathbb{E}[y_t]$')
262+ax[0].set_title(r'$\mathbb{E}[y_t]$ over time')
262263ax[0].legend()
263264264-ax[1].plot(u_hat_t, label=r'$E[u_t|y^{t-1}]$')
265+ax[1].plot(u_hat_t, label=r'$\mathbb{E}[u_t|y^{t-1}]$')
265266ax[1].axhline(y=u_0, color='grey',
266267 linestyle='dashed', label=fr'$u_0={u_0:.2f}$')
267268ax[1].set_xlabel('Time')
268-ax[1].set_ylabel(r'$E[u_t|y^{t-1}]$')
269+ax[1].set_ylabel(r'$\mathbb{E}[u_t|y^{t-1}]$')
269270ax[1].set_title('Inferred work ethic over time')
270271ax[1].legend()
271272@@ -287,7 +288,7 @@ print(Σ_t[:, :, -1])
287288288289Evidently, entries in the conditional covariance matrix become smaller over time.
289290290-It is enlightening to portray how conditional covariance matrices $\Sigma_t$ evolve by plotting confidence ellipsoides around $E [x_t |y^{t-1}] $ at various $t$'s.
291+It is enlightening to portray how conditional covariance matrices $\Sigma_t$ evolve by plotting confidence ellipsoides around $\mathbb{E}[x_t | y^{t-1}]$ at various $t$'s.
291292292293```{code-cell} ipython3
293294# Create a grid of points for contour plotting
@@ -402,17 +403,17 @@ for t in range(1, T):
402403# Generate plots for y_hat_t and u_hat_t
403404fig, ax = plt.subplots(1, 2)
404405405-ax[0].plot(y_hat_t, label=r'$E[y_t| y^{t-1}]$')
406+ax[0].plot(y_hat_t, label=r'$\mathbb{E}[y_t| y^{t-1}]$')
406407ax[0].set_xlabel('Time')
407-ax[0].set_ylabel(r'$E[y_t]$')
408-ax[0].set_title(r'$E[y_t]$ over time')
408+ax[0].set_ylabel(r'$\mathbb{E}[y_t]$')
409+ax[0].set_title(r'$\mathbb{E}[y_t]$ over time')
409410ax[0].legend()
410411411-ax[1].plot(u_hat_t, label=r'$E[u_t|y^{t-1}]$')
412+ax[1].plot(u_hat_t, label=r'$\mathbb{E}[u_t|y^{t-1}]$')
412413ax[1].axhline(y=u_0, color='grey',
413414 linestyle='dashed', label=fr'$u_0={u_0:.2f}$')
414415ax[1].set_xlabel('Time')
415-ax[1].set_ylabel(r'$E[u_t|y^{t-1}]$')
416+ax[1].set_ylabel(r'$\mathbb{E}[u_t|y^{t-1}]$')
416417ax[1].set_title('Inferred work ethic over time')
417418ax[1].legend()
418419@@ -481,11 +482,11 @@ def simulate_workers(worker, T, ax, mu_0=None, Sigma_0=None,
481482 ax.plot(u_hat_t - u_0, alpha=.5)
482483 ax.axhline(y=0, color='grey', linestyle='dashed')
483484 ax.set_xlabel('Time')
484- ax.set_ylabel(r'$E[u_t|y^{t-1}] - u_0$')
485+ ax.set_ylabel(r'$\mathbb{E}[u_t|y^{t-1}] - u_0$')
485486 ax.set_title(title)
486487487488 else:
488- label_line = (r'$E[u_t|y^{t-1}]$' if name is None
489+ label_line = (r'$\mathbb{E}[u_t|y^{t-1}]$' if name is None
489490 else name)
490491 title = ('Inferred work ethic over time'
491492 if title is None else title)
@@ -494,7 +495,7 @@ def simulate_workers(worker, T, ax, mu_0=None, Sigma_0=None,
494495 ax.axhline(y=u_0, color=u_hat_plot[0].get_color(),
495496 linestyle='dashed', alpha=0.5)
496497 ax.set_xlabel('Time')
497- ax.set_ylabel(r'$E[u_t|y^{t-1}]$')
498+ ax.set_ylabel(r'$\mathbb{E}[u_t|y^{t-1}]$')
498499 ax.set_title(title)
499500```
500501