I'm trying to emulate a random walk/ Markov chain using R. As you can see I've set up a transition matrix, and then I'm trying to run a random walker on this. The thing here is that when the random walker meets an absorbing state (like 2 and 5) does not stop but continue running.
Am I using the wrong functions for something like this or there is somewhere else the problem? Actually what I want to achieve is to print out al the vertices that the walker visited.
library(igraph)
# Produce a transition matrix.
tm <- read.table(row.names=1, header=FALSE, text="
1 0.2 0.3 0.1 0.2 0.1 0.1
6 0.3 0.2 0.4 0.1 0 0
3 0 0.2 0.4 0.1 0.2 0.1
4 0.2 0.1 0.2 0.3 0.1 0.1
5 0 0 0 0 1 0
2 0 0 0 0 0 1")
tm<-as.matrix(tm)
row.names(tm) <- c(1,6,3,4,5,2)
colnames(tm) <- c(1,6,3,4,5,2)
g1 <- graph.adjacency(tm, mode="undirected", weighted=TRUE)
random_walk( graph = g1, start = '4', steps = 100, stuck = "error" )
An output example :
[1] 4 5 3 4 4 4 3 3 2 2 4 4 2 2 3 4 4 5 5 3 5 5 3 6 3 3 3 4 4 4 6 4 4 4 4 2 2 4 3 6 3 2 2 2 4 1
[47] 4 3 4 1 1 4 2 3 6 6 6 6 4 3 6 6 6 3 5 5 3 5 5 5 3 1 1 3 2 4 4 2 1 1 1 2 3 1 2 1 1 2 2 1 5 3
[93] 5 4 4 2 4 3 4 4
And as you can see it doesn't stop, neither at 2 nor at 5.