Question

I have a continuous univariate xts object of length 1000, which I have converted into a data.frame called x to be used by the package RHmm.

I have already chosen that there are going to be 5 states and 4 gaussian distributions in the mixed distribution.

What I'm after is the expected mean value for the next observation. How do I go about getting that?

So what I have so far is:

  1. a transition matrix from running the HMMFit() function
  2. a set of means and variances for each of the gaussian distributions in the mixture, along with their respective proportions, all of which was also generated form the HMMFit() function
  3. a list of past hidden states relating to the input data when using the output of the HMMFit function and putting it into the viterbi function

How would I go about getting the next hidden state (i.e. the 1001st value) from what I've got, and then using it to get the weighted mean from the gaussian distributions.

I think I'm pretty close just not too sure what the next part is...The last state is state 5, do I use the 5th row in the transition matrix somehow to get the next state?

All I'm after is the weighted mean for what is to be expect in the next observation, so the next hidden state isn't even necessary. Do I multiply the probabilities in row 5 by each of the means, weighted to their proportion for each state? and then sum it all together?

here is the code I used.

# have used 2000 iterations to ensure convergence
a <- HMMFit(x, nStates=5, nMixt=4, dis="MIXTURE", control=list(iter=2000)
v <- viterbi(a,x)
a
v

As always any help would be greatly appreciated!

Was it helpful?

Solution

Next predicted value uses last hidden state last(v$states) to get probability weights from the transition matrix a$HMM$transMat[last(v$states),] for each state the distribution means a$HMM$distribution$mean are weighted by proportions a$HMM$distribution$proportion, then its all multiplied together and summed. So in the above case it would be as follows:

sum(a$HMM$transMat[last(v$states),] * .colSums((matrix(unlist(a$HMM$distribution$mean), nrow=4,ncol=5)) * (matrix(unlist(a$HMM$distribution$proportion), nrow=4,ncol=5)), m=4,n=5))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top