States and arrows
A transition diagram draws a Markov chain as a picture. Each state is a circle. An arrow from one state to another carries the chance of moving that way in one step, and a loop from a state back to itself carries the chance of staying.
For the city and the country: each year 0.2 of the city moves to the country and 0.3 of the country moves to the city, so the arrow from the city to the country carries 0.2 and the arrow back carries 0.3. The city keeps 0.8, written on its loop, and the country keeps 0.7.
The city C and the country K, each with a loop for the share that stays and an arrow for the share that moves to the other.
From the diagram to the matrix
Each state gets a column of T for where its people start and a row for where they end up, in the same order: the city first, then the country. An arrow from one state to another goes in the column of the state it leaves and the row of the state it reaches. So the 0.2 on the arrow from the city to the country sits in column 1, row 2.
Row 1 then collects every arrow arriving in the city: the loop 0.8 from the city itself and the arrow 0.3 from the country. Row 2 collects the arrows arriving in the country, 0.2 and 0.7. That gives T = (0.8 0.3; 0.2 0.7), the same matrix as the table of shares.
A pair of states with no arrow between them has a 0 in that place. A state drawn with no loop has a 0 on the diagonal: nobody stays.
The top row of T is everything arriving in the city: 0.8 on the city's loop and 0.3 on the arrow from the country.
What leaves a state adds to 1
Everyone who starts in the city either stays or moves, so the loop and the arrows leaving the city add to 1: 0.8 + 0.2 = 1. Those are the entries of column 1 of T. For the country, 0.7 + 0.3 = 1, which is column 2.
This is how to find a share the diagram leaves out. If two arrows leave a state P carrying 0.6 and 0.3, then P's loop must carry 1 − 0.6 − 0.3 = 0.1.
Everything leaving the city C, its loop 0.8 and its arrow 0.2, adds to 1. That pair is the first column of T.
Two steps along the arrows
A diagram also shows how to go two steps. To find the chance that someone in the city is in the city two years later, list every path of two arrows from the city back to the city. Multiply the chances along each path and add the paths.
There are two paths. Staying twice, city to city to city, has chance 0.8 × 0.8 = 0.64. Moving out and coming back, city to country to city, has chance 0.2 × 0.3 = 0.06. Together that is 0.64 + 0.06 = 0.7, which is the top left entry of . Multiplying T by itself adds up exactly these paths.
Regular chains
A Markov chain is regular when some power of T has every entry positive. Then, after that number of steps, every state can be reached from every state, whatever the start.
T itself may have zeros. Take two states A and B. A never stays: its only arrow goes to B, carrying 1. B stays with chance 0.5 and moves to A with chance 0.5. With A first, T = (0 0.5; 1 0.5), which has a 0 in the top left.
Square it. The top left entry of is 0 × 0 + 0.5 × 1 = 0.5, the path A to B to A. The top right is 0 × 0.5 + 0.5 × 0.5 = 0.25, the bottom left is 1 × 0 + 0.5 × 1 = 0.5, and the bottom right is 1 × 0.5 + 0.5 × 0.5 = 0.75. So is the matrix (0.5 0.25; 0.5 0.75). Every entry is positive, so the chain is regular.
A has no loop, so A cannot be in A one step later. In two steps it can: A to B to A has chance 1 × 0.5 = 0.5.
T has a 0 in its top left corner, and its square has none, so this chain is regular.
When a chain is not regular
Take three states A, B and D. A always moves to B, B always moves to D, and D has only a loop carrying 1. Nobody ever leaves D: it is a trap, also called an absorbing state.
In the order A, B, D the columns of T are (0, 1, 0) for A, (0, 0, 1) for B and (0, 0, 1) for D. Square it: two steps take A to D and B to D, and D stays at D, so every column of is (0, 0, 1). Every later power is the same, with zeros in the rows of A and B. No power of T is all positive, so the chain is not regular.
A chain can fail in a second way. If two states swap every step, each arrow carrying 1 and neither state having a loop, then T = (0 1; 1 0), and is the identity matrix (1 0; 0 1). The powers take turns between these two matrices, and both have zeros, so this chain is not regular either.
D has no arrow out, only a loop carrying 1, so everyone who reaches D stays there.
Two states that swap every step: after an odd number of steps a walker who started in A is always in B.
The usual mistakes
Putting an arrow in the row of the state it leaves. The arrow from the city to the country belongs in the city's column and the country's row.
Leaving out a loop that the diagram does not draw. The share that stays is 1 minus the arrows leaving, and it goes on the diagonal of T.
Calling a chain regular because each column of T adds to 1. That is true of every transition matrix; regular asks that some power of T has no zero entries.
Calling a chain not regular because T has a zero. A zero in T is allowed, as long as a zero-free power comes later.
Weather and a frog
In the applications below, a diagram of sunny and rainy days becomes a transition matrix, and the chance of rain two days on is found by multiplying by T twice and checked by adding the chances of the two paths. Then a frog hops between three lily pads, a missing arrow from one end pad to the other gives a 0 in T, and the only two-minute path to the far pad gives its chance.
Worked example: Tomorrow's Weather in a Seaside Town, and the Chance of Rain in Two Days
Question A weather forecaster in a seaside town records each day as sunny or rainy. Her transition diagram shows that after a sunny day the next day is sunny with probability 0.7 and rainy with probability 0.3, and after a rainy day the next day is sunny with probability 0.4 and rainy with probability 0.6. The state vector is a column sr of the chances of sunny and rainy. Monday is sunny. (a) Write down the transition matrix T, and find the chance of rain on Tuesday. (b) Find the chance of rain on Wednesday.
1.The column for a sunny day holds 0.7 and 0.3, and the column for a rainy day holds 0.4 and 0.6: T = 0.70.40.30.6, with the rows and columns in the order sunny, rainy. Each column adds up to 1.
Each arrow carries the chance of tomorrow's weather after today's. The column for sunny holds 0.7 and 0.3, so T = 0.70.40.30.6. 2.Monday is sunny, so the state vector is x0 = 10. Then Tuesday is x1 = Tx0 = 0.70.3, the first column of T.
Monday is sunny, x0 = 10, so Tuesday is the first column of T: 0.70.3. 3.(a) T = 0.70.40.30.6, and the chance of rain on Tuesday is 0.3.
(a) The chance of rain on Tuesday is 0.3, the arrow from sunny to rainy. 4.Multiply by T again for Wednesday: x2 = Tx1 = 0.7 × 0.7 + 0.4 × 0.30.3 × 0.7 + 0.6 × 0.3 = 0.49 + 0.120.21 + 0.18 = 0.610.39.
Wednesday is T0.70.3 = 0.610.39. 5.(b) The chance of rain on Wednesday is 0.39. Check by the paths from Monday: sunny, sunny, rainy has chance 0.7 × 0.3 = 0.21, and sunny, rainy, rainy has chance 0.3 × 0.6 = 0.18, so the chance is 0.21 + 0.18 = 0.39.
(b) The two paths that end in rain on Wednesday give 0.21 + 0.18 = 0.39.
Answer: (a) T = 0.70.40.30.6, and the chance of rain on Tuesday is 0.3; (b) 0.39
Common mistakes
- Putting the sunny day's chances along the first row instead of down the first column. Then T10 = 0.70.4, whose entries add up to 1.1, so it cannot be a state vector.
- Squaring the chance of rain to get 0.3 × 0.3 = 0.09. That uses the chance of rain after a sunny day twice, but after a rainy Tuesday the chance of rain is 0.6, and rain on Wednesday can also follow a sunny Tuesday. The two paths give 0.18 + 0.21 = 0.39.
More transition matrices and markov chains problems, worked step by step →
Worked example: A Frog Hopping Between Three Lily Pads in a Row, and the Share of Time It Spends on the Middle Pad
Question A frog sits on one of three lily pads in a row: the left pad L, the middle pad M and the right pad R. Each minute, a frog on an end pad stays where it is with probability 12 and hops to the middle pad with probability 12; a frog on the middle pad stays with probability 12 and hops to each end pad with probability 14. It cannot hop from one end pad straight to the other. The state vector is a column of the chances that the frog is on L, M and R. The frog starts on the left pad. (a) Write down the transition matrix T, and find the chance that the frog is on the right pad after two minutes. (b) Find the fraction of the time the frog spends on the middle pad in the long run.
1.T = 1214012121201412, with the rows and columns in the order L, M, R. The 0 in each corner is a hop from one end pad straight to the other, which cannot happen.
Each hop is an arrow, and the columns of T = 1214012121201412 are the arrows out of L, M and R. 2.After one minute the frog is on L or on M: x1 = T100 = 12120.
From L the frog stays or hops to M: after one minute the chances are 12120. 3.(a) To be on R after two minutes, the frog must hop to M and then to R, so the chance is 12 × 14 = 18. Check with T: x2 = Tx1 = 381218.
(a) The only way to R in two minutes is L, M, R: 12 × 14 = 18. 4.For the long run, let π = lmr. The first row of Tπ = π gives 12l + 14m = l, so m = 2l, and the third row gives m = 2r in the same way. Then l + 2l + l = 1, so l = 14, m = 12 and r = 14.
The points are the chances minute by minute from L. The rows of Tπ = π give m = 2l = 2r, so π has 14, 12, 14, dashed. 5.(b) In the long run the frog spends half of its time on the middle pad. Check the middle row: 12 × 14 + 12 × 12 + 12 × 14 = 12.
(b) In the long run the frog is on the middle pad half of the time.
Answer: (a) T = 1214012121201412, and the chance is 18 = 0.125; (b) half of the time, 12 = 0.5
Common mistakes
- Giving each pad a third of the time because there are three pads. The middle pad can be reached from both end pads, and the frog leaves it only half of the time, so it holds 12 of the time and each end pad 14.
- Counting a path L, L, R in the two-minute chance. The frog cannot hop from L straight to R, and that entry of T is 0, so the only path is L, M, R, with chance 18.
More transition matrices and markov chains problems, worked step by step →