Tutorials › Linear Algebra › Markov Workshop: Estimating and Checking a Transition Model

Applications in Networks, Economics and Data · Tutorial 963 of 1000

Markov Workshop: Estimating and Checking a Transition Model

Learn to convert transition counts into a column-stochastic matrix and verify that its ordering and multiplication convention agree with the observations.

Intermediate 12 min read

What You'll Learn

  • Organize transition counts by source state and destination state
  • Estimate transition probabilities using each source state's total
  • Assemble a transition matrix for column count vectors
  • Check that probabilities are nonnegative and each column sums to one
  • Compare model predictions with the observations that produced the estimates
  • Reorder a transition model consistently when state labels change

From Observed Transitions to a Matrix

A transition model describes how counts move among a fixed collection of states in one time step. For example, the states might be locations, categories, or conditions, and the data record how many units began in each state and ended in each other state. The main bookkeeping challenge is to preserve the distinction between the state a unit came from and the state it moved to. A matrix can contain valid proportions but still give incorrect predictions if its rows and columns are interpreted in the wrong order.

Use a fixed ordering of the states, say \(S_1,\dots,S_n\). Let \(N_{ij}\) be the observed number of units that began in source state \(S_i\) and ended in destination state \(S_j\). Thus the count table \(\mathbf{N}\) has source states as rows and destination states as columns. The total number observed from source \(S_i\) is \(s_i=\sum_{j=1}^n N_{ij}\). If \(s_i>0\), the observed proportion moving from \(S_i\) to \(S_j\) is \(N_{ij}/s_i\).

Definition: For a fixed state ordering \(S_1,\dots,S_n\), the empirical transition matrix \(\mathbf{P}\) in the column-vector convention has entry \(p_{ji}=N_{ij}/s_i\) in row \(j\), column \(i\), whenever \(s_i>0\). Its column \(i\) gives the destination proportions for source state \(S_i\). Therefore \(\mathbf{P}\mathbf{x}\) predicts destination counts from a column vector \(\mathbf{x}\) of source counts. A transition matrix in this convention has nonnegative entries and every column sums to \(1\); it is called column-stochastic.

The index order in \(p_{ji}\) is deliberate: the first index refers to the destination row and the second to the source column. Each observed source total supplies the denominator for one whole column of \(\mathbf{P}\). If \(s_i=0\), the observed data contain no transitions from \(S_i\), so that column cannot be estimated by this relative-frequency rule. It is not valid to divide by zero or to treat an unobserved source state as having zero probability of every destination. Additional data or an explicitly supplied model would be needed.

Estimating and Checking a Model

Worked Example: Estimate from Three Source States

Suppose the states are \(A,B,C\), in that order, and the observed counts have source states in rows and destination states in columns:

$$ \mathbf{N}= \begin{bmatrix} 6&3&1\\ 2&5&3\\ 1&2&7 \end{bmatrix}. $$

The source totals are \(s_A=6+3+1=10\), \(s_B=2+5+3=10\), and \(s_C=1+2+7=10\). Divide each row of the count table by its own source total, then place those source-specific proportions into columns of \(\mathbf{P}\):

$$ \mathbf{P}= \begin{bmatrix} 6/10&2/10&1/10\\ 3/10&5/10&2/10\\ 1/10&3/10&7/10 \end{bmatrix} = \begin{bmatrix} 3/5&1/5&1/10\\ 3/10&1/2&1/5\\ 1/10&3/10&7/10 \end{bmatrix}. $$

For source \(A\), the column is \((3/5,3/10,1/10)^{\top}\); its entries sum to \(1\). The columns for \(B\) and \(C\) also sum to \(1/5+1/2+3/10=1\) and \(1/10+1/5+7/10=1\), respectively. The observed source-count vector is \(\mathbf{x}=(10,10,10)^{\top}\). Multiplying gives the predicted destination-count vector:

$$ \mathbf{P}\mathbf{x} = \begin{bmatrix} 6+2+1\\ 3+5+2\\ 1+3+7 \end{bmatrix} = \begin{bmatrix} 9\\10\\11 \end{bmatrix}. $$

Check: The observed destination totals are \(6+2+1=9\) in state \(A\), \(3+5+2=10\) in state \(B\), and \(1+3+7=11\) in state \(C\). They agree with the product. This check uses the source totals from these observations, not an arbitrary later source-count vector.

Observed counts and model predictions answer different questions. The data in the example estimate the transition proportions and, when applied to their own source totals, reproduce the observed destination totals. If a later source-count vector differs from \((10,10,10)^{\top}\), its product with \(\mathbf{P}\) is a new prediction; it should not be compared as though it were the historical destination totals.

Worked Example: A Prediction for Different Current Counts

Keep the estimated matrix from the previous example, but suppose a new period begins with \(\mathbf{x}=(10,20,10)^{\top}\) units in states \(A,B,C\), respectively. Compute the model's prediction:

$$ \mathbf{P}\mathbf{x} = \begin{bmatrix} (3/5)10+(1/5)20+(1/10)10\\ (3/10)10+(1/2)20+(1/5)10\\ (1/10)10+(3/10)20+(7/10)10 \end{bmatrix} = \begin{bmatrix} 6+4+1\\ 3+10+2\\ 1+6+7 \end{bmatrix} = \begin{bmatrix} 11\\15\\14 \end{bmatrix}. $$

Check: The predicted total is \(11+15+14=40\), equal to the input total \(10+20+10=40\). These are predictions for the new input. The historical destination totals \((9,10,11)^{\top}\) came from the historical input \((10,10,10)^{\top}\), so there is no reason for the new prediction to match them.

Why the Column Convention Preserves Counts

Theorem: If \(\mathbf{P}\) is an \(n\times n\) column-stochastic matrix and \(\mathbf{x}\in\mathbb{R}^n\) has nonnegative entries, then \(\mathbf{P}\mathbf{x}\) has nonnegative entries and the same total as \(\mathbf{x}\): \(\sum_{j=1}^n(\mathbf{P}\mathbf{x})_j=\sum_{i=1}^n x_i\).

Proof. Each entry of \(\mathbf{P}\mathbf{x}\) is \((\mathbf{P}\mathbf{x})_j=\sum_{i=1}^n p_{ji}x_i\). Since every \(p_{ji}\ge 0\) and every \(x_i\ge 0\), each such sum is nonnegative. Summing all entries and changing the order of the finite sums gives \(\sum_{j=1}^n(\mathbf{P}\mathbf{x})_j=\sum_{j=1}^n\sum_{i=1}^n p_{ji}x_i=\sum_{i=1}^n x_i\sum_{j=1}^n p_{ji}\). Column \(i\) sums to \(1\), so the last expression is \(\sum_{i=1}^n x_i\). \(\square\)

This result gives two useful checks. First, a valid model in this convention cannot create or remove total count in a one-step prediction. Second, because nonnegative source counts produce nonnegative destination counts, negative predicted counts indicate either a calculation error or an object that is not a transition matrix in this convention. The theorem does not say that each predicted count must be an integer: estimated proportions can produce fractional expected counts, as the next example shows.

Worked Example: Unequal Source Totals

Suppose the count table for states \(A,B,C\) is

$$ \mathbf{N}= \begin{bmatrix} 6&2&0\\ 1&3&2\\ 1&0&5 \end{bmatrix}. $$

The source totals are \(8,6,6\), so the transition matrix is

$$ \mathbf{P}= \begin{bmatrix} 6/8&1/6&1/6\\ 2/8&3/6&0\\ 0&2/6&5/6 \end{bmatrix} = \begin{bmatrix} 3/4&1/6&1/6\\ 1/4&1/2&0\\ 0&1/3&5/6 \end{bmatrix}. $$

The column sums are \(3/4+1/4=1\), \(1/6+1/2+1/3=1\), and \(1/6+0+5/6=1\). For the observed source vector \((8,6,6)^{\top}\), the product is

$$ \mathbf{P} \begin{bmatrix}8\\6\\6\end{bmatrix} = \begin{bmatrix} 6+1+1\\ 2+3+0\\ 0+2+5 \end{bmatrix} = \begin{bmatrix}8\\5\\7\end{bmatrix}. $$

The destination totals from the count table are \(8,5,7\), as required. Now consider a different input \((4,3,2)^{\top}\). The predicted counts are

$$ \mathbf{P} \begin{bmatrix}4\\3\\2\end{bmatrix} = \begin{bmatrix} 3+1/2+1/3\\ 1+3/2+0\\ 0+1+5/3 \end{bmatrix} = \begin{bmatrix} 23/6\\5/2\\8/3 \end{bmatrix}. $$

Check: The output total is \(23/6+15/6+16/6=54/6=9\), equal to the input total \(4+3+2=9\). Fractional values are appropriate as model predictions based on proportions; they are not claims that a realized count must be fractional.

Checking State Ordering

A transition matrix is meaningful only with its state ordering attached. In the convention used here, both the rows of \(\mathbf{P}\) and the entries of a destination vector follow the destination-state order; the columns of \(\mathbf{P}\) and the entries of a source vector follow the source-state order. When source and destination states are the same collection, the same ordering is used on both axes.

Theorem: Let \(\mathbf{P}\) be an \(n\times n\) transition matrix for an ordered state list, and let \(\mathbf{S}\) be a permutation matrix that changes that list to a new order. If source counts are reordered to \(\mathbf{x}'=\mathbf{S}\mathbf{x}\), then the transition matrix in the new order is \(\mathbf{P}'=\mathbf{S}\mathbf{P}\mathbf{S}^{\top}\), and its prediction is \(\mathbf{P}'\mathbf{x}'=\mathbf{S}(\mathbf{P}\mathbf{x})\).

Proof. A permutation matrix reorders coordinates, so its columns are a rearrangement of the standard basis vectors. Consequently \(\mathbf{S}^{\top}\mathbf{S}=\mathbf{I}_n\). Reordering destination coordinates applies \(\mathbf{S}\) on the left of \(\mathbf{P}\). Reordering source coordinates applies \(\mathbf{S}^{\top}\) on the right, because \(\mathbf{S}^{\top}\mathbf{x}'=\mathbf{S}^{\top}\mathbf{S}\mathbf{x}=\mathbf{x}\). Thus the matrix in the new order is \(\mathbf{P}'=\mathbf{S}\mathbf{P}\mathbf{S}^{\top}\). Applying it to the reordered input gives \(\mathbf{P}'\mathbf{x}'=\mathbf{S}\mathbf{P}\mathbf{S}^{\top}\mathbf{S}\mathbf{x}=\mathbf{S}\mathbf{P}\mathbf{x}\). This is exactly the original prediction with its coordinates reordered. \(\square\)

Worked Example: Reorder the States Consistently

Return to the first example and change the order from \(A,B,C\) to \(B,A,C\). This swaps the first two coordinates. The correctly reordered matrix, with destination states in rows and source states in columns in the new order, is

$$ \mathbf{P}'= \begin{bmatrix} 1/2&3/10&1/5\\ 1/5&3/5&1/10\\ 3/10&1/10&7/10 \end{bmatrix}. $$

For instance, its first column is the old column for source \(B\), but its entries now appear in the destination order \(B,A,C\). The historical source vector becomes \((10,10,10)^{\top}\), unchanged numerically because its first two entries agree. Multiplication gives \((10,10,10)^{\top}\) transformed to the historical destination vector \((10,9,11)^{\top}\) in the new order:

$$ \mathbf{P}' \begin{bmatrix}10\\10\\10\end{bmatrix} = \begin{bmatrix} 5+3+2\\ 2+6+1\\ 3+1+7 \end{bmatrix} = \begin{bmatrix}10\\9\\11\end{bmatrix}. $$

Check: This is the original prediction \((9,10,11)^{\top}\) with its first two entries swapped. Swapping just the rows or just the columns would not consistently relabel both the destination output and source input.

Common Convention Mistake

Some tables instead use source states as rows and destination states as columns in a row-stochastic transition matrix \(\mathbf{Q}\). Its entries are \(q_{ij}=N_{ij}/s_i\), so each row sums to \(1\). Such a matrix naturally acts on a row vector from the left. If counts are kept as columns, the corresponding operation is \(\mathbf{Q}^{\top}\mathbf{x}\), not \(\mathbf{Q}\mathbf{x}\). These are two consistent conventions; trouble comes from mixing their matrix layout and multiplication rule.

For a concrete check, suppose two states have count table \(\begin{bmatrix}3&1\\1&5\end{bmatrix}\), with source rows. The row-stochastic matrix is \(\mathbf{Q}=\begin{bmatrix}3/4&1/4\\1/6&5/6\end{bmatrix}\). For the column input \((8,2)^{\top}\), the correct result is

$$ \mathbf{Q}^{\top} \begin{bmatrix}8\\2\end{bmatrix} = \begin{bmatrix}3/4&1/6\\1/4&5/6\end{bmatrix} \begin{bmatrix}8\\2\end{bmatrix} = \begin{bmatrix}19/3\\11/3\end{bmatrix}. $$

The total is \(19/3+11/3=10\), matching the input total. A wrong calculation would multiply \(\mathbf{Q}(8,2)^{\top}\), giving \((13/2,3)^{\top}\), whose total is \(19/2\), not \(10\). The correction is to use \(\mathbf{Q}^{\top}\) for column counts, or to use the column-stochastic matrix \(\mathbf{P}=\mathbf{Q}^{\top}\) from the start.

Before trusting an estimated model, check the count table layout, the denominator used for each source state, the sums of the appropriate matrix columns, and the ordering of source and destination coordinates. Then test the matrix on the observed source totals: its output should reproduce the observed destination totals when the transition counts describe the same single transition period. If it does not, locate the discrepancy before interpreting new predictions.

Check Your Understanding

For each question, keep the source and destination roles explicit and verify numerical predictions by multiplication.

  1. A count table with source rows is \(\begin{bmatrix}4&2\\3&3\end{bmatrix}\). Find the column-stochastic transition matrix in the column-count convention.
  2. For the table in question 1, calculate the destination totals from the observed source-total vector and check them directly from the table.
  3. One source state has observed counts \(0,0,0\). Explain why the relative-frequency rule does not determine its transition probabilities.
  4. A column-stochastic matrix is applied to a nonnegative input with total \(25\). What must be true of the total and signs of the predicted counts?
  5. If state coordinates are changed by a permutation matrix \(\mathbf{S}\), write the matrix and input transformations that ensure predictions are reordered consistently.

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon