Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a probability matrix by columns does not work well #148

Open
SergioMarreroMarrero opened this issue Mar 12, 2018 · 3 comments
Open
Assignees

Comments

@SergioMarreroMarrero
Copy link

SergioMarreroMarrero commented Mar 12, 2018

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.

@spedygiorgio
Copy link
Owner

Hi, could you please provide a reproducible example?
Best

@SergioMarreroMarrero
Copy link
Author

SergioMarreroMarrero commented Mar 12, 2018

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

@spedygiorgio
Copy link
Owner

I will have a look by the end of the month.
Best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants