[R] Limiting state probability for Markov chain

Duncan Murdoch murdoch.duncan at gmail.com
Tue Apr 28 14:30:47 CEST 2015


On 28/04/2015 2:52 AM, 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

b has 3 elements; the if() statement wants just a single test.  You can use

if (all( b %*% x == b )) { ...

to avoid this problem, but it's always problematic to compare floating
point values for equality:  even if your Markov chain is exactly at the
limit, rounding may mean those two vectors are not equal.  You can do an
approximate test using the all.equal() function; see the help page
?all.equal for how to use it in an if() statement.

Duncan Murdoch

> 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
> 
> Best Regard
> Ushize Rutikanga Justin
> Student at African Institute for Mathematical Sciences (AIMS) South Africa
> E-mail:justinushize at aims.ac.za
> Tel:+27717029144
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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