knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center", fig.path = "man/figures/README-" )
Multiple Hidden Markov Model Regression (HMMR) for the segmentation of multivariate time series with regime changes.
The model assumes that the time series is governed by a sequence of hidden discrete regimes/states, where each regime/state has multivariate Gaussian regressors emission densities. The model parameters are estimated by MLE via the EM algorithm.
You can install the development version of MHMMR from GitHub with:
# install.packages("devtools") devtools::install_github("fchamroukhi/MHMMR")
To build vignettes for examples of usage, type the command below instead:
# install.packages("devtools") devtools::install_github("fchamroukhi/MHMMR", build_opts = c("--no-resave-data", "--no-manual"), build_vignettes = TRUE)
Use the following command to display vignettes:
browseVignettes("MHMMR")
library(MHMMR)
# Application to a simulated data set data("toydataset") x <- toydataset$x y <- toydataset[, c("y1", "y2", "y3")] K <- 5 # Number of regimes (states) p <- 1 # Dimension of beta (order of the polynomial regressors) variance_type <- "heteroskedastic" # "heteroskedastic" or "homoskedastic" model n_tries <- 1 max_iter <- 1500 threshold <- 1e-6 verbose <- TRUE mhmmr <- emMHMMR(X = x, Y = y, K, p, variance_type, n_tries, max_iter, threshold, verbose) mhmmr$summary() mhmmr$plot(what = c("smoothed", "regressors", "loglikelihood"))
# Application to a real data set (human activity recognition data) data("realdataset") x <- realdataset$x y <- realdataset[, c("y1", "y2", "y3")] K <- 5 # Number of regimes (states) p <- 3 # Dimension of beta (order of the polynomial regressors) variance_type <- "heteroskedastic" # "heteroskedastic" or "homoskedastic" model n_tries <- 1 max_iter <- 1500 threshold <- 1e-6 verbose <- TRUE mhmmr <- emMHMMR(X = x, Y = y, K, p, variance_type, n_tries, max_iter, threshold, verbose) mhmmr$summary() mhmmr$plot(what = c("smoothed", "regressors", "loglikelihood"))
In this package, it is possible to select models based on information criteria such as BIC, AIC and ICL.
The selection can be done for the two following parameters:
Let's select a MHMMR model for the following multivariate time series Y:
data("toydataset") x <- toydataset$x y <- toydataset[, c("y1", "y2", "y3")] matplot(x, y, type = "l", xlab = "x", ylab = "Y", lty = 1)
selectedmhmmr <- selectMHMMR(X = x, Y = y, Kmin = 2, Kmax = 6, pmin = 0, pmax = 3) selectedmhmmr$plot(what = "smoothed")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.