# How to find state-space representation for an estimated HMM model in R

Take the toy (already estimated) HMM model below from the R package MSwM. How do I find a state-space representation for it? Put differently, what are the matrixes: $${G}_t,F_t,R_t,Q_t$$ in the observation- and state-equations below?

$$\mathbf{Y_t}=G_t \mathbf{X_t}+\mathbf{W_t}$$, where $$\mathbf{W_t}$$~$$WN(\mathbf{0},$${$$R_t$$}),

$$\mathbf{X_{t+1}}=F_t \mathbf{X_t}+\mathbf{V_t}$$, where $$\mathbf{V_t}$$~$$WN(\mathbf{0},$${$$Q_t$$}), and $$E(\mathbf{W_tV_s^{'}})=0$$ for all $$s$$ and $$t$$.

library(MSwM)
data(example)
mod=lm(y~x,example)
mod.mswm=msmFit(mod,k=2,p=1,sw=c(TRUE,TRUE,TRUE,TRUE),control=list(parallel=FALSE))
summary(mod.mswm)
• Can I ask what do you mean by "finding a state-space representation of an HMM"? The state in HMM takes value in a finite set, while in state-space equations, it takes value in R^x
– null
Commented Nov 19, 2021 at 12:52
• @NathanExplosion: I am not sure I understand the question, but I am new to HMMs so if I wrote something that doesn't make sense, please clarify with a few more details. Commented Nov 19, 2021 at 13:04
• If your question is one of "Why do I care what the state-space representation is?" then here I would say "imagine that I want to use the Kalman filter to obtain the one-step predictor and error covariance by hand for this particular model. To do that, I need to know the matrices G,F,R, and Q. Commented Nov 19, 2021 at 13:12
• All right. In that case, you don't need to use Kalman filter to solve for HMMs. You can simply use Viterbi algorithm to solve the problem. Please keep in mind that HMMs and state-space models are different: One is of finite state, while the other is of state in $\mathbb{R}^x$.
– null
Commented Nov 19, 2021 at 13:38
• @NathanExplosion: HMMs are a type of state-space models. Commented Nov 19, 2021 at 13:47