[R] Limiting state probability for Markov chain

Jim Lemon drjimlemon at gmail.com
Wed Apr 29 03:14:43 CEST 2015


Hi Justin,
As already noted, you want to compare two values in your "if"
statement. I think you may want to do it like this:

my_fun<-function(A,b) {
 for(j in 1:3) {
  x<-A;
  while((sum(x[j,])==1)) {
   x<-x%*%x;
   print(x);
   if(b%*%x[,j]==b[j]) break;
  }
 }
}

Jim

Justin USHIZE RUTIKANGA wrote:
>> Dear All,
>>
>> I am trying to determine  the liming state probability  .
>> my_fun<-function(A,b){
>> for (j in 1:3){
>> x<-A;
>> while ((sum(x[j,]) ==1) )
>> {
>>   x <- x%*%x;
>>   print (x);
>>   if ( b%*%x==b)
>>   {
>>     break;
>>   }}}
>> }
>> A<-rbind(c(.5,.3,.2), c(.3,.3,.4),c(.1,.5,.4))
>> b <- matrix(data=c(1,0,0), nrow=1, ncol=3, byrow=FALSE)
>> my_fun(A,b)
>>
>> I got the  following warning
>> 1: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 2: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 3: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 4: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 5: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 6: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 7: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 8: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> 9: In if (b %*% x == b) { :
>>   the condition has length > 1 and only the first element will be used
>> your help will be appreciate
>>



More information about the R-help mailing list