[R] nth step transition matrices

Brad Lukoskie lubr0401 at stcloudstate.edu
Wed Apr 23 02:47:36 CEST 2008


Thanks for the reply.

This isn't a homework problem, its just part of a project I am working  
on.

I will give it a try.

I know from experience programming c++ and c# that learning by doing  
is the best way.

Could you explain what the % * % is doing to the matrix? Is this  
similar to a "mod" in c++?






On Apr 22, 2008, at 7:40 PM, markleeds at verizon.net wrote:

>> From: Brad Lukoskie <lubr0401 at stcloudstate.edu>
>> Date: 2008/04/22 Tue PM 06:49:14 CDT
>> To: r-help at r-project.org
>> Subject: [R] nth step transition matrices
>
> The list isn't supposed to be used for homework
> problems which I'm pretty certain this is but
> #R is difficult at first so i'll show you but you really need to do  
> these things on your own or you'll NEVER learn R. I don't want to  
> sound like a philosopher but it's really true that learning ,  
> particularly in programming, can only be attained by doing.
>
> here's the function and a test case but
> make sure you understand what's happening and
> keep it hush, hush. I followed Rolf's layout.
>
>
> matpow<-function(M,n) {
>
>     result<-M
>
>     for ( iter in (2:n)) {
>        result<-M%*%result
>     }
>     return(result)
> }
>
> testMat<-matrix(c(.95,0.05,0.01,0.99),nrow=2,byrow=TRUE)
> transMat<-matpow(testMat,2)
>
> print(transMat)
>
>
>
>
>> Hello,
>>
>> I have a question in regards to markov chains and transition
>> probabilities.
>>
>> I am trying to figure out a way to calculate the "kth-step transition
>> matrix" of a given matrix.
>>
>> Say for example I have a single step 2x2 matrix:
>>
>>
>>          1     2
>> P= 1  .95 .05
>>      2  .01. 99
>>
>> If I were to convert this matrix to a 2-step transition probability
>> matrix I would get:
>>
>>                 1     2
>> P^2 = 1  .90 .10
>>           2  .02  .98
>>
>> Is there a way to use [R] to calculate the nth step of a given  
>> matrix?
>>
>> Thanks,
>>
>> -Brad
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list