'Is there a function i can use to calculate steady state?

i was currently doing an excercise about steady state vector of a markov-chain, i was able to calculate it manually but I'm lost at how to calculate steady state using R, is there a function or library i can use to calculate this? any helps is appreciated, this is the transition matrix I'm using to calculate steady state:

P

P.data=c(0.95,0.03,0.05,0.97)
P = matrix(P.data, nrow=2,ncol=2,byrow=TRUE)
P


Solution 1:[1]

The steady state is a left eigen vector wit corresponding eigen value 1. To calculate the eigen vectors/values in R, there is the function eigen, but it calculates the right eigen vectors, so you have to transpose the Markov matrix.

> P.data <- c(0.95,0.03,0.05,0.97)
> P <- matrix(P.data, nrow=2, ncol=2, byrow=TRUE)
> eigen(t(P))
eigen() decomposition
$values
[1] 1.00 0.92

$vectors
           [,1]       [,2]
[1,] -0.7071068 -0.8574929
[2,] -0.7071068  0.5144958

The eigen vectors are defined up to a multiplicative factor, so here we find (0.5, 0.5) (the coefficients must sum to 1).

See this post and its answers for more details.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stéphane Laurent