0

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
pbicez
  • 55
  • 4
  • There are a lot of ways to determine the steady-state, but it definitely depends on what you are starting with. Are you using a model to create the values? Perhaps the package `dMod` will help. That one is not in the R Cran library, you have to go to Github for that one: devtools::install_github("dkaschek/dMod"). Are you trying to find the steady-state of a Markov chain? Try the package `rootSolve`. Are you working with pharmaceutical data? (Steady-state with time or distribution?) Try the package `PKNCA`. `isotracer` includes a method to determine the steady-state of isotopes tracers. – Kat Jan 11 '22 at 19:24
  • yes thankyou. sorry to not given the info but I'm trying to find steady-state of a markov chain. so i have installed the rootsolve packages, could u help me on what function i should use and the argument i have to also give? – pbicez Jan 11 '22 at 19:34
  • It looks like you're fairly new to SO; welcome to the community! If you want great answers quickly, please make this question reproducible. This includes sample code you've attempted, listing non-base R packages, any errors/warnings received, sample data (e.g., data.frame(x=...,y=...) , like the output from dput(head(dataObject))), and what type of output you are expecting. Check out these resources for great questions: [making R reproducible](https://stackoverflow.com/q/5963269), [minimal reproducible example] and [tagging questions](https://stackoverflow.com/tags/r/info). – Kat Jan 12 '22 at 03:31
  • Your question isn't reproducible. I would have to have an idea of what you're working with in order to tell you how to use it. For example, how did you create the Markov data? What model did you run? [This resource looks helpful for the `rootSolve` package](https://cran.r-project.org/web/packages/rootSolve/vignettes/rootSolve.pdf). – Kat Jan 12 '22 at 03:32

1 Answers1

0

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.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225