0

I created the following non-homogeneous Hidden Markov Model using depmix:

#primary time series
datats<-ts(data$primary)
y<- as.numeric(datats)

#Preparing covariates
cov1ts<-ts(data$cov1)
x1<- as.numeric(cov1ts)

cov2ts<-ts(data$cov2)
x2<- as.numeric(cov2ts)

#Build model
hmm_model <- depmix(y~1, data = data.frame(y), nstates = 2, transition = ~ (scale(x1)+scale(x2)))

hmm_model <-fit(hmm_model)
summary(hmm_model)

I now want to make a prediction about the next state. In the past I did this using homogeneous HMM as explained in this post: How to predict out-of-sample observations with depmixS4 package in R?

Specifically, in my case I did:

#[...] Created homogeneous model "hom_model" like before but without transition parameter

#transition probabilities at states
mat1<-hom_model@transition[[1]]@parameters$coefficients 
mat1<-hom_model@transition[[2]]@parameters$coefficients
#transition matrix
transmat<-rbind(mat1, mat2) 

# prediction as described in post, not very relevant for this question

But now for non-homogeneous hmm, I cannot obtain the transition matrix in the same way because now when I obtain mat1 and mat2, I get the coefficients of the covariates and intercept for each state. Specifically, my output for mat1 in the non-hom case looks like this:

            St1        St2        
(Intercept)   0 -0.6704946 
scale(x1)     0 -1.7279190  
scale(x2)     0 -2.0905961

I am unsure on how to obtain the transition matrix for the non-homogeneous case, and also a bit confused as why the State 1 coefficients are all 0.

Thank you

Fran_1011
  • 77
  • 6

0 Answers0