# Defining your transition matrix for multistate modelling

This example shows how to define a variety of transition matrices, for use with the multistate package in Stata. The transition matrix is used with msset for setting up your dataset for modelling, and with predictms for obtaining predictions from your multistate model. For more background info on multistate, see the multistate homepage, and,

Crowther MJ, Lambert PC. Parametric multi-state survival models: flexible modelling allowing transition-specific distributions with application to estimating clinically useful measures of effect differences. Statistics in Medicine 2017;36(29):4719-4742.

$~$

### The transition matrix

A transition matrix governs the movement of a process between possible states. Within multistate survival analysis, and particularly, the implementation of multistate models in Stata, the transition matrix contains the most crucial information, defining which transitions are possible, between a set of potential states. As always, it’s easier to explain through examples.

### Survival analysis

Standard survival analysis, with a starting state and a finishing state, is a multistate model - it’s just the simplest case. Our transition matrix for this is,

. matrix define tmat = (.,1\.,.)

. matrix list tmat

tmat[2,2]
c1  c2
r1   .   1
r2   .   .

The rows and columns represent states, and the elements of the matrix represent whether a transitions between a row state and a column state is possible. Elements with missing values, ".", imply a transition between a row state and a column state, is impossible. An element with a numeric value represents a transition that is possible. Let’s label our states.

. matrix colnames tmat = "alive" "dead"

. matrix rownames tmat = "alive" "dead"

. matrix list tmat

tmat[2,2]
alive      .      1

Much clearer. The only transition that should be allowed is going from row "alive" to column "dead", and hence we have one possible transition, which we index with a 1. My "death" state is known as an absorbing state, because once you enter it, you can’t leave, i.e., the transition going from "dead" to "alive" has an element containing a missing value.

### Competing risks

Let’s extend to competing risks. I’ll assume three different causes of death

• Death due to cancer
• Death due to cardiovascular disease (CVD)
• Death due to other causes

Our transition matrix is,

. matrix define tmat = (.,1,2,3\.,.,.,.\.,.,.,.\.,.,.,.)

. matrix list tmat

tmat[4,4]
alive           .           1           2           3

which is hopefully starting to become self-explanatory. From the "alive" state, there are three possible transitions, going to each of the three potential causes of death. They are indexed uniquely, from left to right (note, these indices are used by predictms when we pass our transition models to get predictions from our multistate model, see an example here). Of course, all the transitions from the death states to anywhere else are impossible, hence the rest of the transition matrix contains missing values.

### Illness-death

The illness-death model introduces an intermediate state. Potential pathways include,

• alive -> ill -> dead

and of course observations may remain in any of the states. Our transition matrix is,

. matrix define tmat = (.,1,2\.,.,3\.,.,.)

. matrix colnames tmat = "alive" "ill" "dead"

. matrix rownames tmat = "alive" "ill" "dead"

. matrix list tmat

tmat[3,3]
alive      .      1      2
ill      .      .      3

where transition 1 goes from "alive" to "ill", transition 2 goes from "alive" to "dead" (without becoming "ill"), and transition 3 goes from "ill" to "dead". This gives us what’s known as an upper triangular transition matrix.

### Extended illness-death

The extended illness-death partitions the probability of being in the dead state into it’s components of dead without illness, and dead with illness.

. matrix define tmat = (.,1,2,.\.,.,.,3\.,.,.,.\.,.,.,.)

. matrix list tmat

tmat[4,4]
alive           .           1           2           .
ill           .           .           .           3

### Reversible illness-death

The reversible illness-death model allows recovery from the illness state, i.e., we get what’s known as a cyclic transition matrix. The structure is as follows,

. matrix define tmat = (.,1,2\3,.,4\.,.,.)

. matrix colnames tmat = "alive" "ill" "dead"

. matrix rownames tmat = "alive" "ill" "dead"

. matrix list tmat

tmat[3,3]
alive      .      1      2
ill      3      .      4

where transition 1 goes from "alive" to "ill", transition 2 goes from "alive" to "dead" (without becoming "ill"), transition 3 goes from "ill" to "alive", and transition 4 goes from "ill" to "dead".

### We can keep going…

There’s no limitations on the structure you can impose. The final example has an intermediate state and competing death states. Observations have the following potential routes:

• diagnosis -> cvd -> deadcancer
• diagnosis -> cvd -> deadother

with a transition matrix of,

. mat tmat = (.,1,2,3\.,.,4,5\.,.,.,.\.,.,.,.)

. mat list tmat

tmat[4,4]