I have a problem formulated in terms of hidden markov models. A simplified version is discussed here. I have a system that transitions between two discrete hidden states (states 1, 2). The transition probabilities between these states are known, and are shown in the figure below:
Moreover, I have two instruments (I1 and I2) independently observing the system, trying to classify the system as being in state 1 or 2 at each time interval. The observations by the instruments are made at discrete time intervals (say, every hour). Instrument I1 is more dependable than I2. However, data from I1 is not available at all time intervals.
The dependability of the instruments is also estimated independently, with values such as
P(S1 | I1=1) = 0.9
P(S2 | I1=1) = 0.1
P(S1 | I1=2) = 0.8
P(S2 | I1=2) = 0.2
..etc, for instrument 2 too...
where P(S1 | I1=1)
is the probability that the actual state was '1' given that data from instrument 1 estimated it to be '1'.
Now, I have observations (and estimated states) from both the instruments for a given time period:
Time_period I1 I2
1 1 1
2 NA 2
3 2 2
4 1 2
5 1 1
6 NA 2
7 NA 2
8 1 2
9 1 1
where I1
is the state inferred from the observation of instrument 1 and I2
is the state inferred from the observation of instrument 2, and NA
means that the observation was not available. Also, I have initial values of what the states were. Given these and the transition probabilities, I would like to get the posterior probability of the two states. That is, something like this (below):
Time_period I1 I2 pp_1 pp_2
1 1 1 0.92 0.08
2 NA 2 0.85 0.15
3 2 2 0.20 0.80
4 1 2 0.70 0.30
5 1 1 0.90 0.10
6 NA 2 0.95 0.05
7 NA 2 0.93 0.07
8 1 2 0.90 0.10
9 1 1 0.95 0.05
where pp_1 is the posterior probability that the actual state was state 1 and pp_2 is the probability that the actual state was state 2.
I know that this post talked about a similar problem. But I am not sure if I can use the msm package, as I have a discrete time situation. I would like to code this in R; which R package is best for this? Can someone please guide me, maybe with a few lines of relevant code?