markovchain
markovchain copied to clipboard
Define a probability matrix by columns does not work well
When the transition probability matrix is defined by columns (each column sums one) aparently works well, but it does not interpret correctly the "recurrent class", "transient class". In fact , it interprets the "recurrent classes" as "transient classes" and vice versa.
Hi, could you please provide a reproducible example? Best
Hi, let the example of Gambler Ruin provided in the vignette. I modified the function you provided for generate this problem in such a way you can define how you want the vector probabilities (by row or by column):
gamblerRuinMarkovChain <- function(moneyMax = 10, prob = 0.5, byRow = TRUE){
require(matlab)
matr <- zeros(moneyMax + 1)
states <- as.character(seq(from = 0, to = moneyMax, by = 1))
rownames(matr) = states; colnames(matr) = states
matr[1, 1] = 1; matr[moneyMax + 1, moneyMax +1] = 1
for (i in 2:moneyMax) {matr[i, i - 1] = 1 - prob; matr[i, i + 1] = prob}
if (byRow) {
out <- new("markovchain",
transitionMatrix = matr, byrow = byRow,
name = paste("Gambler ruin", moneyMax, "dim", sep = " "))
}else {
out <- new("markovchain",
transitionMatrix = t(matr), byrow = byRow,
name = paste("Gambler ruin", moneyMax, "dim", sep = " "))
}
return(out)
}
## Run the function:
P_byRow <- gamblerRuinMarkovChain(byRow = TRUE)
## 1) Look what is inside P_byRow.
P_byRow.
## 2) Look at: summary(P_byRow)
summary(P_byRow)
P_byCol <- gamblerRuinMarkovChain(byRow = FALSE)
## 3) Look what is inside P_byCol. At this point everything looks good!!
P_byCol
## 4) Look at: summary(P_byCol ).
summary(P_byCol ) ## This does not look good. The classes are exchanged !!
I hope my answer be enough.
Best !
Sergio
I will have a look by the end of the month. Best