I have a series of univariate data and I want to fit a Hidden Markov Model on it using the depmixS4 package on R. My final goal is to predict the next k observations (let's say k = 10) for the data series. I am not really interested in predicting the new state (that is important, but not my final goal), but I want to predict the next values for the data series.
It is a snippet of code:
# My series
data = rnorm(10000)
df_1_col = data.frame(data)
colnames(df_1_col) <- c('obs')
# Model
mod <- depmix(obs ~ 1, data = draws, nstates = n_state)
fit.mod <- fit(mod)
At this point I don't know how to predict the next out-of-samples values. I would like something similar to the forecast
function in the forecast
package.
I try using the following code:
state_ests <- posterior(fit.mod)
pred_resp <- matrix(0, ncol = n_state, nrow = 10)
for(i in 1:n_state) {
pred_resp[,i] <- predict(fit.mod@response[[i]][[1]])
}
Using this code the predict
function generates a number of predicted values that is equal to the number of observations into data
, so it is not right.
How can I do this quite basic operations? I am new to HMM, but I already tried to look into many resources and I did not find any information. Thanks :)