Skip to content

Commit 06c00cb

Browse files
Jiarui-ZHmmckyjstacclaude
authored
Update made to Markov Chains: Basic Concepts lecture (#479)
* Update made to Markov Chains: Basic Concepts lecture * update to markov chain I lecture * cross-sectional frequency explaination added * change prf to ref * [markov_chain_I] Move example subsections to sphinx-proof examples * minor update * fix syntax for example * final update to usage of syntax for example * removing an error * Fix minor typos in markov_chains_I - Add missing space: "distribution(probability mass function)" → "distribution (probability mass function)" - Fix label typo: prob-recesession → prob-recession Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Restore animation description and add label to third prf:example - Revert the description of the 3D simplex animation back to its original form. The PR had rewritten it to describe a single ψ₀ in red with a black stationary distribution, but the actual animation code (lines 845-882) still plots three distributions (blue, red, green) with the stationary distribution in yellow. Restoring the description so it matches the figure. - Add 🏷️ to the Steady-State Unemployment Probability example for consistency with the other two prf:example blocks. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: mmcky <mamckay@gmail.com> Co-authored-by: Matt McKay <mmcky@users.noreply.github.com> Co-authored-by: John Stachurski <john.stachurski@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 93e507e commit 06c00cb

1 file changed

Lines changed: 65 additions & 52 deletions

File tree

‎lectures/markov_chains_I.md‎

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.4
7+
jupytext_version: 1.16.1
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -78,7 +78,7 @@ nonnegative $n$-vector $p$ that sums to one.
7878
For example, $p = (0.2, 0.2, 0.6)$ is a probability mass function over $3$ outcomes.
7979

8080
A **stochastic matrix** (or **Markov matrix**) is an $n \times n$ square matrix $P$
81-
such that each row of $P$ is a probability mass function over $n$ outcomes.
81+
such that each row of $P$ is a probability mass function.
8282

8383
In other words,
8484

@@ -98,7 +98,7 @@ Before defining a Markov chain rigorously, we'll give some examples.
9898

9999

100100
(mc_eg2)=
101-
#### Example 1
101+
#### Example 1: Economic states
102102

103103
From US unemployment data, Hamilton {cite}`Hamilton2005` estimated the following dynamics.
104104

@@ -174,7 +174,7 @@ In particular, $P(i,j)$ is the
174174

175175

176176
(mc_eg1)=
177-
#### Example 2
177+
#### Example 2: Unemployment
178178

179179
Consider a worker who, at any given time $t$, is either unemployed (state 0)
180180
or employed (state 1).
@@ -222,7 +222,7 @@ Then we can address a range of questions, such as
222222
We'll cover some of these applications below.
223223

224224
(mc_eg3)=
225-
#### Example 3
225+
#### Example 3: Political transition dynamics
226226

227227
Imam and Temple {cite}`imampolitical` categorize political institutions into
228228
three types: democracy $\text{(D)}$, autocracy $\text{(A)}$, and an intermediate
@@ -233,17 +233,17 @@ Each institution can have two potential development regimes: collapse $\text{(C)
233233
Imam and Temple {cite}`imampolitical` estimate the following transition
234234
probabilities:
235235

236-
237236
$$
238-
P :=
239-
\begin{bmatrix}
240-
0.86 & 0.11 & 0.03 & 0.00 & 0.00 & 0.00 \\
241-
0.52 & 0.33 & 0.13 & 0.02 & 0.00 & 0.00 \\
242-
0.12 & 0.03 & 0.70 & 0.11 & 0.03 & 0.01 \\
243-
0.13 & 0.02 & 0.35 & 0.36 & 0.10 & 0.04 \\
244-
0.00 & 0.00 & 0.09 & 0.11 & 0.55 & 0.25 \\
245-
0.00 & 0.00 & 0.09 & 0.15 & 0.26 & 0.50
246-
\end{bmatrix}
237+
\begin{array}{c|cccccc}
238+
& \text{DG} & \text{DC} & \text{NG} & \text{NC} & \text{AG} & \text{AC} \\
239+
\hline
240+
\text{DG} & 0.86 & 0.11 & 0.03 & 0.00 & 0.00 & 0.00 \\
241+
\text{DC} & 0.52 & 0.33 & 0.13 & 0.02 & 0.00 & 0.00 \\
242+
\text{NG} & 0.12 & 0.03 & 0.70 & 0.11 & 0.03 & 0.01 \\
243+
\text{NC} & 0.13 & 0.02 & 0.35 & 0.36 & 0.10 & 0.04 \\
244+
\text{AG} & 0.00 & 0.00 & 0.09 & 0.11 & 0.55 & 0.25 \\
245+
\text{AC} & 0.00 & 0.00 & 0.09 & 0.15 & 0.26 & 0.50 \\
246+
\end{array}
247247
$$
248248

249249
```{code-cell} ipython3
@@ -287,6 +287,20 @@ plt.colorbar(pc, ax=ax)
287287
plt.show()
288288
```
289289

290+
The probabilities can be represented in matrix form as follows
291+
292+
$$
293+
P :=
294+
\begin{bmatrix}
295+
0.86 & 0.11 & 0.03 & 0.00 & 0.00 & 0.00 \\
296+
0.52 & 0.33 & 0.13 & 0.02 & 0.00 & 0.00 \\
297+
0.12 & 0.03 & 0.70 & 0.11 & 0.03 & 0.01 \\
298+
0.13 & 0.02 & 0.35 & 0.36 & 0.10 & 0.04 \\
299+
0.00 & 0.00 & 0.09 & 0.11 & 0.55 & 0.25 \\
300+
0.00 & 0.00 & 0.09 & 0.15 & 0.26 & 0.50
301+
\end{bmatrix}
302+
$$
303+
290304
Looking at the data, we see that democracies tend to have longer-lasting growth
291305
regimes compared to autocracies (as indicated by the lower probability of
292306
transitioning from growth to growth in autocracies).
@@ -310,7 +324,7 @@ A **distribution** $\psi$ on $S$ is a probability mass function of length $n$, w
310324
A **Markov chain** $\{X_t\}$ on $S$ is a sequence of random variables taking values in $S$
311325
that have the **Markov property**.
312326

313-
This means that, for any date $t$ and any state $y \in S$,
327+
This means that, for any time $t$ and any state $y \in S$,
314328

315329
```{math}
316330
:label: fin_markov_mp
@@ -333,7 +347,7 @@ P(x, y) := \mathbb P \{ X_{t+1} = y \,|\, X_t = x \}
333347
By construction,
334348

335349
* $P(x, y)$ is the probability of going from $x$ to $y$ in one unit of time (one step)
336-
* $P(x, \cdot)$ is the conditional distribution of $X_{t+1}$ given $X_t = x$
350+
* $P(x, \cdot)$ is the conditional distribution (probability mass function) of $X_{t+1}$ given $X_t = x$
337351

338352
We can view $P$ as a stochastic matrix where
339353

@@ -439,7 +453,7 @@ Here's a short time series.
439453
mc_sample_path(P, ψ_0=(1.0, 0.0), ts_length=10)
440454
```
441455

442-
It can be shown that for a long series drawn from `P`, the fraction of the
456+
It can be proven that for a long series drawn from `P`, the fraction of the
443457
sample that takes value 0 will be about 0.25.
444458

445459
(We will explain why {ref}`later <ergodicity>`.)
@@ -607,39 +621,40 @@ $$
607621
$$
608622

609623

610-
### Example: probability of recession
611-
612624
```{index} single: Markov Chains; Future Probabilities
613625
```
614626

615-
Recall the stochastic matrix $P$ for recession and growth {ref}`considered above <mc_eg2>`.
627+
```{prf:example} Probability of Recession
628+
:label: prob-recession
629+
630+
Recall the stochastic matrix $P$ for recession and growth considered in {ref}`Example 1: Economic states <mc_eg2>`.
616631
617-
Suppose that the current state is unknown --- perhaps statistics are available only at the *end* of the current month.
632+
Suppose that the current state is unknown — perhaps statistics are available only at the *end* of the current month.
618633
619-
We guess that the probability that the economy is in state $x$ is $\psi_t(x)$ at time t.
634+
We guess that the probability that the economy is in state $x$ is $\psi_t(x)$ at time $t$.
620635
621-
The probability of being in recession (either mild or severe) in 6 months time is given by
636+
The probability of being in recession (either mild or severe) in 6 months' time is given by
622637
623638
$$
624639
(\psi_t P^6)(1) + (\psi_t P^6)(2)
625640
$$
626641
642+
```
627643

644+
```{index} single: Markov Chains; Cross-Sectional Distributions
645+
```
628646

629-
(mc_eg1-1)=
630-
### Example 2: cross-sectional distributions
647+
````{prf:example} Cross-Sectional Distributions
648+
:label: cross-sectional-distributions
631649
632650
The distributions we have been studying can be viewed either
633651
634652
1. as probabilities or
635-
1. as cross-sectional frequencies that the law of large numbers leads us to anticipate for large samples.
653+
2. as cross-sectional frequencies that the law of large numbers leads us to anticipate for large samples.
636654
637-
To illustrate, recall our model of employment/unemployment dynamics for a given worker {ref}`discussed above <mc_eg1>`.
655+
To illustrate, recall our model of employment/unemployment dynamics for a given worker discussed in {ref}`Example 2: Unemployment <mc_eg1>`.
638656
639-
Consider a large population of workers, each of whose lifetime experience is
640-
described by the specified dynamics, with each worker's outcomes being
641-
realizations of processes that are statistically independent of all other
642-
workers' processes.
657+
Consider a large population of workers, each of whose lifetime experience is described by the specified dynamics, with each worker's outcomes being realizations of processes that are statistically independent of all other workers' processes.
643658
644659
Let $\psi_t$ be the current *cross-sectional* distribution over $\{ 0, 1 \}$.
645660
@@ -649,26 +664,25 @@ The cross-sectional distribution records fractions of workers employed and unemp
649664
650665
What will the cross-sectional distribution be in 10 periods hence?
651666
652-
The answer is $\psi_t P^{10}$, where $P$ is the stochastic matrix in
653-
{eq}`p_unempemp`.
667+
The answer is $\psi_t P^{10}$, where $P$ is the stochastic matrix in {eq}`p_unempemp`.
654668
655-
This is because each worker's state evolves according to $P$, so
656-
$\psi_t P^{10}$ is a [marginal distribution](https://en.wikipedia.org/wiki/Marginal_distribution) for a single randomly selected
657-
worker.
669+
This is because each worker's state evolves according to $P$, so $\psi_t P^{10}$ is a [marginal distribution](https://en.wikipedia.org/wiki/Marginal_distribution) for a single randomly selected worker.
658670
659-
But when the sample is large, outcomes and probabilities are roughly equal (by an application of the law
660-
of large numbers).
671+
But when the sample is large, outcomes and probabilities are roughly equal (by an application of the law of large numbers).
661672
662-
So for a very large (tending to infinite) population,
663-
$\psi_t P^{10}$ also represents fractions of workers in
664-
each state.
673+
So for a very large (tending to infinite) population, $\psi_t P^{10}$ also represents fractions of workers in each state.
665674
666675
This is exactly the cross-sectional distribution.
667676
677+
```{note}
678+
A cross-sectional frequency measures how a particular variable (e.g., employment status) is distributed across a population at a specific time, providing information on the proportions of individuals in each possible state of that variable.
679+
```
680+
681+
````
682+
668683
(stationary)=
669684
## Stationary distributions
670685

671-
672686
As seen in {eq}`fin_mc_fr`, we can shift a distribution forward one
673687
unit of time via postmultiplication by $P$.
674688

@@ -683,8 +697,6 @@ P = np.array([[0.4, 0.6],
683697

684698
Notice that `ψ @ P` is the same as `ψ`.
685699

686-
687-
688700
Such distributions are called **stationary** or **invariant**.
689701

690702
(mc_stat_dd)=
@@ -725,10 +737,10 @@ distribution.
725737
We will come back to this when we introduce irreducibility in the {doc}`next lecture <markov_chains_II>` on Markov chains.
726738

727739

740+
```{prf:example} Steady-State Unemployment Probability
741+
:label: steady-state-unemployment
728742
729-
### Example
730-
731-
Recall our model of the employment/unemployment dynamics of a particular worker {ref}`discussed above <mc_eg1>`.
743+
Recall our model of the employment/unemployment dynamics of a particular worker discussed in {ref}`Example 2: Unemployment <mc_eg1>`.
732744
733745
If $\alpha \in (0,1)$ and $\beta \in (0,1)$, then the transition matrix is everywhere positive.
734746
@@ -738,12 +750,13 @@ corresponds to unemployment (state 0).
738750
Using $\psi^* = \psi^* P$ and a bit of algebra yields
739751
740752
$$
741-
p = \frac{\beta}{\alpha + \beta}
753+
p = \frac{\beta}{\alpha + \beta}
742754
$$
743755
744756
This is, in some sense, a steady state probability of unemployment.
745757
746758
Not surprisingly it tends to zero as $\beta \to 0$, and to one as $\alpha \to 0$.
759+
```
747760

748761

749762

@@ -879,9 +892,9 @@ HTML(anim.to_jshtml())
879892

880893
Here
881894

882-
* $P$ is the stochastic matrix for recession and growth {ref}`considered above <mc_eg2>`.
883-
* The red, blue and green dots are initial marginal probability distributions $\psi_1, \psi_2, \psi_3$, each of which is represented as a vector in $\mathbb R^3$.
884-
* The transparent dots are the marginal distributions $\psi_i P^t$ for $t = 1, 2, \ldots$, for $i=1,2,3.$.
895+
* $P$ is the stochastic matrix for recession and growth considered in {ref}`Example 1: Economic states <mc_eg2>`.
896+
* The red, blue and green dots are initial marginal probability distributions $\psi_1, \psi_2, \psi_3$, each of which is represented as a vector in $\mathbb R^3$.
897+
* The transparent dots are the marginal distributions $\psi_i P^t$ for $t = 1, 2, \ldots$, for $i=1,2,3.$
885898
* The yellow dot is $\psi^*$.
886899

887900
You might like to try experimenting with different initial conditions.

0 commit comments

Comments
 (0)