0

I am running scripts for a project in Hidden Markov Model with 2 hiddens states at school. At some point, I use Viterbi's algrithm to find the most suitable sequences of hidden states. My output is a vector like that :

c("1","1","1","2","2","1", "1","1","1","2", "2","2")

I would like to count how many subsequences of each states there is, and also record their length and positions. The output would be, for example, a matrx like that:

State   Length  Starting_Position
1        3      1
2        2      4
1        4      6
2        3      10

Is there any R command or package who can do that easily ?

Thank you.

Micawber
  • 707
  • 1
  • 5
  • 19
  • 1
    It is a little hard for me to understand what you are asking for. Please provide an example vector you get from Viterbi's algorithm and your desired output from that vector. – josliber Jun 14 '17 at 14:47
  • Maybe look at `rle()` to capture "subsequences"? It would be more clear if you provided a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and the desired output for that input. – MrFlick Jun 14 '17 at 14:54
  • Ok, I edited my post to make it understable :) – Micawber Jun 14 '17 at 15:24

0 Answers0