0

I have generated the Markov Chain using Matlab. From the generated Markov Chain, I need to calculate the probability density function (PDF).

  • How should i do it?
    Should I use the generated Markov Chain directly in any of the PDF functions?
    or
    Should I do any pre-processing of the data before finding the PDF?

The Markov Chain is generated using the following code:

%  x     = the quantity corresponding to each state, typical element x(i)
%  P     = Markov transition matrix, typical element p(i,j) i,j=1,...n
%  pi0   = probability distribution over initial state
%  T     = number of periods to simulate 
%  chain = sequence of realizations from the simulation

n = length(x); % what is the size of the state vector?
E = rand(1,T); % T-vector of draws from independent uniform [0,1]  

cumsumP = P*triu(ones(size(P)));
E0   = rand(1,1);
ppi0 = [0,cumsum(pi0)];
s0   = ((E0<=ppi0(2:n+1)).*(E0>ppi0(1:n)))';
s    = s0; 

for t=1:T,
state(:,t) = s;
ppi        = [0,s'*cumsumP];
s          = ((E(t)<=ppi(2:n+1)).*(E(t)>ppi(1:n)))';
end

chain = x'*state;    

After generating the Markov Chain, I need to calculate the probability density.

  • How can I find the probability density using Matlab?
Schorsch
  • 7,761
  • 6
  • 39
  • 65
Ram Sundar
  • 13
  • 1
  • 6
  • Have you had a look at Matlab's [``pdf``](http://www.mathworks.com/help/stats/pdf.html)-function? It is part of the [statistics toolbox](http://www.mathworks.com/products/statistics/) though. – Schorsch May 23 '13 at 15:44
  • @Schorsch ya, i have used the pdf function 'ksdensity' as follows, [f,xi] = ksdensity(chain,bins,'function','PDF'); Is it correct? – Ram Sundar May 24 '13 at 07:26
  • Without being more specific on what you encountered, it is difficult to say if your use of ``kdensity`` is *correct*. It sure looks like the [example on mathworks](http://www.mathworks.com/help/stats/ksdensity.html). – Schorsch May 24 '13 at 11:38

1 Answers1

0

If you have the states as single values in vector chain, you can simply make a histogram and normalize it.

chainPdf = hist(chain) / length(chain);

You may need to specify the number of bins or bin centers when calling hist.

shoelzer
  • 10,648
  • 2
  • 28
  • 49