0

we met with interesting problem of R. We wanted to find 100 degree of any given markov chain matrix. The problem is that after some time matrix suddenly goes to zero. We think that is causation of approximately of matrix multiplication. Do you have any ideas how to fix it?

a <- c(0.2, 0, 0.7, 0.1) 
b <- c(0.5, 0.2, 0.2, 0.1)
c <- c(0, 0.3, 0.7, 0)
d <- c(0.1, 0.8, 0, 0.1)
mat <- matrix(c(a,b,c,d), ncol=4, byrow=TRUE)
z <- mat
for(i in 1:100)
{
  print(i)
  z <-  z%*%z
  print(z)
}
  • This is a floating point issue. Check if the result from `library(expm); mat %^% 100` is correct. – Roland May 13 '16 at 10:45
  • I've checked the rowSums and in iteration 31 you lose a bit of probability which aggregates into all future numbers. I think it's more stable to do this by repeatedly calculating pi = pi*P, where pi is the vector with stationary probabilities. It is very inefficient to multiply the complete matrix. – Forzaa May 13 '16 at 12:22

0 Answers0