Learn R Programming

castor (version 1.6.1)

get_stationary_distribution: Stationary distribution of Markov transition matrix.

Description

Calculate the stationary probability distribution vector p for a transition matrix Q of a continuous-time Markov chain. That is, calculate \(p\in[0,1]^n\) such that sum(p)==0 and \(p^TQ=0\).

Usage

get_stationary_distribution(Q)

Arguments

Q

A valid transition rate matrix of size Nstates x Nstates, i.e. a quadratic matrix in which every row sums up to zero.

Value

A numeric vector of size Nstates and with non-negative entries, satisfying the conditions p%*%Q==0 and sum(p)==1.0.

Details

A stationary distribution of a discrete-state continuous-time Markov chain is a probability distribution across states that remains constant over time, i.e. \(p^TQ=0\). Note that in some cases (i.e. if Q is not irreducible), there may be multiple distinct stationary distributions. In that case,which one is returned by this function is unpredictable. Internally, p is estimated by stepwise minimization of the norm of \(p^TQ\), starting with the vector p in which every entry equals 1/Nstates.

See Also

exponentiate_matrix

Examples

Run this code
# NOT RUN {
# generate a random 5x5 Markov transition matrix
Q = get_random_mk_transition_matrix(Nstates=5, rate_model="ARD")

# calculate stationary probability distribution
p = get_stationary_distribution(Q)
print(p)

# test correctness (p*Q should be 0, apart from rounding errors)
cat(sprintf("max(abs(p*Q)) = %g\n",max(abs(p %*% Q))))
# }

Run the code above in your browser using DataLab