Home > wafo > markov > estmc.m

estmc

PURPOSE ^

estimates transition matrix P from a time series of a Markov chain.

SYNOPSIS ^

[Pest,N,Ni] = estmc(z,r)

DESCRIPTION ^

  ESTMC  estimates transition matrix P from a time series of a Markov chain.
 
  [Pest,N] = estmc(z,r);
 
  z    = time series of a Markov chain.    [1xT]
  r    = number of states in Markov chain.
 
  Pest = Estimated transition matrix.
  N    =

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function [Pest,N,Ni] = estmc(z,r)
002 % ESTMC  estimates transition matrix P from a time series of a Markov chain.
003 %
004 % [Pest,N] = estmc(z,r);
005 %
006 % z    = time series of a Markov chain.    [1xT]
007 % r    = number of states in Markov chain.
008 %
009 % Pest = Estimated transition matrix.
010 % N    =
011 
012 
013 T = length(z);
014 
015 N = zeros(r,r);
016 Pest = zeros(r,r);
017 
018 for i = 1:r
019   for j=1:r
020     N(i,j) = sum( (z(1:T-1)==i) & (z(2:T)==j) );
021 %    if i==j
022 %      N(i,i) = sum(z(1:T-1)==i);
023 %    else
024 %      N(i,j) = sum((z(2:T)-z(1:T-1))==j-i);
025 %    end
026   end
027 end
028 
029 Ni = sum(N,2);
030 
031 for i = 1:r
032   if Ni(i) > 0
033     Pest(i,:) = N(i,:)/Ni(i);
034   else
035     Pest(i,:) = ones(1,r)/r;
036   end
037   Pest(i,i) = 0;
038   Pest(i,i) = 1-sum(Pest(i,:));
039 end
040 
041 
042 
043

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003