0

By "compound" I mean the transition matrix satisfies the Markov property,namely I have two columns s_t and s_t+k that represent state of each individual in two period t and t+k respectively. What I want is to find the matrix M that

s_t+k = M^k * s_t

so that matrix M satisfies the Markov property.

My default working language is Stata, in which commands like tab, svy:tab or xttran can generate one period transition matrices, but these matrices do not necessarily satisfy the Markov property. So I wonder how to achieve my goal in Stata or other common language like R or Python.

PS:This problem raise from a paper which research many countries' GDP_per_capita transition dynamics from 1960 to 2010. Say, at the beginning of each decades, we group all countries into 5 groups (from 1:extremely poor country to 5: high-income country), so we have a distribution of countries with 5 states. It's easy if I simply estimate the decade-to-decade transition matrix using markovchain class. However, the author claim that (page11, footnote4)

“The decade average transition matrix is estimated based on the 5-decade transition matrices from 1960 to 2010 by employing a numerical optimization program. Instead of taking the simple average for the five transition matrices (which suffers from Jensen’s Inequality), we estimate a transition matrix that can give us an exact 5 decade duration transition matrix (entry in 1960 and exit in 2010) by taking its power 5.”

Gaurav
  • 1,597
  • 2
  • 14
  • 31
zlqs1985
  • 509
  • 2
  • 8
  • 25
  • This seems backward to me. If the process is the simplest kind of Markov process, then the one-step transition probability matrix is what you need. If it's not, then that matrix is not sufficient to characterise the process. Any way, for a review of Stata technique in this territory see http://www.stata.com/meeting/boston14/abstracts/materials/boston14_nichols.pdf – Nick Cox Jun 14 '16 at 06:47
  • Thanks,NIck,I have read Austin‘s slice exactly before I posted this question. Though he described how to calculate transition matrix period-to-period in details, these methods cannot be applied to my problem directly. Thank you after all. – zlqs1985 Jun 14 '16 at 11:04

3 Answers3

1

In R you can use the markovchain package to get the transition matrix that satisfies markov property. You can use the following example code...

library(markovchain)
data(rain)
mysequence<-rain$rain
createSequenceMatrix(mysequence)
myFit<-markovchainFit(data=mysequence,,method="bootstrap",nboot=5, name="Bootstrap Mc")
myFit

The myFit is your estimated transition matrix. This example uses the Alofi rainfall dataset.

Gaurav
  • 1,597
  • 2
  • 14
  • 31
  • Thanks. But as I explained in my question, I need to estimate a transition matrix that satifies `s_t+k = M^k * s_t` , rather than `s_t+1= M*s_t`. Can I set the "time gap" `k` in the `markovchainFit` function ? – zlqs1985 Jun 15 '16 at 05:10
  • The cran document doesn't specify time gap parameter. You could probably calculate the `myFit` matrix and get the kth root using Jordan decomposition – Gaurav Jun 15 '16 at 05:26
  • @zlqs1985 from what I understand from your recent edit you can get `s_t+1= M*s_t` and then solve for `M^(1/5)` – Gaurav Jun 15 '16 at 05:50
  • Hey,@Gaurav, I try your method and get the transition matrix successfully. However, when I try to take exponent of this matrix (I named it rgdp_e_trans), it throws me error message like `Error in rgdp_e_trans %^% 1 : not a matrix`. So is this transition matrix returned from `markovchainfit` a data fram or a matrix? If it's data frame, I need to first transfer it to matrix – zlqs1985 Jun 19 '16 at 07:53
  • @zlqs1985 Try doing `as.matrix()` – Gaurav Jun 20 '16 at 12:09
0

The multiplication of matrix in R is not * but %*%.

I wrote a simple function in R to solve the problem.

trans_mat = function(k,s_t,M){
      for(i in 1:k){
       M = M % * % M
         }
      return(M%*%s_t)}
now, what you need to do is to type in k(how long the period you want),s_t(the original state), and M(markov property).
s_t+k  = trans_mat(k,s_t,M)
Alexc
  • 41
  • 3
  • I think the OP wants to estimate the matrix from the data. Your answer is just how to use it when you have it. – Nick Cox Jun 14 '16 at 06:45
  • Yes, Nick point out exactly what I want. Generally speaking, I want to create a set of states (dummies) by certain standard, and then estimate the transition matrix. If I cannot implement it (easily) within stata, I need to call R function. That's my plan. Thank you after all, @alexc – zlqs1985 Jun 14 '16 at 11:11
0

The markovchain package directly implements the power for any markovchain object:

require(markovchain)
#creating the MC
myMatr<-matrix(data=c(0.2,0.8,.6,.4),ncol=2,byrow=TRUE)
myMc<-as(myMatr,"markovchain")
#5th power of the MC
myMc5<-myMc^5
myMc5
Giorgio Spedicato
  • 2,413
  • 3
  • 31
  • 45