Math5846_chapter8
Math5846_chapter8
UNSW Sydney
OPEN LEARNING
Chapter 8 Markov Chains
2 / 101
Outline:
3 / 101
The source of this chapter is Ross, S.M. (2023) Introduction to Probability
Models, 13th Edition, Academic Press (Elsevier), California, U.S.A.
4 / 101
8.1 Introduction to Stochastic
Processes
5 / 101
Definition
A stochastic (or random) process {X(t), t ≥ 0} is a family (or
collection of random variables.
That is, for all t contained in the index set T , X(t) is a random variable.
6 / 101
You can think of X(t) as
the position of a particle at time t
the number of people going to the library at time t
the amount of fish in the ocean at time t, etc. .
The set of possible values which the random variable X(t), t ∈ T , may
take is called the state space of the process.
7 / 101
A continuous-time stochastic process {X(t), t ≥ 0} has
independent increments if for all choices
are independent;
8 / 101
Example
{Xn , n = 0, 1, 2, 3, . . . }
9 / 101
Example
A stochastic process {X(t), t ≥ 0} is said to be a Brownian motion
(BM) if
X(0) = 0
for every t > 0, X(t) is normally distributed with mean zero and
variance σ 2 t.
10 / 101
The general random walk and Brownian motion are examples of a class of
stochastic processes known as Markov processes.
Definition
The process {X(t), t ≥ 0} is a Markov Process if
P X(t) ≤ x X(t1 ) = x1 , X(t2 ) = x2 , . . . , X(tn ) = xn = P X(t) ≤ x X(tn ) = xn
11 / 101
8.1.1 Four Main Types of Stochastic Processes
12 / 101
discrete-time discrete-state stochastic processes, for example,
discrete-time Markov chains, Branching processes
13 / 101
8.1.2 Applications of Stochastic Processes
14 / 101
Finance: stock price movements ↭ Brownian motion, Itô’s formula;
volatility ↭ Gaussian processes; options ↭ Levy processes
15 / 101
Medicine: the spread of diseases ↭ birth and death process; the
number of bacteria and/or red blood cells in a drop of blood ↭ Poisson
process
16 / 101
8.2 Markov Chains
17 / 101
Definition
A stochastic process {Xn , n = 0, 1, . . . } with a finite or countable state is a
Markov chain if for all states i0 , i1 , . . . , in−1 , i, j and all n ≥ 0
18 / 101
This course will focus on Markov chains, which have stationary transition
probabilities.
Let Pij = P(Xn+1 = j|Xn = i), one step transition probability that one has
moved to state j at time n + 1 given that one was in state i at time n.
Notation: We will label the state space of the process by the positive
integers {0, 1, 2, . . . , } unless otherwise stated.
19 / 101
Write P to be the matrix of one-step transition probabilities Pij :
20 / 101
Since we consider the Pij ’s as probabilities, we require that
Pij ≥ 0, i, j = 0, 1, 2, . . .
and
∞
X
Pij = 1 for i = 0, 1, 2, . . . .
j=0
It turns out the process X is completely specified once P and the initial
distributions of X are known.
21 / 101
To see this, consider the following:
P(X0 = i0 , X1 = i1 , . . . , Xn = in )
= P(Xn = in |X0 = i0 , . . . , Xn−1 = in−1 )P(X0 = i0 , . . . , Xn−1 = in−1 )
= Pin−1 ,in P(X0 = i0 , . . . , Xn−1 = in−1 ) by the Markov property
= Pin−1 ,in Pin−2 ,in−1 P(X0 = i0 , . . . , Xn−1 = in−2 )
..
.
= Pin−1 ,in Pin−2 ,in−1 · · · Pi0 ,i1 P(X0 = i0 ),
22 / 101
Example
Random Walk Model
··· −2 −1 0 1 2 ···
(
1
with probability p
You can think that Yi = , where the Yi , i = 0, ±1, ±2, . . . are independent and identically
−1
with probability 1 − p
Pn
distributed. Hence the random walk is Xn = i=1 Yi .
23 / 101
Example
Gambling Model
Further, suppose that this gambler stops playing when she has no money left,
or she has $N. Then the gambler’s fortune is a Markov chain with transition
probabilities given by
P00 = PN N = 1.
24 / 101
Example
The states 0 and N are known as absorbing states because once you reach
that state, you can’t leave (i.e. you are fixed there for life.).
Hence, the gambler’s fortune is a finite state random variable with absorbing
states 0 and N . We will discuss absorbing states in detail later on.
p p p p
1 0 1 2 ··· N −1 N 1
1−p 1−p 1−p 1−p
25 / 101
8.2.1 Chapman-Kolmogorov Equations
26 / 101
Recall that we established
Write Pijn as the probability of the process going from state i to state j in n
steps. That is,
27 / 101
Chapman-Kolmogorov Equations
For any r ≤ n,
∞
X
n−r
Pijn = Pikr Pkj . (2)
k=0
28 / 101
If we let P(n) denote the matrix of n- step transition probability Pijn , then
That is, the n-step transition matrix is the nth power of the one-step
transition matrix.
29 / 101
Example
Ticks of Stocks
Traders of a stock pay close attention to the ticks of a stock. A stock can
trade on an uptick, even tick or downtick, if the price is higher, the same or
lower than the previous price, respectively.
For a particular stock, traders observed that the ticks could be modelled
using a Markov chain.
For example, they observed that following an even tick, the next trade price
was an even tick with a probability of 0.6, an uptick with a probability of 0.2
and a downtick with a probability of 0.2.
30 / 101
Example
Suppose that the states are 0,1,2 if the previous trade price is a downtick, an
even tick and an uptick, respectively.
Find the state transition matrix P , the 2-step transition matrix, and the n
step transition matrix, when n = 20, for example.
31 / 101
Example
Solution:
First we will state the states of the Markov chain:
state 0 will be downtick
state 1 will be an even tick
state 2 will be an uptick.
0.6 0.2
0.4 0 1 2 0.4
0.2 0.6
0.6
32 / 101
Example
Solution - continued:
The one-step transition matrix is
0.4 0.6 0
P = 0.2 0.6 0.2 .
0 0.6 0.4
The second-step transition matrix is
P(2) ·P
= P
0.4 0.6 0 0.4 0.6 0
= 0.2 0.6 0.2 · 0.2 0.6 0.2
0 0.6 0.4 0 0.6 0.4
0.28 0.6 0.12
= 0.2 0.6 0.2 .
0.12 0.6 0.28
33 / 101
Example
Solution - continued:
The twenty-step transition matrix is
0.2 0.6 0.2
P(20) = P20 = 0.2 0.6 0.2 .
0.2 0.6 0.2
34 / 101
Notation
We can also determine the probability of the process being in state j at time
time n by
∞
X
n
P(Xn = j) = αk Pkj .
k=0
35 / 101
Example
Suppose a Markov chain X0 , X1 , . . . has the transition probability matrix
0.3 0.2 0.5
P = 0.5 0.1 0.4
0.5 0.2 0.3
with initial distribution α0 = 0.5 and α1 = 0.5. Determine P(X2 = 0) and
P(X3 = 0).
36 / 101
Example
Solution:
Firstly, the states of this Markov chain are 0, 1, 2.
37 / 101
Example
Solution - continued:
The third-step transition matrix is
P(3) = P (2)
·P
0.44 0.18 0.38 0.3 0.2 0.5
= 0.40 0.19 0.41 · 0.5 0.1 0.4
0.40 0.18 0.42 0.5 0.2 0.3
0.412 0.182 0.406
= 0.42 0.181 0.399 .
0.42 0.182 0.398
38 / 101
Example
Solution - continued:
40 / 101
State j is said to be accessible from state i if for some n ≥ 0, Pijn > 0.
This implies that state j is accessible from state i if and only if, starting in
state i, it is possible that the process will eventually enter state j.
Two states i and j accessible to each other, are said to communicate, and
we write i ↔ j.
41 / 101
Proposition
Communication is an equivalence relation. That is, for any states i, j and k,
we have
(i) i ↔ i
(ii) if i ↔ j, then j ↔ i
(iii) if i ↔ j and j ↔ k, then i ↔ k.
If two states communicate with each other, then they are in the same class.
Then, by the above proposition, any two classes are either disjoint or
identical.
42 / 101
Example
Consider the following Markov chain consisting of the three states 0, 1, and 2
and having a transition matrix
1/2 1/2 0
P = 1/2 1/4 1/4 .
0 1/3 2/3
Is this Markov chain irreducible? Determine the classes of this Markov chain.
43 / 101
Example
Solution:
This Markov chain has 3 states: 0,1,2. A graphical representation of this Markov chain is
given by
1/2 1/4
1/2 0 1 2 2/3
1/2 1/3
1/4
We need to check if the states are communicating with each other. That is, we see
0 → 1 and 1 → 0 so states 0 and 1 communicate with each other (0 ↔ 1).
1 → 2 and 2 → 1 so states 1 and 2 communicate with each other (1 ↔ 2).
0 → 2 via 0 → 1 and 1 → 2; and 2 → 0 via 2 → 1 and 1 → 0.
Therefore, the Markov chain is irreducible since all the states communicate with each
other, and only one class contains all the states. 44 / 101
Example
Consider the following Markov chain consisting of four states 0, 1, 2, and 3
and having a transition matrix
1/2 1/2 0 0
1/2 1/2 0 0
P = 1/4 1/4 1/4 1/4 .
0 0 0 1
Is this Markov chain irreducible? Determine the classes of this Markov chain.
45 / 101
Example
Solution:
This Markov chain has 3 states: 0,1,2,3. A graphical representation of this Markov chain is
given by
1/2 1/4
1/2 1/4
1/2 0 1 2 3 1
1/2 1/4
1/4
We need to check if the states are communicating with each other. That is, we see
0 → 1 and 1 → 0 so states 0 and 1 communicate with each other (0 ↔ 1).
Hence the classes are {0, 1}, {2}, and {3}. This Markov chain is not irreducible. Moreover,
{3} is an absorbing state.
46 / 101
Definition
State i has period d if Piin = 0 whenever n is not divisible by d and d is the
largest integer with this property.
State i has period d if d is the greatest common divisor (g.c.d) of the number
of transitions by which state i can be reached, starting in state i. That is,
47 / 101
Let d(i) be the period of state i. The next proposition tells us that
periodicity is a class property.
Proposition
If i ↔ j, then d(i) = d(j).
48 / 101
Example
Consider the Markov chain with a transition probability matrix
0 1 0 0
0 0 1 0
P = 0
.
0 0 1
1/2 0 1/2 0
What is the period of state 0? Is this chain irreducible?
49 / 101
Example
Solution:
This Markov chain has 3 states: 0,1,2,3. A graphical representation of this Markov chain is
given by
1 1 1
0 1 2 3
1/2
1/2
n
The period of 0 is determined by finding d(0) = g.c.d({n : P00 > 0}). We see that
1 2 3 4
P00 =0 P00 =0 P00 =0 P00 >0
5 6
P00 =0 P00 = (1/2)2 7
P00 =0 8
P00 >0
n
For n = 4, 6, 8, . . . , we have P00 > 0, so d(0) = g.c.d({4, 6, 8, . . . }) = 2.
Solution - continued:
We need to check if the states are communicating with each other. That is, we see
0 → 1 and 1 → 0 so states 0 and 1 communicate with each other (0 ↔ 1).
1 → 2 and 2 → 1, so 1 and 2 communicate with each other (1 ↔ 2).
2 → 3 and 3 → 2, so 2 and 3 communicate with each other (2 ↔ 3).
All the states communicate with each other, so there is only one class, {0, 1, 2, 3}.
51 / 101
For any state i, let fi be the probability that starting in i, the process will
ever re-enter state i.
Definition
State i is said to be recurrent if fi = 1 and transient if fi < 1.
52 / 101
Suppose the process starts in state i and i is transient. Then
with probability (1 − fi ) > 0, the process will never reenter state i.
starting in state i, the probability that the process will be in state i for
exactly n times equals fin−1 (1 − fi ), n ≥ 1.
If state i is transient, starting in state i, the process will only visit a finite
number of times (with probability one); hence the name transient.
This leads to the conclusion that in a finite-state Markov chain, not all states
can be transient.
53 / 101
Let Ni be the number of times state i is visited.
1
That is Ni X0 = i ∼ Geometric(1 − fi ) and E[Ni X0 = i] = 1−fi
< ∞ if
state i is transient.
54 / 101
We write ∞
X
Ni = 1{Xn =i} ,
n=0
where (
1, if Xn = i
1{Xn =i} =
0, if Xn ̸= i.
55 / 101
Hence
∞
hX i
E(Ni X0 = i) = E 1{Xn =i} X0 = i
n=0
∞
X h i
= E 1{Xn =i} X0 = i
n=0
X∞ h i
= P X n = i X0 = i
n=0
∞
X
Piin .
n=0
56 / 101
Proposition
State i is recurrent if ∞
X
Piin = ∞.
n=1
State i is transient if ∞
X
Piin < ∞.
n=1
Corollary
If state i is transient, then Piin → 0 as n → ∞.
57 / 101
Next, we learn that recurrence/transience state is a class property.
Corollary
If State i is recurrent and state i communicates with state j , then state j
is recurrent.
Corollary
In a Markov chain, all states in a given class are recurrent or transient. We
refer to the class itself as being recurrent or transient.
58 / 101
Example
Consider the Markov Chain having states 0, 1, 2, 3 and has a transition
probability matrix
0 0 12 12
1 0 0 0
P = 0 1 0 0 .
0 1 0 0
59 / 101
Example
Solution:
Here we have four states: 0,1,2,3. The graphical representation of this
Markov chain is
1/2
1/2
0 1 2 3
1 1
60 / 101
Example
Solution- continued:
From this graphic, we see that
0 → 1 via 0 → 2, 2 → 1 1→0 =⇒ 0 ↔ 1
1 → 2 via 1 → 0, 0 → 2 2→1 =⇒ 1 ↔ 2
2 → 3 via 2 → 1, 1 → 0 , 0 → 3 3 → 2 via 3 → 1, 1 → 0, 0 → 2 =⇒ 2 ↔ 3.
We observe that all the states communicate with each other; hence, there is
only one class {0, 1, 2, 3}. The Markov chain is irreducible . All the states
are recurrent
61 / 101
Example
Consider the Markov Chain having states 0, 1, 2, 3, 4 and has a transition
probability matrix
1/2 1/2 0 0 0
1/2 1/2 0 0 0
P = 0 0 1/2 1/2 0 .
0 0 1/2 1/2 0
1/4 1/4 0 0 1/2
62 / 101
Example
Solution:
This Markov chain has 5 states: 0,1,2,3,4. A graphical representation of this Markov chain is given by
1/2
1/2
1/2 0 1 4 1/2
1/2 1/4
1/4
1/2
1/2 2 3 1/2
1/2
63 / 101
Example
Solution- continued:
From this graphic, we see that
0→1 1→0 =⇒ 0 ↔ 1
1↛2 2↛1 =⇒ 1 ↮ 2
4→1 1↛4 =⇒ 1 ↮ 4
2→3 3→2 =⇒ 2 ↔ 3
Further, suppose that this gambler stops playing when she has no money left,
or she has $N. Then the gambler’s fortune is a Markov chain with transition
probabilities given by
Pi,i+1 = p = 1 − Pi,i−1 i = 1, 2, . . . , N − 1
P00 = PN N = 1.
65 / 101
Example
The states 0 and N are known as absorbing states because once you reach
that state, you can’t leave (i.e. you are fixed there for life.).
Hence, the gambler’s fortune is a finite state random variable with absorbing
states 0 and N . We will discuss absorbing states in detail later on.
p p p p
1 0 1 2 ··· N −1 N 1
1−p 1−p 1−p 1−p
There are three classes: {0} - recurrent; {1, 2, . . . , N − 1} - transient; and {N } - recurrent.
66 / 101
Example
Random Walk Model
67 / 101
Example
From this graphic representation, we observe that
The chain is irreducible, and all states are either recurrent or transient.
P∞ n
Let us consider state 0 and attempt to determine if n=0 P00 is finite or
infinite.
2n−1
We also observe for n = 1, 2, . . . , P00 = 0 and
(4 p (1 − p))n
2n 2n n 2n! n
P00 = p (1 − p)n = p (1 − p)n ≈ √
n n! n! πn
√
(by Stirling’s approximation n! = nn+1/2 e−n 2 π. )
68 / 101
Example
In particular,
When p = 1/2, then (4 p (1 − p) )n = 1. Hence,
∞ ∞ n ∞
X
n
X 4 p (1 − p) X 1
P00 ≈ √ = √ = ∞.
n=0 n=0
πn n=0
πn
69 / 101
8.2.3 Long-Run Properties
70 / 101
For pairs of states i ̸= j, let fij denote the probability that the Markov
chain, starting in state i, will ever transition into state j. That is,
Proposition
If i is recurrent and i communicates with j, then fij =1.
71 / 101
If state j is recurrent, let mj denote the expected number of
transitions that it takes the Markov chain when starting in state j
to return to back to state j. That is, we see that mj , with
Nj = min{ n > 0 : Xn = j}
equal to the number of transitions until the Markov chain makes a transition
into state j,
mj = E(Nj X0 = j).
72 / 101
Definition
We say that the recurrent state j is
positive recurrent if mj < ∞
null recurrent if mj = ∞.
73 / 101
Suppose that the Markov chain is irreducible and recurrent.
Let πj denote the long-run proportion of time that the Markov chain
is in state j.
Proposition
If the finite-state Markov chain is irreducible and recurrent, then for
any initial state
πj = 1/mj .
74 / 101
Next we need to determine the long-run proportions {πj , j ≥ 1}.
Note that because πi is the long-run proportion of transitions that come from
state i, we observe that
75 / 101
Theorem
Consider an irreducible Markov chain. If the chain is positive recurrent, then
the long-run proportions are the unique solution of the equation
X
πj = πi Pij , j ≥ 0
i
X
πj = 1.
j
76 / 101
Example
Forecasting the Weather
This example comes from Ross (2023).
77 / 101
Example
The transition probability matrix is
α 1−α
P = .
β 1−β
1−α
α R NR 1−β
β
78 / 101
Example
We have an irreducible Markov chain, and the chain is positive recurrent.
That is,
α 1−α
(πR , πN R ) = (πR , πN R ) = (α πR + β πN R , (1 − α) πR + (1 − β) πN R .
β 1−β
πR = α π R + β π N R
πN R = (1 − α) πR + (1 − β) πN R
πR + πN R = 1.
79 / 101
Example
From this, we see that
β
πR =
1−α+β
1−α
πN R = 1 − πR = .
1−α+β
Using the values α = 0.7 and β = 0.4, we see that the long-run proportion of
0.4
rain, πR = 1−0.7+0.4 = 47 .
80 / 101
Example
Consider a Markov chain with 3 states: 0, 1, 2 and a transition probability
matrix
0.5 0.4 0.1
P = 0.3 0.4 0.3 .
0.2 0.3 0.5
81 / 101
Example
P2
We need to solve for π = (π0 , π1 , π2 ) when π = π P and i=0 πi = 1.
82 / 101
8.2.4 Stationary Probabilities
83 / 101
The long-run proportion {πj , j ≥ 0}, are often called stationary
probabilities.
The reason is that if the initial state is chosen according to the probabilities
πj , j ≤ 0, then the probability of being in state j at any time n is also equal
to πj . That is,
P (X0 = j) = πj ,
then
P (Xn = j) = πj for all n.
84 / 101
The preceding is easily proven by induction. Assume that it is true when
n = 0, and if we suppose it is true for n − 1, then by writing
X
P (Xn = j) = P (Xn = j Xn−1 = i)P (Xn−1 = i)
i
X
= Pij πi
i
= πj .
85 / 101
Definition
A state is said to be ergodic if it is positive recurrent and aperiodic.
86 / 101
Example
Recall the forecasting of the weather problem from Ross (2023) .
Calculate P4 , P8 , P16 .
87 / 101
Example
We have
2 0.7 0.3 0.7 0.3 0.61 0.39
P = P ·P = · =
0.4 0.6 0.4 0.6 0.52 0.48
0.61 0.39 0.61 0.39 0.5749 0.4251
P4 = P2 · P2 = · =
0.52 0.48 0.52 0.48 0.5668 0.4332
0.5749 0.4251 0.5749 0.4251 0.5715 0.4285
P8 4
= P ·P =4
· =
0.5668 0.4332 0.5668 0.4332 0.5714 0.4286
0.5715 0.4285 0.5715 0.4285 0.5714 0.4286
P 16 8
= P ·P =8
· = .
0.5714 0.4286 0.5714 0.4286 0.5714 0.4286
88 / 101
It seems that Pijn is converging to some value as n → ∞, with this value not
depending on state i.
It is not always true that the long-run proportions are also the limit
probabilities.
89 / 101
Theorem
For an ergodic Markov chain, limn→∞ Pijn exists for all state j, and is
independent of state i.
Further, letting
πj = lim Pijn ,
n→∞
X
πj = πi Pijn , j ≥ 0,
i
X
πj = 1.
j
90 / 101
Example
Application of the Gambler’s ruin problem
Suppose we have a gambler who at each play of the game has probability p of
winning one dollar and probability q = 1 − p of losing one dollar.
91 / 101
Example
The graphical representation of the gambler’s ruin problem is
p p p p
1 0 1 2 ··· N −1 N 1
1−p 1−p 1−p 1−p
92 / 101
Example
Result
1−(q/p)i
1−(q/p)N , if p ̸= 1/2
Pi =
i
N
, if p = 1/2.
As N → ∞, we observe
i
1 − (q/p) , if p > 1/2
Pi =
0, if p = 1/2.
93 / 101
8.3 Supplementary Material
94 / 101
Supplementary Material - Gambler’s Ruin Problem
96 / 101
Supplementary Material - Gambler’s Ruin Problem -continued
97 / 101
Supplementary Material - Gambler’s Ruin Problem -continued
98 / 101
Supplementary Material - Gambler’s Ruin Problem -continued
1 − (q/p)N
PN = 1 = P1 .
1 − (q/p)
1 − (q/p)
∴ P1 = .
1 − (q/p)N
1
Case 2: p = 2
PN = 1 = N P 1 .
1
∴ P1 = .
N
99 / 101
Supplementary Material - Gambler’s Ruin Problem -continued
1−(q/p)i
1
1−(q/p)N P1 , if p > 2 ,
=
i
N
if p = 21 .
100 / 101
Supplementary Material - Gambler’s Ruin Problem -continued
Therefore, (
1 − (q/p)i , if p > 12 ,
lim Pi =
N →∞ 0, if p ≤ 21 .
101 / 101