Functions & Formulae

Each applied formula has its own function page, with a signature, implementations, and tests.

Absorbing Markov chain function

P = [[Q,R],[0,I]]

A state k is absorbing when p_kk = 1 and p_kj = 0 for every other state j, so no one who enters it can leave. Ordering the transient states first writes the transition matrix in canonical form, with Q the transitions among transient states, R the transitions from transient to absorbing states, a zero block and an identity block for the absorbing states. From Q and R the expected time before absorption and the probability of ending in each absorbing state follow without running the cohort trace s_(t+1) = s_t P.

  • Expected cycles before absorption from the fundamental matrix

    t_abs = (I - Q)^(-1) * c

    Inverts I minus Q to obtain the fundamental matrix N, whose entry in row i and column j is the expected number of cycles spent in transient state j by a person starting in transient state i, counting the starting cycle. Multiplying N by a column of ones sums each row, giving the expected number of cycles before absorption from each starting state. With death as the only absorbing state, this is the undiscounted expected number of cycles alive.

  • Probability of ending in each absorbing state

    B = (I - Q)^(-1) * R

    Multiplies the fundamental matrix by R, the one-cycle probabilities of moving from each transient state to each absorbing state. Entry i, j of B is the probability that a person starting in transient state i is eventually absorbed in state j. It is useful when a model keeps separate death states, for example death from the disease and death from other causes.