<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Hello vinsz,<br><br>Thank you very much for taking time to help me.<br>Yes, you are correct. I see how the function works now.<br>The first state in the generated sequence is not the one indicated by the parameter but rather the next one in the chain starting from that initial state.<br><br>All very clear now. Thank you again.<br><br>Dan<br><br><br>______________________________<br><br><br>On 15/04/2010 16:45, 诚 甄 wrote:
<blockquote cite="mid:SNT143-w618121A880D49FC8DD24DBCC0F0@phx.gbl">
  <style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Verdana;}

</style>Hello
fellow Scilab Users,<br>
  <br>
I am using the grand() function to generate a state sequence for a
2-state Markov chain.<br>
It works fine to generate the sequence, but I don't quite understand
how the initial state parameter 'x0' works. Here is the code I use:<br>
  <br>
//-------------------<br>
  <font style="" face="Courier New">N=50;</font><font style="" face="Courier New">                       //length of sequence<br>
  </font><font style="" face="Courier New">P=[0.6 0.4;0.1 0.9];</font><font style="" face="Courier New">        //state transition matrix<br>
  </font><font style="" face="Courier New">q=grand(N,'markov',P,[1]);</font><font style="" face="Courier New">  //initial state is '1'<br>
  </font><font style="" face="Courier New">q=-(q*2.0-3.0);</font><font style="" face="Courier New">             //normalize to -1:+1 range<br>
  </font><font style="" face="Courier New"><br>
clf();</font><font style="" face="Courier New"><br>
  </font><font style="" face="Courier New">plot2d3([1:N],[q],[0],rect=[0,-1.5,N,1.5],leg='2-state
Markov chain');</font><br>
//------------------<br>
  <br>
If you run this piece of code a few times, sometimes it will start with
state '1', but not always.<br>
  <br>
From the help page I understand that:<br>
  <br>
- if I want the chain to start in state '1', then I just have to make
'x0 = [1]', as in the code above;<br>
  <br>
- if I want the state sequence to start from state '2', then I should
do 'x0=[2]'.<br>
  <br>
- if I want to get paths starting from both states I would make x0=[1
2], and each column of q (the output) would represent a path starting
at the corresponding state.<br>
  <br>
However, if I make x0=[1] or x0=[2], I get realizations starting from
any of the states (sometimes state 1 and sometimes state 2) and that
does not make much sense to me, because then, what are the
limiting-state probabilities that the function is using to choose the
initial state?<br>
According to what is explained in the grand() help page, if I make, for
example, x0=[1], shouldn't the sequence 'always' start in state 1?<br>
  <br>
I appreciate any help and clarifications on the behaviour of this
function.<br>
  <br>
</blockquote>
Hi Dan,<br>
<br>
I think the initial state is not reported in the grand() output. You
therefore see the other state according to your transition matrix. For
instance:<br>
<br>
N = 10000<br>
b = zeros(N, 1) ;<br>
for i=1:N<br>
  b(i) = grand(1,'markov',P,[1]);<br>
end<br>
ii = find(b==2);<br>
<br>
size(ii,'*')/N<br>
 ans  =<br>
 <br>
 0.4095 <br>
<br>
This is close enough to the probability to go from state 1 to state 2
being in state 1.<br>
<br>
Hope it helps,<br>
<br>
<br>
                                          <br /><hr />Hotmail: Trusted email with powerful SPAM protection. <a href='https://signup.live.com/signup.aspx?id=60969' target='_new'>Sign up now.</a></body>
</html>