@Tung, I have forgotten most of my Markov chain knowledge, but I think if you have the transition matrix (mc in your code) , raising it up to the number of steps would give you the transition probabilities already. I am not following why you need to call that function multiple times and create a matrix out of the results. Isn't mc^2 enough to give you all the probabilities?
Anyway, this is probably one more possibility of using outer.
outer(c("0", "1", "2", "3", "4"), c("0", "1", "2", "3", "4"), Vectorize(function(x, y) transitionProbability(mc^2, x, y)))
But as far as I can see, it'll be same as (mc^2)@transitionMatrix.
@bayesian, briefly answering two of your points, in case it helps.
-
purrr::pmap is supposed to go beyond two. It has support for ...1, ...2 etc. I almost never used it, so can't give an example. Sorry.
- Markov chain is a type of stochastic process. In the simplest case, given present future is independent of past (conditional probability of next step given the state history up to current state is same as conditional probability of next step given only the current step).
Edit (in reply to post #13)
I mentioned this previously:
You should have used this only. There is no need to create a matrix using outer, map2, pmap, for or any other method, as what you have is enough to check convergence. Probably some wrapper like this will be enough, but to be fair, probably unnecessary:
f <- function(markov_object, number_of_steps)
{
probabilities_after_steps <- markov_object ^ number_of_steps
return(probabilities_after_steps@transitionMatrix)
}
Then call it as f(mc, 10), f(mc, 50), etc. to get matrices for that many steps.
Please note that this is not a site to solve your problem for you. I gave you a solution and its explanation (here and in previous thread), and from that you should have been able to make a function to repeat for multiple steps. At least, you are supposed to show us some of your effort where you may or may not have failed.
And, for your future threads, please provide a minimal reproducible example, and ask only one concise question. Ideally, each thread should be about only one question, without multiple follow up questions. Asking explanations about a solution is fine, but not a new question. Please take a look at #meta for FAQ's.